Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion `getContainingDC(DC) == CurContext && "The next DeclContext should be lexically contained in the current one."' failed. #44285

Open
llvmbot opened this issue Feb 17, 2020 · 1 comment
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash-on-invalid

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 17, 2020

Bugzilla Link 44940
Version trunk
OS All
Reporter LLVM Bugzilla Contributor
CC @zygoloid

Extended Description

POC:

struct {
        struct {a ( b = (struct {
                                c {) )
                )

Run script:

Crash reproducer for clang version 11.0.0 (https://github.com/llvm/llvm-project.git 56b7f59)

Driver args: "--driver-mode=g++" "-x" "c++" "-o" "tm" "test1.c"

Original command: "/data/rxz226/llvm-project/bld/bin/clang-11" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free" "-main-file-name" "test1.c" "-mrelocation-model" "static" "-mthread-model" "posix" "-mframe-pointer=all" "-fmath-errno" "-fno-rounding-math" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-target-cpu" "x86-64" "-dwarf-column-info" "-fno-split-dwarf-inlining" "-debugger-tuning=gdb" "-resource-dir" "/data/rxz226/llvm-project/bld/lib/clang/11.0.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/x86_64-linux-gnu/c++/7.4.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/x86_64-linux-gnu/c++/7.4.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/backward" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/data/rxz226/llvm-project/bld/lib/clang/11.0.0/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-fdeprecated-macro" "-fdebug-compilation-dir" "/home/rxz226/c_reduce" "-ferror-limit" "19" "-fmessage-length" "0" "-fgnuc-version=4.2.1" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-faddrsig" "-o" "/tmp/test1-0eca8d.o" "-x" "c++" "test1.c"

"/data/rxz226/llvm-project/bld/bin/clang-11" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free" "-main-file-name" "test1.c" "-mrelocation-model" "static" "-mthread-model" "posix" "-mframe-pointer=all" "-fmath-errno" "-fno-rounding-math" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-target-cpu" "x86-64" "-dwarf-column-info" "-fno-split-dwarf-inlining" "-debugger-tuning=gdb" "-fdeprecated-macro" "-ferror-limit" "19" "-fmessage-length" "0" "-fgnuc-version=4.2.1" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-faddrsig" "-x" "c++" "test1-c8ca1c.cpp"

Stack dump:

Stack dump:
0. Program arguments: /home/rxz226/llvm-project/bld/bin/clang++ -x c++ -o tm test1.c

  1.  <eof> parser at end of file
    
  2.  test1.c:1:1: parsing struct/union/class body '(anonymous)'
    

#​0 0x000000000511679b llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/rxz226/llvm-project/llvm/lib/Support/Unix/Signals.inc:564:0
#​1 0x000000000511682e PrintStackTraceSignalHandler(void*) /home/rxz226/llvm-project/llvm/lib/Support/Unix/Signals.inc:625:0
#​2 0x00000000051145b6 llvm::sys::RunSignalHandlers() /home/rxz226/llvm-project/llvm/lib/Support/Signals.cpp:68:0
#​3 0x0000000005115fd7 llvm::sys::CleanupOnSignal(unsigned long) /home/rxz226/llvm-project/llvm/lib/Support/Unix/Signals.inc:361:0
#​4 0x000000000501be1f (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) /home/rxz226/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:80:0
#​5 0x000000000501c2fe CrashRecoverySignalHandler(int) /home/rxz226/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:362:0
#​6 0x00007fe6d284d390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
#​7 0x00007fe6d155c428 raise /build/glibc-LK5gWL/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0
#​8 0x00007fe6d155e02a abort /build/glibc-LK5gWL/glibc-2.23/stdlib/abort.c:91:0
#​9 0x00007fe6d1554bd7 __assert_fail_base /build/glibc-LK5gWL/glibc-2.23/assert/assert.c:92:0
#​10 0x00007fe6d1554c82 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc82)
#​11 0x0000000007c2f161 clang::Sema::PushDeclContext(clang::Scope*, clang::DeclContext*) /home/rxz226/llvm-project/clang/lib/Sema/SemaDecl.cpp:1299:0
#​12 0x0000000007d5a8f1 clang::Sema::ActOnStartDelayedMemberDeclarations(clang::Scope*, clang::Decl*) /home/rxz226/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:9678:0
#​13 0x0000000007a0f6a4 clang::Parser::ParseLexedMethodDeclarations(clang::Parser::ParsingClass&) /home/rxz226/llvm-project/clang/lib/Parse/ParseCXXInlineMethods.cpp:292:0
#​14 0x0000000007a0f45d clang::Parser::LateParsedClass::ParseLexedMethodDeclarations() /home/rxz226/llvm-project/clang/lib/Parse/ParseCXXInlineMethods.cpp:239:0
#​15 0x0000000007a0f6f0 clang::Parser::ParseLexedMethodDeclarations(clang::Parser::ParsingClass&) /home/rxz226/llvm-project/clang/lib/Parse/ParseCXXInlineMethods.cpp:292:0
#​16 0x0000000007a49e11 clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::Parser::ParsedAttributesWithRange&, unsigned int, clang::Decl*) /home/rxz226/llvm-project/clang/lib/Parse/Par
seDeclCXX.cpp:3370:0
#​17 0x0000000007a442a1 clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, cl
ang::Parser::ParsedAttributesWithRange&) /home/rxz226/llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:1960:0
#​18 0x0000000007a258ec clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*) /home/rxz22
6/llvm-project/clang/lib/Parse/ParseDecl.cpp:3935:0
#​19 0x00000000079ff10d clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /home/rxz226/llvm-project/clang/lib/Parse/Parser.cpp:1020:0
#​20 0x00000000079ff7ab clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /home/rxz226/llvm-project/clang/lib/Parse/Parser.cpp:1125:0
#​21 0x00000000079fec86 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) /home/rxz226/llvm-project/clang/lib/Parse/Parser.cpp:945:0
#​22 0x00000000079fdf00 clang::Parser::ParseTopLevelDecl(clang::OpaquePtrclang::DeclGroupRef&, bool) /home/rxz226/llvm-project/clang/lib/Parse/Parser.cpp:696:0
#​23 0x00000000079fd881 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtrclang::DeclGroupRef&) /home/rxz226/llvm-project/clang/lib/Parse/Parser.cpp:564:0
#​24 0x00000000079f97d7 clang::ParseAST(clang::Sema&, bool, bool) /home/rxz226/llvm-project/clang/lib/Parse/ParseAST.cpp:157:0
#​25 0x0000000005c0bed1 clang::ASTFrontendAction::ExecuteAction() /home/rxz226/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1044:0
#​26 0x00000000064f371e clang::CodeGenAction::ExecuteAction() /home/rxz226/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1177:0
#​27 0x0000000005c0b820 clang::FrontendAction::Execute() /home/rxz226/llvm-project/clang/lib/Frontend/FrontendAction.cpp:940:0
#​28 0x0000000005ba0092 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/rxz226/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:965:0
#​29 0x0000000005d7818e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/rxz226/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:290:0
#​30 0x000000000272848c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/rxz226/llvm-project/clang/tools/driver/cc1_main.cpp:239:0
#​31 0x000000000271d97a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) /home/rxz226/llvm-project/clang/tools/driver/driver.cpp:328:0
...

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@shafik
Copy link
Collaborator

shafik commented Jun 23, 2023

Still reproduces: https://godbolt.org/z/bd77b8WPc

Assertion:

clang++: /root/llvm-project/clang/lib/Sema/SemaDecl.cpp:1345:
void clang::Sema::PushDeclContext(clang::Scope*, clang::DeclContext*):
Assertion `DC->getLexicalParent() == CurContext && "The next DeclContext should be lexically contained in the current one."' failed.

backtrace:

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 -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 <source>
1.	<eof> parser at end of file
2.	<source>:1:1: parsing struct/union/class body '(unnamed struct at <source>:1:1)'
 #0 0x00005621f13e895f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c4c95f)
 #1 0x00005621f13e66cc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c4a6cc)
 #2 0x00005621f1330d18 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f10dd36d420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f10dce3a00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f10dce19859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f10dce19729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f10dce2afd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x00005621f3e6eb42 clang::Sema::PushDeclContext(clang::Scope*, clang::DeclContext*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66d2b42)
 #9 0x00005621f3f633bd clang::Sema::ActOnStartDelayedMemberDeclarations(clang::Scope*, clang::Decl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x67c73bd)
#10 0x00005621f3b72254 clang::Parser::ParseLexedMemberInitializers(clang::Parser::ParsingClass&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63d6254)
#11 0x00005621f3b7234d clang::Parser::ParseLexedMemberInitializers(clang::Parser::ParsingClass&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63d634d)
#12 0x00005621f3bbda79 clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributes&, unsigned int, clang::Decl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6421a79)
#13 0x00005621f3bbfaf8 clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6423af8)
#14 0x00005621f3b987dd clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63fc7dd)
#15 0x00005621f3b638cb clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63c78cb)
#16 0x00005621f3b641ff clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#17 0x00005621f3b6aba1 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63ceba1)
#18 0x00005621f3b6b516 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63cf516)
#19 0x00005621f3b6b9b4 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63cf9b4)
#20 0x00005621f3b5f28a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63c328a)
#21 0x00005621f26637d8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ec77d8)
#22 0x00005621f1eae989 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4712989)
#23 0x00005621f1e345a6 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x46985a6)
#24 0x00005621f1f92da6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47f6da6)
#25 0x00005621ee891f8d cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x10f5f8d)
#26 0x00005621ee88dc8a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#27 0x00005621f1c94cad 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
#28 0x00005621f1331220 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b95220)
#29 0x00005621f1c952cf 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
#30 0x00005621f1c5c67c clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44c067c)
#31 0x00005621f1c5d10d 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+++0x44c110d)
#32 0x00005621f1c651ed clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44c91ed)
#33 0x00005621ee8901ea clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x10f41ea)
#34 0x00005621ee7965a5 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xffa5a5)
#35 0x00007f10dce1b083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#36 0x00005621ee888a6e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x10eca6e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash-on-invalid
Projects
None yet
Development

No branches or pull requests

2 participants