Issue |
52805
|
Summary |
Frontend crash on malformed `template` blocks
|
Labels |
new issue
|
Assignees |
|
Reporter |
jcsp
|
This crash was found by accident while minimizing the example for #52804 -- one of the paths the minimizer took produced an entirely different crash on some malformed C++ code.
Crashes on 13.0.0 and 12.0.1, on x86_64.
## Reproducer
Attached as
[parser_crash.zip](https://github.com/llvm/llvm-project/files/7744301/parser_crash.zip)
Compile with `clang++ -std=c++20 -c`
## Output
```
$ clang++ -std=c++20 -c ./parser_crash.cpp
In file included from ./parser_crash.cpp:1:
/usr/include/bits/wordsize.h:1:15: error: expected '{'
namespace std ;
^
/usr/include/bits/wordsize.h:2239:1: error: expected '{'
namespace std
^
/usr/include/bits/wordsize.h:2240:2: error: expected '{'
inline namespace __1 {
^
/usr/include/bits/wordsize.h:2254:22: error: expected unqualified-id
class __tuple_leaf_Ip, _Hp, true
^
/usr/include/bits/wordsize.h:2269:41: error: expected '{' after base class list
: public __tuple_leaf<_Indx, _Tp>...
^
/usr/include/bits/wordsize.h:2278:48: error: expected '{' after base class list
struct _PackExpandsToThisTuple : false_type ;
^
/usr/include/bits/wordsize.h:2335:5: error: expected '<' after 'template'
__attribute__ () __attribute__ ()
^
/usr/include/bits/wordsize.h:2337:47: error: too few template arguments for alias template '_EnableIf'
template <class _AllocArgT, class _Alloc, _EnableIf<> = nullptr
^
/usr/include/bits/wordsize.h:170:1: note: template is declared here
using _EnableIf __attribute__(()) = typename _MetaBase<_Cond>::template _EnableIfImpl<>;
^
/usr/include/bits/wordsize.h:2337:61: error: value of type 'nullptr_t' is not implicitly convertible to 'int'
template <class _AllocArgT, class _Alloc, _EnableIf<> = nullptr
^~~~~~~
/usr/include/bits/wordsize.h:2342:5: error: expected '<' after 'template'
__attribute__ () __attribute__ () constexpr
^
/usr/include/bits/wordsize.h:2345:5: error: expected '<' after 'template'
__attribute__ () __attribute__ () constexpr
^
/usr/include/bits/wordsize.h:2348:7: error: expected '<' after 'template'
__attribute__ () __attribute__ ()
^
/usr/include/bits/wordsize.h:2351:7: error: expected '<' after 'template'
__attribute__ () __attribute__ ()
^
/usr/include/bits/wordsize.h:2393:9: error: expected '<' after 'template'
__attribute__ () __attribute__ ()
^
/usr/include/bits/wordsize.h:2396:9: error: expected '<' after 'template'
__attribute__ () __attribute__ ()
^
/usr/include/bits/wordsize.h:2414:9: error: expected '<' after 'template'
__attribute__ () __attribute__ ()
^
/usr/include/bits/wordsize.h:2417:9: error: expected '<' after 'template'
__attribute__ () __attribute__ ()
^
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /usr/bin/clang++ -std=c++20 -c -fcolor-diagnostics -o parser_crash.o ./parser_crash.cpp
1. /usr/include/bits/wordsize.h:2448:19: current parser token ';'
2. /usr/include/bits/wordsize.h:2240:9: parsing namespace '__1'
#0 0x00007f4f69a919a6 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib64/libLLVM-13.so+0xb5f9a6)
#1 0x00007f4f69a8f734 llvm::sys::RunSignalHandlers() (/lib64/libLLVM-13.so+0xb5d734)
#2 0x00007f4f699c1b28 (/lib64/libLLVM-13.so+0xa8fb28)
#3 0x00007f4f68b4b760 __restore_rt (/lib64/libc.so.6+0x42760)
#4 0x00007f4f708c535b (/lib64/libclang-cpp.so.13+0x193335b)
#5 0x00007f4f708c67c0 clang::Sema::DeclareImplicitDeductionGuides(clang::TemplateDecl*, clang::SourceLocation) (/lib64/libclang-cpp.so.13+0x19347c0)
#6 0x00007f4f706c17e3 (/lib64/libclang-cpp.so.13+0x172f7e3)
#7 0x00007f4f706c1dbf (/lib64/libclang-cpp.so.13+0x172fdbf)
#8 0x00007f4f706b1d81 clang::Sema::CppLookupName(clang::LookupResult&, clang::Scope*) (/lib64/libclang-cpp.so.13+0x171fd81)
#9 0x00007f4f706b2485 clang::Sema::LookupName(clang::LookupResult&, clang::Scope*, bool) (/lib64/libclang-cpp.so.13+0x1720485)
#10 0x00007f4f703d2f32 clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) (/lib64/libclang-cpp.so.13+0x1440f32)
#11 0x00007f4f708489f5 clang::Sema::ActOnTemplateDeclarator(clang::Scope*, llvm::MutableArrayRef<clang::TemplateParameterList*>, clang::Declarator&) (/lib64/libclang-cpp.so.13+0x18b69f5)
#12 0x00007f4f6fb81d29 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/lib64/libclang-cpp.so.13+0xbefd29)
#13 0x00007f4f6fc2d426 clang::Parser::ParseSingleDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/lib64/libclang-cpp.so.13+0xc9b426)
#14 0x00007f4f6fc3325a clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/lib64/libclang-cpp.so.13+0xca125a)
#15 0x00007f4f6fc3355c clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/lib64/libclang-cpp.so.13+0xca155c)
#16 0x00007f4f6fb93a9b clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributesWithRange&, clang::SourceLocation*) (/lib64/libclang-cpp.so.13+0xc01a9b)
#17 0x00007f4f6fc44d4f clang::Parser::ParseExternalDeclaration(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/lib64/libclang-cpp.so.13+0xcb2d4f)
#18 0x00007f4f6fba7369 clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) (/lib64/libclang-cpp.so.13+0xc15369)
#19 0x00007f4f6fba7f37 clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) (/lib64/libclang-cpp.so.13+0xc15f37)
#20 0x00007f4f6fb93bdb clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributesWithRange&, clang::SourceLocation*) (/lib64/libclang-cpp.so.13+0xc01bdb)
#21 0x00007f4f6fc44d4f clang::Parser::ParseExternalDeclaration(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/lib64/libclang-cpp.so.13+0xcb2d4f)
#22 0x00007f4f6fc45f78 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) (/lib64/libclang-cpp.so.13+0xcb3f78)
#23 0x00007f4f6fb6f3b9 clang::ParseAST(clang::Sema&, bool, bool) (/lib64/libclang-cpp.so.13+0xbdd3b9)
#24 0x00007f4f7140dc69 clang::FrontendAction::Execute() (/lib64/libclang-cpp.so.13+0x247bc69)
#25 0x00007f4f713ab219 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/lib64/libclang-cpp.so.13+0x2419219)
#26 0x00007f4f7147d64b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/lib64/libclang-cpp.so.13+0x24eb64b)
#27 0x0000560948928430 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/bin/clang+++0x16430)
#28 0x00005609489257bc (/usr/bin/clang+++0x137bc)
#29 0x00007f4f710c7f79 (/lib64/libclang-cpp.so.13+0x2135f79)
#30 0x00007f4f699c1bf7 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/lib64/libLLVM-13.so+0xa8fbf7)
#31 0x00007f4f710c881e (/lib64/libclang-cpp.so.13+0x213681e)
#32 0x00007f4f7109ddfb clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/lib64/libclang-cpp.so.13+0x210bdfb)
#33 0x00007f4f7109e5be clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/lib64/libclang-cpp.so.13+0x210c5be)
#34 0x00007f4f710a8532 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/lib64/libclang-cpp.so.13+0x2116532)
#35 0x0000560948923360 main (/usr/bin/clang+++0x11360)
#36 0x00007f4f68b36560 __libc_start_call_main (/lib64/libc.so.6+0x2d560)
#37 0x00007f4f68b3660c __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2d60c)
#38 0x0000560948924bf5 _start (/usr/bin/clang+++0x12bf5)
clang-13: error: clang frontend command failed with exit code 139 (use -v to see invocation)
clang version 13.0.0 (Fedora 13.0.0-3.fc35)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang-13: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-13: note: diagnostic msg: /tmp/parser_crash-378cb0.cpp
clang-13: note: diagnostic msg: /tmp/parser_crash-378cb0.sh
clang-13: note: diagnostic msg:
********************
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs