llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.05k stars 11.98k forks source link

[clang] should not generate implicit declarations for dependent cases UNREACHABLE executed at /root/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:239! #112915

Open yijan4845 opened 3 weeks ago

yijan4845 commented 3 weeks ago

This testcase is generated by a fuzzer.

Compiler Explorer: https://godbolt.org/z/5svjMfjvT

This invalid code will crash on Clang Assertion Trunk:

struct D { ~D() noexcept(A()); };
struct S {
  ~S(); 
  struct X {
    friend S::~S(); 
  };
  D t;
};

This seems to go back to clang-11.

Stack dump:

should not generate implicit declarations for dependent cases
UNREACHABLE executed at /root/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:239!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.  Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1.  <source>:8:2: current parser token ';'
2.  <source>:2:1: parsing struct/union/class body 'S'
 #0 0x0000000003bb4fc8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bb4fc8)
 #1 0x0000000003bb2c8c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bb2c8c)
 #2 0x0000000003b00278 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f6e66242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f6e662969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007f6e66242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007f6e662287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x0000000003b0bb4a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b0bb4a)
 #8 0x0000000006aba777 clang::Sema::ImplicitExceptionSpecification::CalledDecl(clang::SourceLocation, clang::CXXMethodDecl const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6aba777)
 #9 0x0000000006aba936 (anonymous namespace)::SpecialMemberExceptionSpecInfo::visitClassSubobject(clang::CXXRecordDecl*, llvm::PointerUnion<clang::CXXBaseSpecifier*, clang::FieldDecl*>, unsigned int) SemaDeclCXX.cpp:0:0
#10 0x0000000006b4e531 ComputeDefaultedSpecialMemberExceptionSpec(clang::Sema&, clang::SourceLocation, clang::CXXMethodDecl*, clang::CXXSpecialMemberKind, clang::Sema::InheritedConstructorInfo*) SemaDeclCXX.cpp:0:0
#11 0x0000000006b4ebfd clang::Sema::EvaluateImplicitExceptionSpec(clang::SourceLocation, clang::FunctionDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b4ebfd)
#12 0x0000000006baebad clang::Sema::ResolveExceptionSpec(clang::SourceLocation, clang::FunctionProtoType const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6baebad)
#13 0x0000000006bb0456 clang::CheckEquivalentExceptionSpecImpl(clang::Sema&, clang::PartialDiagnostic const&, clang::PartialDiagnostic const&, clang::FunctionProtoType const*, clang::SourceLocation, clang::FunctionProtoType const*, clang::SourceLocation, bool*, bool*, bool, bool) SemaExceptionSpec.cpp:0:0
#14 0x0000000006bb4372 clang::Sema::CheckEquivalentExceptionSpec(clang::FunctionDecl*, clang::FunctionDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6bb4372)
#15 0x0000000006abbc03 clang::Sema::CheckDelayedMemberExceptionSpecs() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6abbc03)
#16 0x000000000668eabb clang::Parser::ParseLexedMemberInitializers(clang::Parser::ParsingClass&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x668eabb)
#17 0x00000000066df9cb clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributes&, unsigned int, clang::Decl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66df9cb)
#18 0x00000000066e2003 clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66e2003)
#19 0x00000000066b6800 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66b6800)
#20 0x0000000006674334 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6674334)
#21 0x0000000006674d9e clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6674d9e)
#22 0x000000000667c533 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x667c533)
#23 0x000000000667d41d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x667d41d)
#24 0x000000000666f93a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x666f93a)
#25 0x0000000004529838 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4529838)
#26 0x00000000047e3f89 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47e3f89)
#27 0x0000000004762a7e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4762a7e)
#28 0x00000000048c972e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48c972e)
#29 0x0000000000cdd9cf cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcdd9cf)
#30 0x0000000000cd56da ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#31 0x000000000456d549 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#32 0x0000000003b00724 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b00724)
#33 0x000000000456db3f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#34 0x000000000453343d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x453343d)
#35 0x000000000453452d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x453452d)
#36 0x000000000453be55 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x453be55)
#37 0x0000000000cda89f clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcda89f)
#38 0x0000000000ba9b24 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xba9b24)
#39 0x00007f6e66229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#40 0x00007f6e66229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#41 0x0000000000cd518e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcd518e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
llvmbot commented 3 weeks ago

@llvm/issue-subscribers-clang-frontend

Author: Yihan Yang (yijan4845)

**This testcase is generated by a fuzzer.** Compiler Explorer: [https://godbolt.org/z/5svjMfjvT](https://godbolt.org/z/5svjMfjvT) This invalid code will crash on Clang Assertion Trunk: ```cpp struct D { ~D() noexcept(A()); }; struct S { ~S(); struct X { friend S::~S(); }; D t; }; ``` This seems to go back to clang-11. Stack dump: ``` should not generate implicit declarations for dependent cases UNREACHABLE executed at /root/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:239! PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script. Stack dump: 0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source> 1. <source>:8:2: current parser token ';' 2. <source>:2:1: parsing struct/union/class body 'S' #0 0x0000000003bb4fc8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bb4fc8) #1 0x0000000003bb2c8c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bb2c8c) #2 0x0000000003b00278 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0 #3 0x00007f6e66242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #4 0x00007f6e662969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #5 0x00007f6e66242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476) #6 0x00007f6e662287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #7 0x0000000003b0bb4a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b0bb4a) #8 0x0000000006aba777 clang::Sema::ImplicitExceptionSpecification::CalledDecl(clang::SourceLocation, clang::CXXMethodDecl const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6aba777) #9 0x0000000006aba936 (anonymous namespace)::SpecialMemberExceptionSpecInfo::visitClassSubobject(clang::CXXRecordDecl*, llvm::PointerUnion<clang::CXXBaseSpecifier*, clang::FieldDecl*>, unsigned int) SemaDeclCXX.cpp:0:0 #10 0x0000000006b4e531 ComputeDefaultedSpecialMemberExceptionSpec(clang::Sema&, clang::SourceLocation, clang::CXXMethodDecl*, clang::CXXSpecialMemberKind, clang::Sema::InheritedConstructorInfo*) SemaDeclCXX.cpp:0:0 #11 0x0000000006b4ebfd clang::Sema::EvaluateImplicitExceptionSpec(clang::SourceLocation, clang::FunctionDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b4ebfd) #12 0x0000000006baebad clang::Sema::ResolveExceptionSpec(clang::SourceLocation, clang::FunctionProtoType const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6baebad) #13 0x0000000006bb0456 clang::CheckEquivalentExceptionSpecImpl(clang::Sema&, clang::PartialDiagnostic const&, clang::PartialDiagnostic const&, clang::FunctionProtoType const*, clang::SourceLocation, clang::FunctionProtoType const*, clang::SourceLocation, bool*, bool*, bool, bool) SemaExceptionSpec.cpp:0:0 #14 0x0000000006bb4372 clang::Sema::CheckEquivalentExceptionSpec(clang::FunctionDecl*, clang::FunctionDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6bb4372) #15 0x0000000006abbc03 clang::Sema::CheckDelayedMemberExceptionSpecs() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6abbc03) #16 0x000000000668eabb clang::Parser::ParseLexedMemberInitializers(clang::Parser::ParsingClass&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x668eabb) #17 0x00000000066df9cb clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributes&, unsigned int, clang::Decl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66df9cb) #18 0x00000000066e2003 clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66e2003) #19 0x00000000066b6800 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66b6800) #20 0x0000000006674334 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6674334) #21 0x0000000006674d9e clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6674d9e) #22 0x000000000667c533 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x667c533) #23 0x000000000667d41d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x667d41d) #24 0x000000000666f93a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x666f93a) #25 0x0000000004529838 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4529838) #26 0x00000000047e3f89 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47e3f89) #27 0x0000000004762a7e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4762a7e) #28 0x00000000048c972e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48c972e) #29 0x0000000000cdd9cf cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcdd9cf) #30 0x0000000000cd56da ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0 #31 0x000000000456d549 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0 #32 0x0000000003b00724 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b00724) #33 0x000000000456db3f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0 #34 0x000000000453343d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x453343d) #35 0x000000000453452d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x453452d) #36 0x000000000453be55 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x453be55) #37 0x0000000000cda89f clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcda89f) #38 0x0000000000ba9b24 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xba9b24) #39 0x00007f6e66229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #40 0x00007f6e66229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #41 0x0000000000cd518e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcd518e) clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation) Compiler returned: 134 ```
shafik commented 3 weeks ago

This a weird one the friend S::~S(); is necessary here but not clear why.