llvm / llvm/llvm-project

[clang] crashes when compiling variadic template fold expression with [[clang::always_inline]] attribute

Open
#192,776 2 comments 0 reactions 0 assignees View on GitHub
clang:frontend crash generated by fuzzer regression:15
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reproducer:
https://godbolt.org/z/xsMnGfv6h
```cpp
template int f1(size_t x) {return x;}
int f2(int x) {return x;}
template int f3(int x) {
[[clang::always_inline]] return f2(x) + (f1(x) + ...);
}

void g() {
f3<0, 1, 2>(0);
}
```

Backtrace:
```console
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: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics
1. parser at end of file
2. :3:24: instantiating function definition 'f3<0, 1, 2>'
#0 0x00000000044f2d68 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44f2d68)
#1 0x00000000044efb94 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44efb94)
#2 0x00000000044f01b4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44f01b4)
#3 0x000000000442d918 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x0000742ca6442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#5 0x0000742ca64969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#6 0x0000742ca6442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#7 0x0000742ca64287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#8 0x0000000000ddb1e2 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xddb1e2)
#9 0x000000000777b2b8 bool CheckStmtInlineAttr(clang::Sema&, clang::Stmt const*, clang::Stmt const*, clang::AttributeCommonInfo const&) SemaStmtAttr.cpp:0:0
#10 0x000000000797c89a clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformAttributedStmt(clang::AttributedStmt*, clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::StmtDiscardKind) SemaTemplateInstantiate.cpp:0:0
#11 0x000000000797b9c5 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) SemaTemplateInstantiate.cpp:0:0
#12 0x0000000007984e83 clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7984e83)
#13 0x0000000007a23b4c clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7a23b4c)
#14 0x0000000007a21db6 clang::Sema::PerformPendingInstantiations(bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7a21db6)
#15 0x0000000006f83762 clang::Sema::ActOnEndOfTranslationUnitFragment(clang::TUFragmentKind) (.part.0) Sema.cpp:0:0
#16 0x0000000006f83ae2 clang::Sema::ActOnEndOfTranslationUnit() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f83ae2)
#17 0x0000000006de8eaa clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6de8eaa)
#18 0x0000000006dc9bca clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dc9bca)
#19 0x0000000004ffa678 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ffa678)
#20 0x0000000005318cb5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5318cb5)
#21 0x00000000052978d8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52978d8)
#22 0x00000000054154ad clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x54154ad)
#23 0x0000000000de468b cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde468b)
#24 0x0000000000ddafea ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#25 0x0000000000ddb16d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#26 0x0000000005064ad9 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#27 0x000000000442dd54 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x442dd54)
#28 0x0000000005065106 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#29 0x00000000050235c2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50235c2)
#30 0x000000000502456e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x502456e)
#31 0x000000000502c215 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x502c215)
#32 0x0000000000de0a14 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde0a14)
#33 0x0000000000c9929a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc9929a)
#34 0x0000742ca6429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#35 0x0000742ca6429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#36 0x0000000000ddaa85 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xddaa85)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
```

Contributor guide

Open the contributing guide

Research direction

Start by compiling the linked Godbolt reproducer and then inspect CheckStmtInlineAttr in SemaStmtAttr.cpp and TransformAttributedStmt in SemaTemplateInstantiate.cpp, matching the supplied stack trace. Confirm the crash occurs while instantiating f3 with the always_inline attributed return statement; done means the reproducer compiles without a frontend crash.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.