llvm / llvm-project

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

clang crashes on C++ code with ambiguous reference: Assertion `!Found.isAmbiguous() && "Cannot handle ambiguities here yet"' failed #28556

Open zhendongsu opened 8 years ago

zhendongsu commented 8 years ago
Bugzilla Link 28182
Version trunk
OS All
CC @DougGregor,@hfinkel

Extended Description

The current clang trunk crashes when compiling the following C++ test case on x86_64-linux-gnu in both 32-bit and 64-bit modes.

This is a regression from 3.8.x.

$ clang++ -v clang version 3.9.0 (trunk 272993) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /usr/local/clang-trunk/bin Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9 Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9.3 Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5.3.0 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4.7 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6.4 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7.3 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.5 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.3 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.3.0 Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Candidate multilib: x32;@mx32 Selected multilib: .;@m64 $ $ clang++ -c small.cpp clang-3.9: /tmp/llvm-builder/llvm-source-trunk/tools/clang/lib/Sema/SemaCXXScopeSpec.cpp:371: clang::NamedDecl clang::Sema::FindFirstQualifierInScope(clang::Scope, clang::NestedNameSpecifier*): Assertion `!Found.isAmbiguous() && "Cannot handle ambiguities here yet"' failed.

​0 0x0000000001d1b425 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/local/clang-trunk/bin/clang-3.9+0x1d1b425)

​1 0x0000000001d192b6 llvm::sys::RunSignalHandlers() (/usr/local/clang-trunk/bin/clang-3.9+0x1d192b6)

​2 0x0000000001d194d4 SignalHandler(int) (/usr/local/clang-trunk/bin/clang-3.9+0x1d194d4)

​3 0x00007f0b62465340 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x10340)

​4 0x00007f0b61683cc9 gsignal /build/eglibc-3GlaMS/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0

​5 0x00007f0b616870d8 abort /build/eglibc-3GlaMS/eglibc-2.19/stdlib/abort.c:91:0

​6 0x00007f0b6167cb86 __assert_fail_base /build/eglibc-3GlaMS/eglibc-2.19/assert/assert.c:92:0

​7 0x00007f0b6167cc32 (/lib/x86_64-linux-gnu/libc.so.6+0x2fc32)

​8 0x0000000002a193cf clang::Sema::FindFirstQualifierInScope(clang::Scope, clang::NestedNameSpecifier) (/usr/local/clang-trunk/bin/clang-3.9+0x2a193cf)

​9 0x0000000002c43694 clang::Sema::ActOnMemberAccessExpr(clang::Scope, clang::Expr, clang::SourceLocation, clang::tok::TokenKind, clang::CXXScopeSpec&, clang::SourceLocation, clang::UnqualifiedId&, clang::Decl*) (/usr/local/clang-trunk/bin/clang-3.9+0x2c43694)

​10 0x0000000002835ffe clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) (/usr/local/clang-trunk/bin/clang-3.9+0x2835ffe)

​11 0x0000000002830b18 clang::Parser::ParseCastExpression(bool, bool, bool&, clang::Parser::TypeCastState) (/usr/local/clang-trunk/bin/clang-3.9+0x2830b18)

​12 0x000000000283367d clang::Parser::ParseCastExpression(bool, bool, clang::Parser::TypeCastState) (/usr/local/clang-trunk/bin/clang-3.9+0x283367d)

​13 0x0000000002833709 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/usr/local/clang-trunk/bin/clang-3.9+0x2833709)

​14 0x0000000002833789 clang::Parser::ParseExpression(clang::Parser::TypeCastState) (/usr/local/clang-trunk/bin/clang-3.9+0x2833789)

​15 0x0000000002874b96 clang::Parser::ParseExprStatement() (/usr/local/clang-trunk/bin/clang-3.9+0x2874b96)

​16 0x000000000287206f clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt, 32u>&, clang::Parser::AllowedContsructsKind, clang::SourceLocation, clang::Parser::ParsedAttributesWithRange&) (/usr/local/clang-trunk/bin/clang-3.9+0x287206f)

​17 0x00000000028721ce clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt, 32u>&, clang::Parser::AllowedContsructsKind, clang::SourceLocation) (/usr/local/clang-trunk/bin/clang-3.9+0x28721ce)

​18 0x00000000028767b9 clang::Parser::ParseCompoundStatementBody(bool) (/usr/local/clang-trunk/bin/clang-3.9+0x28767b9)

​19 0x0000000002879009 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/usr/local/clang-trunk/bin/clang-3.9+0x2879009)

​20 0x00000000027fb191 clang::Parser::ParseLexedMethodDef(clang::Parser::LexedMethod&) (/usr/local/clang-trunk/bin/clang-3.9+0x27fb191)

​21 0x00000000027faf0e clang::Parser::ParseLexedMethodDefs(clang::Parser::ParsingClass&) (/usr/local/clang-trunk/bin/clang-3.9+0x27faf0e)

​22 0x000000000282bdf9 clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::Parser::ParsedAttributesWithRange&, unsigned int, clang::Decl*) (/usr/local/clang-trunk/bin/clang-3.9+0x282bdf9)

​23 0x000000000282cb1f clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::Parser::ParsedAttributesWithRange&) (/usr/local/clang-trunk/bin/clang-3.9+0x282cb1f)

​24 0x000000000280e830 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*) (/usr/local/clang-trunk/bin/clang-3.9+0x280e830)

​25 0x0000000002885e3e clang::Parser::ParseSingleDeclarationAfterTemplate(unsigned int, clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::AccessSpecifier, clang::AttributeList*) (/usr/local/clang-trunk/bin/clang-3.9+0x2885e3e)

​26 0x0000000002887827 clang::Parser::ParseTemplateDeclarationOrSpecialization(unsigned int, clang::SourceLocation&, clang::AccessSpecifier, clang::AttributeList*) (/usr/local/clang-trunk/bin/clang-3.9+0x2887827)

​27 0x0000000002887b9a clang::Parser::ParseDeclarationStartingWithTemplate(unsigned int, clang::SourceLocation&, clang::AccessSpecifier, clang::AttributeList*) (/usr/local/clang-trunk/bin/clang-3.9+0x2887b9a)

​28 0x0000000002819f14 clang::Parser::ParseDeclaration(unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) (/usr/local/clang-trunk/bin/clang-3.9+0x2819f14)

​29 0x00000000027f8882 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/usr/local/clang-trunk/bin/clang-3.9+0x27f8882)

​30 0x00000000027f9030 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&) (/usr/local/clang-trunk/bin/clang-3.9+0x27f9030)

​31 0x00000000027f065b clang::ParseAST(clang::Sema&, bool, bool) (/usr/local/clang-trunk/bin/clang-3.9+0x27f065b)

​32 0x0000000002486d3e clang::CodeGenAction::ExecuteAction() (/usr/local/clang-trunk/bin/clang-3.9+0x2486d3e)

​33 0x00000000021977fe clang::FrontendAction::Execute() (/usr/local/clang-trunk/bin/clang-3.9+0x21977fe)

​34 0x000000000216d266 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/local/clang-trunk/bin/clang-3.9+0x216d266)

​35 0x00000000022245c2 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/local/clang-trunk/bin/clang-3.9+0x22245c2)

​36 0x0000000000af0548 cc1_main(llvm::ArrayRef<char const>, char const, void*) (/usr/local/clang-trunk/bin/clang-3.9+0xaf0548)

​37 0x0000000000aa46dc main (/usr/local/clang-trunk/bin/clang-3.9+0xaa46dc)

​38 0x00007f0b6166eec5 __libc_start_main /build/eglibc-3GlaMS/eglibc-2.19/csu/libc-start.c:321:0

​39 0x0000000000aec5b4 _start (/usr/local/clang-trunk/bin/clang-3.9+0xaec5b4)

Stack dump:

  1. Program arguments: /usr/local/clang-trunk/bin/clang-3.9 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name small.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -coverage-file /data2/small.cpp -resource-dir /usr/local/clang-trunk/bin/../lib/clang/3.9.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/x86_64-linux-gnu/c++/4.9 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/x86_64-linux-gnu/c++/4.9 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/backward -internal-isystem /usr/local/include -internal-isystem /usr/local/clang-trunk/bin/../lib/clang/3.9.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 /data2 -ferror-limit 19 -fmessage-length 278 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o small.o -x c++ small.cpp
  2. small.cpp:10:13: current parser token '('
  3. small.cpp:6:22: parsing struct/union/class body 'B'
  4. small.cpp:9:3: parsing function body 'B::foo'
  5. small.cpp:9:3: in compound statement ('{}') clang-3.9: error: unable to execute command: Aborted (core dumped) clang-3.9: error: clang frontend command failed due to signal (use -v to see invocation) clang version 3.9.0 (trunk 272993) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /usr/local/clang-trunk/bin clang-3.9: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script. clang-3.9: note: diagnostic msg:

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang-3.9: note: diagnostic msg: /tmp/small-fa9a75.cpp clang-3.9: note: diagnostic msg: /tmp/small-fa9a75.sh clang-3.9: note: diagnostic msg:


$


template < class T > struct A { void f () {} };

template < class T > struct B : A < int >, A < char > { void foo (T *t) { t->A::f (); // should be: A < int >::f (); } };

fhahn commented 2 years ago

Still crashing: https://godbolt.org/z/YrGvd3jbr

llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-frontend

shafik commented 1 year ago

Code:

template < class T > struct A { void f () {} };

template < class T > struct B : A < int >, A < char > {
void foo (T *t) {
  t->A::f (); // should be: A < int >::f ();
}
};