[PATCH] D154503: [Sema] Fix handling of functions that hide classes
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 10 04:47:39 PDT 2023
kadircet added a comment.
Hi!
After this patch clang seems to be crashing on:
class a {
static c a;
void b(){a};
};
with stack trace and assertion error:
$ ~/repos/llvm/build/bin/clang -xc++ repro.cc
repro.cc:2:10: error: unknown type name 'c'
2 | static c a;
| ^
repro.cc:2:12: error: member 'a' has the same name as its class
2 | static c a;
| ^
clang-17: /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaLookup.cpp:333: bool clang::LookupResult::checkDebugAssumptions() const: Assertion `ResultKind != Found || Decls.size() == 1' 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: /usr/local/google/home/kadircet/repos/llvm/build/bin/clang-17 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name repro.cc -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/local/google/home/kadircet/repos/tmp/new_crasher -resource-dir /usr/local/google/home/kadircet/repos/llvm/build/lib/clang/18 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/backward -internal-isystem /usr/local/google/home/kadircet/repos/llvm/build/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir=/usr/local/google/home/kadircet/repos/tmp/new_crasher -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/repro-aa9901.o -x c++ repro.cc
1. repro.cc:3:12: current parser token 'a'
2. repro.cc:1:1: parsing struct/union/class body 'a'
3. repro.cc:3:11: parsing function body 'a::b'
4. repro.cc:3:11: in compound statement ('{}')
#0 0x000000000746e327 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Unix/Signals.inc:602:13
#1 0x000000000746c0ae llvm::sys::RunSignalHandlers() /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Signals.cpp:105:18
#2 0x000000000746e9ba SignalHandler(int) /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Unix/Signals.inc:413:1
#3 0x00007efd7465a540 (/lib/x86_64-linux-gnu/libc.so.6+0x3c540)
#4 0x00007efd746a812c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007efd7465a4a2 raise ./signal/../sysdeps/posix/raise.c:27:6
#6 0x00007efd746444b2 abort ./stdlib/abort.c:81:7
#7 0x00007efd746443d5 _nl_load_domain ./intl/loadmsgcat.c:1177:9
#8 0x00007efd746533a2 (/lib/x86_64-linux-gnu/libc.so.6+0x353a2)
#9 0x000000000a014bf8 clang::LookupResult::checkDebugAssumptions() const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaLookup.cpp:334:3
#10 0x0000000009b95356 getResultKind /usr/local/google/home/kadircet/repos/llvm/clang/include/clang/Sema/Lookup.h:342:5
#11 0x0000000009b95356 clang::Sema::ClassifyName(clang::Scope*, clang::CXXScopeSpec&, clang::IdentifierInfo*&, clang::SourceLocation, clang::Token const&, clang::CorrectionCandidateCallback*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDecl.cpp:953:18
#12 0x00000000098a793e clang::Parser::TryAnnotateName(clang::CorrectionCandidateCallback*, clang::ImplicitTypenameContext) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:1770:53
#13 0x00000000099570dd clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseStmt.cpp:214:33
#14 0x0000000009956c55 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseStmt.cpp:117:20
#15 0x0000000009960ab1 clang::Parser::ParseCompoundStatementBody(bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseStmt.cpp:1205:11
#16 0x0000000009961a9d clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseStmt.cpp:2468:21
#17 0x0000000009954a3f isNot /usr/local/google/home/kadircet/repos/llvm/clang/include/clang/Lex/Token.h:99:52
#18 0x0000000009954a3f clang::Parser::ParseLexedMethodDef(clang::Parser::LexedMethod&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseCXXInlineMethods.cpp:600:14
#19 0x0000000009952e0a clang::Parser::ParseLexedMethodDefs(clang::Parser::ParsingClass&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseCXXInlineMethods.cpp:529:33
#20 0x00000000098f78e8 clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributes&, unsigned int, clang::Decl*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseDeclCXX.cpp:3674:21
#21 0x00000000098f4e9c clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributes&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseDeclCXX.cpp:0:7
#22 0x0000000009918955 empty /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/SmallVector.h:94:46
#23 0x0000000009918955 empty /usr/local/google/home/kadircet/repos/llvm/clang/include/clang/Sema/ParsedAttr.h:819:40
#24 0x0000000009918955 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseDecl.cpp:4327:23
#25 0x00000000098a3234 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:1123:10
#26 0x00000000098a2ed0 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:1229:12
#27 0x00000000098a1e8e clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:0:14
#28 0x000000000989fad7 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:0:12
#29 0x000000000989f27f clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:594:26
#30 0x0000000009899f6b clang::ParseAST(clang::Sema&, bool, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseAST.cpp:162:5
#31 0x0000000008037930 clang::FrontendAction::Execute() /usr/local/google/home/kadircet/repos/llvm/clang/lib/Frontend/FrontendAction.cpp:1067:10
#32 0x0000000007fab25f getPtr /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Error.h:270:42
#33 0x0000000007fab25f operator bool /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Error.h:233:16
#34 0x0000000007fab25f clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Frontend/CompilerInstance.cpp:1054:23
#35 0x000000000811efff clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:272:25
#36 0x0000000004ee5ea8 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /usr/local/google/home/kadircet/repos/llvm/clang/tools/driver/cc1_main.cpp:249:15
#37 0x0000000004ee2a41 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /usr/local/google/home/kadircet/repos/llvm/clang/tools/driver/driver.cpp:0:12
#38 0x0000000004ee1c39 clang_main(int, char**, llvm::ToolContext const&) /usr/local/google/home/kadircet/repos/llvm/clang/tools/driver/driver.cpp:407:12
#39 0x0000000004ef2431 main /usr/local/google/home/kadircet/repos/llvm/build/tools/clang/tools/driver/clang-driver.cpp:15:3
#40 0x00007efd746456ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#41 0x00007efd74645785 call_init ./csu/../csu/libc-start.c:128:20
#42 0x00007efd74645785 __libc_start_main ./csu/../csu/libc-start.c:347:5
#43 0x0000000004ededa1 _start (/usr/local/google/home/kadircet/repos/llvm/build/bin/clang-17+0x4ededa1)
(note that this assertion failure is leading into crashes in NDEBUG builds).
Without this patch clang's output was:
$ ~/repos/llvm/build/bin/clang -xc++ repro.cc
repro.cc:2:10: error: unknown type name 'c'
2 | static c a;
| ^
repro.cc:2:12: error: member 'a' has the same name as its class
2 | static c a;
| ^
repro.cc:3:13: error: expected unqualified-id
3 | void b(){a};
| ^
3 errors generated
Reverting for now as this is triggering lots of crashes in our production systems.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154503/new/
https://reviews.llvm.org/D154503
More information about the cfe-commits
mailing list