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 `Ancestor->getEntity() == CurContext && "ancestor context mismatch"' failed. #30908

Closed
llvmbot opened this issue Jan 6, 2017 · 7 comments · Fixed by #77434
Closed
Assignees
Labels
bugzilla Issues migrated from bugzilla clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer confirmed Verified by a second party crash-on-invalid

Comments

@llvmbot
Copy link

llvmbot commented Jan 6, 2017

Bugzilla Link 31560
Version unspecified
OS Windows NT
Reporter LLVM Bugzilla Contributor

Extended Description

$ cat file.cpp
namespace llvm {
namespace Hexagon {}
}
void set() {
  Hexagon::NoRegister;
  Hexagon::NoRegister;
  Hexagon::NoRegister;
}
template <class> struct pair { pair(int, int); };
struct HexagonMCChecker {
  static pair<int> Unconditional;
  void checkRegisters();
};
pair<int> HexagonMCChecker::Unconditional(Hexagon::NoRegister, 0);
void HexagonMCChecker::checkRegisters() {}
$/.../llvm/build/bin/clang -v
clang version 4.0.0 (trunk 291212)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /.../llvm/build/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.2.0
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.2.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64

$#/.../llvm/build/bin/clang -cc1 -fsyntax-only -ferror-limit 5 file.cpp
file.cpp:5:3: error: use of undeclared identifier 'Hexagon'; did you mean 'llvm::Hexagon'?
  Hexagon::NoRegister;
  ^~~~~~~
  llvm::Hexagon
file.cpp:2:11: note: 'llvm::Hexagon' declared here
namespace Hexagon {}
          ^
file.cpp:5:12: error: no member named 'NoRegister' in namespace 'llvm::Hexagon'
  Hexagon::NoRegister;
  ~~~~~~~~~^
file.cpp:6:3: error: use of undeclared identifier 'Hexagon'; did you mean 'llvm::Hexagon'?
  Hexagon::NoRegister;
  ^~~~~~~
  llvm::Hexagon
file.cpp:2:11: note: 'llvm::Hexagon' declared here
namespace Hexagon {}
          ^
file.cpp:6:12: error: no member named 'NoRegister' in namespace 'llvm::Hexagon'
  Hexagon::NoRegister;
  ~~~~~~~~~^
file.cpp:7:3: error: use of undeclared identifier 'Hexagon'; did you mean 'llvm::Hexagon'?
  Hexagon::NoRegister;
  ^~~~~~~
  llvm::Hexagon
file.cpp:2:11: note: 'llvm::Hexagon' declared here
namespace Hexagon {}
          ^
fatal error: too many errors emitted, stopping now
clang: ../tools/clang/lib/Sema/SemaDecl.cpp:1170: void clang::Sema::EnterDeclaratorContext(clang::Scope *, clang::DeclContext *): Assertion `Ancestor->getEntity() == CurContext && "ancestor context mismatch"' failed.
#&#8203;0 0x0000000002d1809c llvm::sys::PrintStackTrace(llvm::raw_ostream&) /.../llvm/build/../lib/Support/Unix/Signals.inc:402:11
#&#8203;1 0x0000000002d18589 PrintStackTraceSignalHandler(void*) /.../llvm/build/../lib/Support/Unix/Signals.inc:466:1
#&#8203;2 0x0000000002d16903 llvm::sys::RunSignalHandlers() /.../llvm/build/../lib/Support/Signals.cpp:0:5
#&#8203;3 0x0000000002d188e4 SignalHandler(int) /.../llvm/build/../lib/Support/Unix/Signals.inc:256:1
#&#8203;4 0x00007f2d354d3390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
#&#8203;5 0x00007f2d34037428 gsignal /build/glibc-t3gR2i/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0
#&#8203;6 0x00007f2d3403902a abort /build/glibc-t3gR2i/glibc-2.23/stdlib/abort.c:91:0
#&#8203;7 0x00007f2d3402fbd7 __assert_fail_base /build/glibc-t3gR2i/glibc-2.23/assert/assert.c:92:0
#&#8203;8 0x00007f2d3402fc82 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc82)
#&#8203;9 0x0000000004fc983e clang::Sema::EnterDeclaratorContext(clang::Scope*, clang::DeclContext*) /.../llvm/build/../tools/clang/lib/Sema/SemaDecl.cpp:1173:16
#&#8203;10 0x0000000004f11f38 clang::Sema::ActOnCXXEnterDeclaratorScope(clang::Scope*, clang::CXXScopeSpec&) /.../llvm/build/../tools/clang/lib/Sema/SemaCXXScopeSpec.cpp:1066:7
#&#8203;11 0x0000000004b3e380 clang::Parser::DeclaratorScopeObj::EnterDeclaratorScope() /.../llvm/build/../tools/clang/include/clang/Parse/Parser.h:2337:11
#&#8203;12 0x0000000004b351e5 clang::Parser::ParseDirectDeclarator(clang::Declarator&) /.../llvm/build/../tools/clang/lib/Parse/ParseDecl.cpp:5267:9
#&#8203;13 0x0000000004b3448d clang::Parser::ParseDeclaratorInternal(clang::Declarator&, void (clang::Parser::*)(clang::Declarator&)) /.../llvm/build/../tools/clang/lib/Parse/ParseDecl.cpp:0:11
#&#8203;14 0x0000000004b1abb8 clang::Parser::ParseDeclarator(clang::Declarator&) /.../llvm/build/../tools/clang/lib/Parse/ParseDecl.cpp:4951:1
#&#8203;15 0x0000000004b2b3cc clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, unsigned int, clang::SourceLocation*, clang::Parser::ForRangeInit*) /.../llvm/build/../tools/clang/lib/Parse/ParseDecl.cpp:1758:3
#&#8203;16 0x0000000004b06062 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /.../llvm/build/../tools/clang/lib/Parse/Parser.cpp:985:10
#&#8203;17 0x0000000004b057a0 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /.../llvm/build/../tools/clang/lib/Parse/Parser.cpp:1001:12
#&#8203;18 0x0000000004b0509b clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) /.../llvm/build/../tools/clang/lib/Parse/Parser.cpp:851:12
#&#8203;19 0x0000000004b0403e clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) /.../llvm/build/../tools/clang/lib/Parse/Parser.cpp:627:12
#&#8203;20 0x0000000004afecef clang::ParseAST(clang::Sema&, bool, bool) /.../llvm/build/../tools/clang/lib/Parse/ParseAST.cpp:147:14
#&#8203;21 0x00000000036bedbc clang::ASTFrontendAction::ExecuteAction() /.../llvm/build/../tools/clang/lib/Frontend/FrontendAction.cpp:560:1
#&#8203;22 0x00000000036be860 clang::FrontendAction::Execute() /.../llvm/build/../tools/clang/lib/Frontend/FrontendAction.cpp:463:7
#&#8203;23 0x0000000003651ba7 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /.../llvm/build/../tools/clang/lib/Frontend/CompilerInstance.cpp:954:7
#&#8203;24 0x0000000003828b15 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /.../llvm/build/../tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:249:8
#&#8203;25 0x0000000000e048bf cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /.../llvm/build/../tools/clang/tools/driver/cc1_main.cpp:221:11
#&#8203;26 0x0000000000df81f9 ExecuteCC1Tool(llvm::ArrayRef<char const*>, llvm::StringRef) /.../llvm/build/../tools/clang/tools/driver/driver.cpp:299:5
#&#8203;27 0x0000000000df6e70 main /.../llvm/build/../tools/clang/tools/driver/driver.cpp:380:5
#&#8203;28 0x00007f2d34022830 __libc_start_main /build/glibc-t3gR2i/glibc-2.23/csu/../csu/libc-start.c:325:0
#&#8203;29 0x0000000000df5ff9 _start (/.../llvm/build/bin/clang+0xdf5ff9)
Stack dump:
0.      Program arguments: /.../llvm/build/bin/clang -cc1 -fsyntax-only -ferror-limit 5 file.cpp
1.      file.cpp:15:24: current parser token 'checkRegisters'
@llvmbot
Copy link
Author

llvmbot commented Jun 10, 2017

as of r305089 assertion fails

@llvmbot
Copy link
Author

llvmbot commented Sep 3, 2021

as of 10d78a0 still asserts

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@Endilll Endilll added clang:frontend Language frontend issues, e.g. anything involving "Sema" crash-on-invalid labels Jul 16, 2023
@llvmbot
Copy link
Author

llvmbot commented Jul 16, 2023

@llvm/issue-subscribers-clang-frontend

@Endilll
Copy link
Contributor

Endilll commented Jul 16, 2023

I can't reproduce it with Clang 4 with assertions, but comment above claims to reproduce this 2 years ago. I wonder what I'm missing: https://godbolt.org/z/6GcbK7zzz

CC @AaronBallman

@AaronBallman AaronBallman added confirmed Verified by a second party clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 16, 2023
@AaronBallman
Copy link
Collaborator

AaronBallman commented Jul 16, 2023

It requires -ferror-limit 5 to reproduce the issue: https://godbolt.org/z/3KEM5es4b

@Endilll
Copy link
Contributor

Endilll commented Jul 16, 2023

Still crashing as of post-16 trunk: https://godbolt.org/z/v4ojjvfs1

<source>:5:3: error: use of undeclared identifier 'Hexagon'; did you mean 'llvm::Hexagon'?
    5 |   Hexagon::NoRegister;
      |   ^~~~~~~
      |   llvm::Hexagon
<source>:2:11: note: 'llvm::Hexagon' declared here
    2 | namespace Hexagon {}
      |           ^
<source>:5:12: error: no member named 'NoRegister' in namespace 'llvm::Hexagon'
    5 |   Hexagon::NoRegister;
      |   ~~~~~~~~~^
<source>:6:3: error: use of undeclared identifier 'Hexagon'; did you mean 'llvm::Hexagon'?
    6 |   Hexagon::NoRegister;
      |   ^~~~~~~
      |   llvm::Hexagon
<source>:2:11: note: 'llvm::Hexagon' declared here
    2 | namespace Hexagon {}
      |           ^
<source>:6:12: error: no member named 'NoRegister' in namespace 'llvm::Hexagon'
    6 |   Hexagon::NoRegister;
      |   ~~~~~~~~~^
<source>:7:3: error: use of undeclared identifier 'Hexagon'; did you mean 'llvm::Hexagon'?
    7 |   Hexagon::NoRegister;
      |   ^~~~~~~
      |   llvm::Hexagon
<source>:2:11: note: 'llvm::Hexagon' declared here
    2 | namespace Hexagon {}
      |           ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
clang++: /root/llvm-project/clang/lib/Sema/SemaDecl.cpp:1402: void clang::Sema::EnterDeclaratorContext(clang::Scope*, clang::DeclContext*): Assertion `Ancestor->getEntity() == CurContext && "ancestor context mismatch"' failed.
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 -Xclang -ferror-limit -Xclang 5 <source>
1.	<source>:15:24: current parser token 'checkRegisters'
 #0 0x000055926c29ac1a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a9ac1a)
 #1 0x000055926c29884c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a9884c)
 #2 0x000055926c1e7020 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f15f1d9a420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f15f186700b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f15f1846859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f15f1846729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f15f1857fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x000055926e8cbbe7 clang::Sema::EnterDeclaratorContext(clang::Scope*, clang::DeclContext*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x60cbbe7)
 #9 0x000055926e79b3ab clang::Sema::ActOnCXXEnterDeclaratorScope(clang::Scope*, clang::CXXScopeSpec&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f9b3ab)
#10 0x000055926e6553da clang::Parser::DeclaratorScopeObj::EnterDeclaratorScope() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e553da)
#11 0x000055926e671667 clang::Parser::ParseDirectDeclarator(clang::Declarator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e71667)
#12 0x000055926e6655d6 clang::Parser::ParseDeclaratorInternal(clang::Declarator&, void (clang::Parser::*)(clang::Declarator&)) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e655d6)
#13 0x000055926e7616ff clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f616ff)
#14 0x000055926e671d67 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e71d67)
#15 0x000055926e63e728 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e3e728)
#16 0x000055926e63f0a6 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.321) Parser.cpp:0:0
#17 0x000055926e64394b clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e4394b)
#18 0x000055926e645176 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e45176)
#19 0x000055926e63a22b clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e3a22b)
#20 0x000055926d367560 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b67560)
#21 0x000055926cc892e9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44892e9)
#22 0x000055926cc1dc42 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x441dc42)
#23 0x000055926cd60c9f clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4560c9f)
#24 0x0000559269a22cc3 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1222cc3)
#25 0x0000559269a1ade8 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#26 0x000055926ca912f9 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
#27 0x000055926c1e74a5 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x39e74a5)
#28 0x000055926ca93eee clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4293eee)
#29 0x000055926ca6060b clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x426060b)
#30 0x000055926ca611e3 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+++0x42611e3)
#31 0x000055926ca69fd6 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4269fd6)
#32 0x0000559269a20a8e clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1220a8e)
#33 0x0000559269951cb1 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1151cb1)
#34 0x00007f15f1848083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#35 0x0000559269a1a4da _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x121a4da)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134

@danix800
Copy link
Member

danix800 commented Jan 9, 2024

We got this crash on the latest trunk lately and proposed a fix (#77434).

Another testcase https://godbolt.org/z/e9MYx5fqs

danix800 added a commit to danix800/llvm-project that referenced this issue Jan 9, 2024
…t Init

Invalid (direct) initializer would invalid VarDecl so InitializerScopeRAII
cannot restore scope stack balance.

As with other kind of initializers, InitializerScopeRAII::pop() is moved up
before Sema::ActOnInitializerError() which invalidates the VarDecl, so
scope can be balanced and current DeclContext can be restored.

Fixes llvm#30908
danix800 added a commit that referenced this issue Jan 10, 2024
…77434)

Invalid (direct) initializer would invalid `VarDecl` so
`InitializerScopeRAII` cannot restore scope stack balance.

As with other kind of initializer, `InitializerScopeRAII::pop()` is
moved up before `Sema::ActOnInitializerError()` which invalidates the
`VarDecl`, so scope can be balanced and current `DeclContext` can be
restored.

Fixes #30908
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this issue Jan 28, 2024
…lvm#77434)

Invalid (direct) initializer would invalid `VarDecl` so
`InitializerScopeRAII` cannot restore scope stack balance.

As with other kind of initializer, `InitializerScopeRAII::pop()` is
moved up before `Sema::ActOnInitializerError()` which invalidates the
`VarDecl`, so scope can be balanced and current `DeclContext` can be
restored.

Fixes llvm#30908
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:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer confirmed Verified by a second party crash-on-invalid
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants