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

Crash on invalid code. #56924

Open AlexeyDmitriev opened 2 years ago

AlexeyDmitriev commented 2 years ago

The following code (not correct c++, reduced by creduce) crashes the compiler with the request to submit bug report instead of giving a compiler error.

Code:

template <typename a, (struct {          a *b {           delete b

command to reproduce

➜  ~  "/usr/lib/llvm-14/bin/clang" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-obj" "--mrelax-relocations" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "perfect_hash_table.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=none" "-menable-no-infs" "-menable-no-nans" "-fapprox-func" "-menable-unsafe-fp-math" "-fno-signed-zeros" "-mreassociate" "-freciprocal-math" "-fdenormal-fp-math=preserve-sign,preserve-sign" "-ffp-contract=fast" "-fno-rounding-math" "-ffast-math" "-ffinite-math-only" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-target-feature" "+sse4.2" "-target-feature" "+pclmul" "-mllvm" "-x86-branches-within-32B-boundaries" "-tune-cpu" "generic" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debug-info-kind=constructor" "-dwarf-version=4" "-debugger-tuning=gdb" "-fcoverage-compilation-dir=~/mybuild" "-D" "BOOST_ASIO_ENABLE_SEQUENTIAL_STRAND_ALLOCATION" "-D" "BOOST_ASIO_NO_DEPRECATED" "-D" "BOOST_ASIO_STRAND_IMPLEMENTATIONS=200000" "-D" "BOOST_SYSTEM_NO_DEPRECATED" "-D" "CPPHTTPLIB_COMPRESSION_BUFSIZ=size_t(1048576u)" "-D" "CPPHTTPLIB_RECV_BUFSIZ=size_t(1048576u)" "-D" "CPPHTTPLIB_ZLIB_SUPPORT" "-D" "JEMALLOC_EXPORT=" "-D" "RAPIDJSON_HAS_STDSTRING" "-D" "SIMDJSON_THREADS_ENABLED=1" "-D" "USE_OS_TZDB=1" "-D" "NDEBUG" "-O3" "-Wall" "-Wextra" "-Wold-style-cast" "-Wconversion" "-Wsign-conversion" "-Wunreachable-code" "-Wno-missing-braces" "-Wno-error=deprecated-declarations" "-Wno-overriding-t-option" "-Wno-gnu-zero-variadic-macro-arguments" "-Werror" "-pedantic" "-std=c++2a" "-fdeprecated-macro" "-fdebug-compilation-dir=~/mybuild" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fno-implicit-modules" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c++" "perfect_hash_table-3d772a.cpp"

Output

perfect_hash_table-3d772a.cpp:1:67: error: expected ';' at end of declaration list
template <typename a, (struct {          a *b {           delete b
                                                                  ^
                                                                  ;
perfect_hash_table-3d772a.cpp:1:67: error: expected '}'
perfect_hash_table-3d772a.cpp:1:31: note: to match this '{'
template <typename a, (struct {          a *b {           delete b
                              ^
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/lib/llvm-14/bin/clang -cc1 -triple x86_64-pc-linux-gnu -emit-obj --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name perfect_hash_table.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -menable-no-infs -menable-no-nans -fapprox-func -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -fdenormal-fp-math=preserve-sign,preserve-sign -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -target-feature +sse4.2 -target-feature +pclmul -mllvm -x86-branches-within-32B-boundaries -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -fcoverage-compilation-dir=~/mybuild -D BOOST_ASIO_ENABLE_SEQUENTIAL_STRAND_ALLOCATION -D BOOST_ASIO_NO_DEPRECATED -D BOOST_ASIO_STRAND_IMPLEMENTATIONS=200000 -D BOOST_SYSTEM_NO_DEPRECATED -D CPPHTTPLIB_COMPRESSION_BUFSIZ=size_t(1048576u) -D CPPHTTPLIB_RECV_BUFSIZ=size_t(1048576u) -D CPPHTTPLIB_ZLIB_SUPPORT -D JEMALLOC_EXPORT= -D RAPIDJSON_HAS_STDSTRING -D SIMDJSON_THREADS_ENABLED=1 -D USE_OS_TZDB=1 -D NDEBUG -O3 -Wall -Wextra -Wold-style-cast -Wconversion -Wsign-conversion -Wunreachable-code -Wno-missing-braces -Wno-error=deprecated-declarations -Wno-overriding-t-option -Wno-gnu-zero-variadic-macro-arguments -Werror -pedantic -std=c++2a -fdeprecated-macro -fdebug-compilation-dir=~/mybuild -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fcxx-exceptions -fexceptions -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -x c++ perfect_hash_table-3d772a.cpp
1.  <eof> parser at end of file
2.  perfect_hash_table-3d772a.cpp:1:24: parsing struct/union/class body '(anonymous)'
 #0 0x00007f51e029c041 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xe4b041)
 #1 0x00007f51e0299d8e llvm::sys::RunSignalHandlers() (/usr/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xe48d8e)
 #2 0x00007f51e029c57b (/usr/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xe4b57b)
 #3 0x00007f51e950b3c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x143c0)
 #4 0x00007f51e67f5027 clang::ASTContext::getTypeInfoImpl(clang::Type const*) const (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xae5027)
 #5 0x00007f51e67f6516 clang::ASTContext::getTypeInfo(clang::Type const*) const (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xae6516)
 #6 0x00007f51e67f6752 clang::ASTContext::getTypeAlignIfKnown(clang::QualType, bool) const (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xae6752)
 #7 0x00007f51e71a895d (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0x149895d)
 #8 0x00007f51e71ab539 clang::Sema::ActOnCXXDelete(clang::SourceLocation, bool, bool, clang::Expr*) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0x149b539)
 #9 0x00007f51e677130e clang::Parser::ParseCXXDeleteExpression(bool, clang::SourceLocation) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xa6130e)
#10 0x00007f51e675ba6b clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xa4ba6b)
#11 0x00007f51e6757166 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xa47166)
#12 0x00007f51e677720c clang::Parser::ParseBraceInitializer() (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xa6720c)
#13 0x00007f51e674fe90 clang::Parser::ParseCXXMemberInitializer(clang::Decl*, bool, clang::SourceLocation&) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xa3fe90)
#14 0x00007f51e67194c0 clang::Parser::ParseLexedMemberInitializer(clang::Parser::LateParsedMemberInitializer&) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xa094c0)
#15 0x00007f51e6717b3b clang::Parser::ParseLexedMemberInitializers(clang::Parser::ParsingClass&) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xa07b3b)
#16 0x00007f51e674ae5c clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributesWithRange&, unsigned int, clang::Decl*) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xa3ae5c)
#17 0x00007f51e6748636 clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributesWithRange&) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xa38636)
#18 0x00007f51e67281b4 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xa181b4)
#19 0x00007f51e673d368 clang::Parser::ParseParameterDeclarationClause(clang::DeclaratorContext, clang::ParsedAttributes&, llvm::SmallVectorImpl<clang::DeclaratorChunk::ParamInfo>&, clang::SourceLocation&) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xa2d368)
#20 0x00007f51e673b156 clang::Parser::ParseFunctionDeclarator(clang::Declarator&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&, bool, bool) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xa2b156)
#21 0x00007f51e673a297 clang::Parser::ParseParenDeclarator(clang::Declarator&) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xa2a297)
#22 0x00007f51e67388b9 clang::Parser::ParseDirectDeclarator(clang::Declarator&) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xa288b9)
#23 0x00007f51e6737576 clang::Parser::ParseDeclaratorInternal(clang::Declarator&, void (clang::Parser::*)(clang::Declarator&)) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xa27576)
#24 0x00007f51e67c537c clang::Parser::ParseNonTypeTemplateParameter(unsigned int, unsigned int) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xab537c)
#25 0x00007f51e67c3c4b clang::Parser::ParseTemplateParameter(unsigned int, unsigned int) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xab3c4b)
#26 0x00007f51e67c375e clang::Parser::ParseTemplateParameterList(unsigned int, llvm::SmallVectorImpl<clang::NamedDecl*>&) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xab375e)
#27 0x00007f51e67c1ecb clang::Parser::ParseTemplateParameters(clang::Parser::MultiParseScope&, unsigned int, llvm::SmallVectorImpl<clang::NamedDecl*>&, clang::SourceLocation&, clang::SourceLocation&) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xab1ecb)
#28 0x00007f51e67c1989 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xab1989)
#29 0x00007f51e67c166f clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xab166f)
#30 0x00007f51e67270ab clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributesWithRange&, clang::SourceLocation*) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xa170ab)
#31 0x00007f51e67d23e4 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xac23e4)
#32 0x00007f51e67d128d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xac128d)
#33 0x00007f51e67d0df7 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xac0df7)
#34 0x00007f51e6714136 clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xa04136)
#35 0x00007f51e788fb51 clang::CodeGenAction::ExecuteAction() (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0x1b7fb51)
#36 0x00007f51e822a677 clang::FrontendAction::Execute() (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0x251a677)
#37 0x00007f51e8183346 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0x2473346)
#38 0x00007f51e82a369b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14+0x259369b)
#39 0x00000000004131b3 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-14/bin/clang+0x4131b3)
#40 0x000000000041140c (/usr/lib/llvm-14/bin/clang+0x41140c)
#41 0x0000000000411257 main (/usr/lib/llvm-14/bin/clang+0x411257)
#42 0x00007f51deaf80b3 __libc_start_main /build/glibc-sMfBJT/glibc-2.31/csu/../csu/libc-start.c:342:3
#43 0x000000000040e30e _start (/usr/lib/llvm-14/bin/clang+0x40e30e)
[1]    2776960 segmentation fault (core dumped)  "/usr/lib/llvm-14/bin/clang" "-cc1" "-triple" "x86_64-pc-linux-gnu"
pmor13 commented 2 years ago

@AlexeyDmitriev See my comment in https://github.com/llvm/llvm-project/issues/55732.

llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-frontend

vient commented 2 years ago

@pmor13 here diagnostics can be fixed while clang will still crash

template<typename a,(struct{a*b{delete b;}

Also, the only needed flag is -std=c++17, on 14 and lower clang works fine: https://godbolt.org/z/3WMW9oqax

pmor13 commented 2 years ago

@vient FYI: version with no anonymous struct does not lead to crash:

template<typename a,(struct X{a*b{delete b;}
6 errors generated.