[llvm-bugs] [Bug 28309] New: clang crashes on invalid C++ code with wrong qualified member access (without any proper diagnostics)

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Jun 25 23:22:51 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=28309

            Bug ID: 28309
           Summary: clang crashes on invalid C++ code with wrong qualified
                    member access (without any proper diagnostics)
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: su at cs.ucdavis.edu
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

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 also affects 
- 3.6.x to 3.8.x (the same behavior as that for the trunk) 
- 3.4.x to 3.5.x (crash, but after correct diagnostics),
but not 3.3, which rejects the code with proper diagnostics. 


$ clang++ -v
clang version 3.9.0 (trunk 273780)
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
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
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.3.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.1.1
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++-3.3 -c small.cpp
small.cpp:10:8: error: no member named 'i' in 'B'
  c.B::i;  // should be: c.A::i;
  ~    ^
1 error generated.
$
$ clang++ -c small.cpp
clang-3.9:
/tmp/llvm-builder/llvm-source-trunk/tools/clang/lib/Sema/SemaDeclCXX.cpp:1765:
bool clang::Sema::CheckDerivedToBaseConversion(clang::QualType,
clang::QualType, unsigned int, unsigned int, clang::SourceLocation,
clang::SourceRange, clang::DeclarationName, clang::CXXCastPath*, bool):
Assertion `DerivationOkay && "Can only be used with a derived-to-base
conversion"' failed.
#0 0x0000000001d2e515 llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/usr/local/clang-trunk/bin/clang-3.9+0x1d2e515)
#1 0x0000000001d2c3a6 llvm::sys::RunSignalHandlers()
(/usr/local/clang-trunk/bin/clang-3.9+0x1d2c3a6)
#2 0x0000000001d2c5c4 SignalHandler(int)
(/usr/local/clang-trunk/bin/clang-3.9+0x1d2c5c4)
#3 0x00007f487835a340 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x10340)
#4 0x00007f487714bcc9 gsignal
/build/eglibc-3GlaMS/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#5 0x00007f487714f0d8 abort
/build/eglibc-3GlaMS/eglibc-2.19/stdlib/abort.c:91:0
#6 0x00007f4877144b86 __assert_fail_base
/build/eglibc-3GlaMS/eglibc-2.19/assert/assert.c:92:0
#7 0x00007f4877144c32 (/lib/x86_64-linux-gnu/libc.so.6+0x2fc32)
#8 0x0000000002b32181
clang::Sema::CheckDerivedToBaseConversion(clang::QualType, clang::QualType,
unsigned int, unsigned int, clang::SourceLocation, clang::SourceRange,
clang::DeclarationName, llvm::SmallVector<clang::CXXBaseSpecifier*, 4u>*, bool)
(/usr/local/clang-trunk/bin/clang-3.9+0x2b32181)
#9 0x0000000002b321c3
clang::Sema::CheckDerivedToBaseConversion(clang::QualType, clang::QualType,
clang::SourceLocation, clang::SourceRange,
llvm::SmallVector<clang::CXXBaseSpecifier*, 4u>*, bool)
(/usr/local/clang-trunk/bin/clang-3.9+0x2b321c3)
#10 0x0000000002b992c1 clang::Sema::PerformObjectMemberConversion(clang::Expr*,
clang::NestedNameSpecifier*, clang::NamedDecl*, clang::NamedDecl*)
(/usr/local/clang-trunk/bin/clang-3.9+0x2b992c1)
#11 0x0000000002c4f2aa BuildFieldReferenceExpr(clang::Sema&, clang::Expr*,
bool, clang::SourceLocation, clang::CXXScopeSpec const&, clang::FieldDecl*,
clang::DeclAccessPair, clang::DeclarationNameInfo const&)
(/usr/local/clang-trunk/bin/clang-3.9+0x2c4f2aa)
#12 0x0000000002c55488 clang::Sema::BuildMemberReferenceExpr(clang::Expr*,
clang::QualType, clang::SourceLocation, bool, clang::CXXScopeSpec const&,
clang::SourceLocation, clang::NamedDecl*, clang::LookupResult&,
clang::TemplateArgumentListInfo const*, clang::Scope const*, bool,
clang::Sema::ActOnMemberAccessExtraArgs*)
(/usr/local/clang-trunk/bin/clang-3.9+0x2c55488)
#13 0x0000000002c5677c std::_Function_handler<clang::ActionResult<clang::Expr*,
true> (clang::Sema&, clang::TypoExpr*, clang::TypoCorrection),
LookupMemberExprInRecord(clang::Sema&, clang::LookupResult&, clang::Expr*,
clang::RecordType const*, clang::SourceLocation, bool, clang::CXXScopeSpec&,
bool, clang::TypoExpr*&)::{lambda(clang::Sema&, clang::TypoExpr*,
clang::TypoCorrection)#2}>::_M_invoke(std::_Any_data const&, clang::Sema&,
clang::TypoExpr*, clang::TypoCorrection)
(/usr/local/clang-trunk/bin/clang-3.9+0x2c5677c)
#14 0x0000000002c0dcbd std::function<clang::ActionResult<clang::Expr*, true>
(clang::Sema&, clang::TypoExpr*,
clang::TypoCorrection)>::operator()(clang::Sema&, clang::TypoExpr*,
clang::TypoCorrection) const (/usr/local/clang-trunk/bin/clang-3.9+0x2c0dcbd)
#15 0x0000000002c2db89 clang::TreeTransform<(anonymous
namespace)::TransformTypos>::TransformExpr(clang::Expr*)
(/usr/local/clang-trunk/bin/clang-3.9+0x2c2db89)
#16 0x0000000002c2e779 (anonymous
namespace)::TransformTypos::TryTransform(clang::Expr*)
(/usr/local/clang-trunk/bin/clang-3.9+0x2c2e779)
#17 0x0000000002c2ac5d clang::Sema::CorrectDelayedTyposInExpr(clang::Expr*,
clang::VarDecl*, llvm::function_ref<clang::ActionResult<clang::Expr*, true>
(clang::Expr*)>) (/usr/local/clang-trunk/bin/clang-3.9+0x2c2ac5d)
#18 0x0000000002c2bee4 clang::Sema::ActOnFinishFullExpr(clang::Expr*,
clang::SourceLocation, bool, bool, bool)
(/usr/local/clang-trunk/bin/clang-3.9+0x2c2bee4)
#19 0x0000000002d56310
clang::Sema::ActOnExprStmt(clang::ActionResult<clang::Expr*, true>)
(/usr/local/clang-trunk/bin/clang-3.9+0x2d56310)
#20 0x0000000002884c5d clang::Parser::ParseExprStatement()
(/usr/local/clang-trunk/bin/clang-3.9+0x2884c5d)
#21 0x00000000028820e7
clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*,
32u>&, clang::Parser::AllowedContsructsKind, clang::SourceLocation*,
clang::Parser::ParsedAttributesWithRange&)
(/usr/local/clang-trunk/bin/clang-3.9+0x28820e7)
#22 0x000000000288223e
clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*,
32u>&, clang::Parser::AllowedContsructsKind, clang::SourceLocation*)
(/usr/local/clang-trunk/bin/clang-3.9+0x288223e)
#23 0x0000000002886af9 clang::Parser::ParseCompoundStatementBody(bool)
(/usr/local/clang-trunk/bin/clang-3.9+0x2886af9)
#24 0x0000000002889349 clang::Parser::ParseFunctionStatementBody(clang::Decl*,
clang::Parser::ParseScope&) (/usr/local/clang-trunk/bin/clang-3.9+0x2889349)
#25 0x00000000028078eb
clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&,
clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*)
(/usr/local/clang-trunk/bin/clang-3.9+0x28078eb)
#26 0x00000000028277cd clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&,
unsigned int, clang::SourceLocation*, clang::Parser::ForRangeInit*)
(/usr/local/clang-trunk/bin/clang-3.9+0x28277cd)
#27 0x000000000280350d
clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec&, clang::AccessSpecifier)
(/usr/local/clang-trunk/bin/clang-3.9+0x280350d)
#28 0x0000000002803bb1
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*, clang::AccessSpecifier) [clone .part.222]
(/usr/local/clang-trunk/bin/clang-3.9+0x2803bb1)
#29 0x0000000002803bef
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*, clang::AccessSpecifier)
(/usr/local/clang-trunk/bin/clang-3.9+0x2803bef)
#30 0x0000000002808a60
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*) (/usr/local/clang-trunk/bin/clang-3.9+0x2808a60)
#31 0x0000000002809230
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&)
(/usr/local/clang-trunk/bin/clang-3.9+0x2809230)
#32 0x000000000280085b clang::ParseAST(clang::Sema&, bool, bool)
(/usr/local/clang-trunk/bin/clang-3.9+0x280085b)
#33 0x000000000249dd2e clang::CodeGenAction::ExecuteAction()
(/usr/local/clang-trunk/bin/clang-3.9+0x249dd2e)
#34 0x00000000021aa94e clang::FrontendAction::Execute()
(/usr/local/clang-trunk/bin/clang-3.9+0x21aa94e)
#35 0x00000000021800f6
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/usr/local/clang-trunk/bin/clang-3.9+0x21800f6)
#36 0x0000000002238932
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/usr/local/clang-trunk/bin/clang-3.9+0x2238932)
#37 0x0000000000af7b28 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/usr/local/clang-trunk/bin/clang-3.9+0xaf7b28)
#38 0x0000000000aab16c main (/usr/local/clang-trunk/bin/clang-3.9+0xaab16c)
#39 0x00007f4877136ec5 __libc_start_main
/build/eglibc-3GlaMS/eglibc-2.19/csu/libc-start.c:321:0
#40 0x0000000000af3b94 _start (/usr/local/clang-trunk/bin/clang-3.9+0xaf3b94)
Stack dump:
0.      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 201
-fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option
-fcolor-diagnostics -o small.o -x c++ small.cpp
1.      small.cpp:11:3: current parser token 'return'
2.      small.cpp:8:1: parsing function body 'main'
3.      small.cpp:8:1: 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 273780)
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-10afb3.cpp
clang-3.9: note: diagnostic msg: /tmp/small-10afb3.sh
clang-3.9: note: diagnostic msg:

********************
$


-----------------------------------


struct A { int i; };

struct B {};

struct C : A, B {};

int main ()
{ 
  C c;
  c.B::i;  // should be: c.A::i;
  return 0;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160626/da25e650/attachment-0001.html>


More information about the llvm-bugs mailing list