-
Notifications
You must be signed in to change notification settings - Fork 15.8k
Closed as duplicate of#122892
Copy link
Labels
clang:codegenIR generation bugs: mangling, exceptions, etc.IR generation bugs: mangling, exceptions, etc.crashPrefer [crash-on-valid] or [crash-on-invalid]Prefer [crash-on-valid] or [crash-on-invalid]duplicateResolved as duplicateResolved as duplicateregression:18Regression in 18 releaseRegression in 18 release
Description
Summary
Clang crashes when compiling a small C++ program that calls a templated static method from a constructor. The crash yields a segmentation fault. Below is the minimal reproduction code, the command line used, and the backtrace.
Steps to Reproduce
- Save the following code as
a.cpp:
class A {
public:
A() {
int i = 0;
foo(i);
}
template <typename T>
static auto foo(T t) {
return t;
}
};
int main(void) {
A a{};
return 0;
}- Compile with Clang (version 19.1.7) using the following command:
clang++ -v -std=c++20 -Wall -O0 -g -o a a.cpp
- Observe the segmentation fault and compiler crash.
Expected Behavior
The code should fail to compile because the deduced return type cannot be used before it is defined.
Actual Behavior
Clang fails with a segmentation fault and requests that a bug report be filed.
clang++ -v -std=c++20 -Wall -O0 -g -o a a.cpp
clang version 19.1.7
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /opt/local/libexec/llvm-19/bin
"/opt/local/libexec/llvm-19/bin/clang" -cc1 -triple arm64-apple-macosx14.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name a.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -ffp-contract=on -fno-rounding-math -funwind-tables=1 -target-sdk-version=15.2 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -fdefine-target-os-macros -target-cpu apple-m1 -target-feature +zcm -target-feature +zcz -target-feature +v8.4a -target-feature +aes -target-feature +altnzcv -target-feature +ccdp -target-feature +complxnum -target-feature +crc -target-feature +dotprod -target-feature +fp-armv8 -target-feature +fp16fml -target-feature +fptoint -target-feature +fullfp16 -target-feature +jsconv -target-feature +lse -target-feature +neon -target-feature +pauth -target-feature +perfmon -target-feature +predres -target-feature +ras -target-feature +rcpc -target-feature +rdm -target-feature +sb -target-feature +sha2 -target-feature +sha3 -target-feature +specrestrict -target-feature +ssbs -target-abi darwinpcs -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=lldb -fdebug-compilation-dir=/Users/diego/cartesi/emulator/clang-crash -target-linker-version 1053.12 -v -fcoverage-compilation-dir=/Users/diego/cartesi/emulator/clang-crash -resource-dir /opt/local/libexec/llvm-19/lib/clang/19 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I/usr/local/include -internal-isystem /opt/local/libexec/llvm-19/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /opt/local/libexec/llvm-19/lib/clang/19/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -O0 -Wall -std=c++20 -fdeprecated-macro -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/c1/9gdm_twx72q20qy1qy3bcqvr0000gn/T/a-c9f6e1.o -x c++ a.cpp
clang -cc1 version 19.1.7 based upon LLVM 19.1.7 default target arm64-apple-darwin23.5.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/opt/local/libexec/llvm-19/bin/../include/c++/v1
/opt/local/libexec/llvm-19/lib/clang/19/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
a.cpp:5:9: error: cannot compile this l-value expression yet
5 | foo(i);
| ^~~
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/local/libexec/llvm-19/bin/clang -cc1 -triple arm64-apple-macosx14.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name a.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -ffp-contract=on -fno-rounding-math -funwind-tables=1 -target-sdk-version=15.2 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -fdefine-target-os-macros -target-cpu apple-m1 -target-feature +zcm -target-feature +zcz -target-feature +v8.4a -target-feature +aes -target-feature +altnzcv -target-feature +ccdp -target-feature +complxnum -target-feature +crc -target-feature +dotprod -target-feature +fp-armv8 -target-feature +fp16fml -target-feature +fptoint -target-feature +fullfp16 -target-feature +jsconv -target-feature +lse -target-feature +neon -target-feature +pauth -target-feature +perfmon -target-feature +predres -target-feature +ras -target-feature +rcpc -target-feature +rdm -target-feature +sb -target-feature +sha2 -target-feature +sha3 -target-feature +specrestrict -target-feature +ssbs -target-abi darwinpcs -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=lldb -fdebug-compilation-dir=/Users/diego/cartesi/emulator/clang-crash -target-linker-version 1053.12 -v -fcoverage-compilation-dir=/Users/diego/cartesi/emulator/clang-crash -resource-dir /opt/local/libexec/llvm-19/lib/clang/19 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I/usr/local/include -internal-isystem /opt/local/libexec/llvm-19/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /opt/local/libexec/llvm-19/lib/clang/19/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -O0 -Wall -std=c++20 -fdeprecated-macro -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/c1/9gdm_twx72q20qy1qy3bcqvr0000gn/T/a-c9f6e1.o -x c++ a.cpp
1. <eof> parser at end of file
2. Per-file LLVM IR generation
3. a.cpp:3:5: Generating code for declaration 'A::A'
4. a.cpp:3:9: LLVM IR generation of compound statement ('{}')
#0 0x00000001116d2d14 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/local/libexec/llvm-19/lib/libLLVM.dylib+0x14ed14)
#1 0x00000001116d0f28 llvm::sys::RunSignalHandlers() (/opt/local/libexec/llvm-19/lib/libLLVM.dylib+0x14cf28)
#2 0x00000001116d33d0 SignalHandler(int) (/opt/local/libexec/llvm-19/lib/libLLVM.dylib+0x14f3d0)
#3 0x0000000198ceb584 (/usr/lib/system/libsystem_platform.dylib+0x180477584)
#4 0x0000000106b2c02c arrangeFreeFunctionLikeCall(clang::CodeGen::CodeGenTypes&, clang::CodeGen::CodeGenModule&, clang::CodeGen::CallArgList const&, clang::FunctionType const*, unsigned int, bool) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x151402c)
#5 0x0000000106bf2108 clang::CodeGen::CodeGenFunction::EmitCall(clang::QualType, clang::CodeGen::CGCallee const&, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::Value*) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x15da108)
#6 0x0000000106bf1304 clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x15d9304)
#7 0x0000000106c34dec (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x161cdec)
#8 0x0000000106c24674 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x160c674)
#9 0x0000000106bd65dc clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x15be5dc)
#10 0x0000000106bd642c clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x15be42c)
#11 0x0000000106d13a70 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x16fba70)
#12 0x0000000106d14a40 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x16fca40)
#13 0x0000000106d1399c clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x16fb99c)
#14 0x0000000106b482e4 clang::CodeGen::CodeGenFunction::EmitConstructorBody(clang::CodeGen::FunctionArgList&) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x15302e4)
#15 0x0000000106d77990 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x175f990)
#16 0x0000000106b2737c clang::CodeGen::CodeGenModule::codegenCXXStructor(clang::GlobalDecl) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x150f37c)
#17 0x0000000106e1bcf0 (anonymous namespace)::ItaniumCXXABI::emitCXXStructor(clang::GlobalDecl) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x1803cf0)
#18 0x0000000106d919bc clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x17799bc)
#19 0x0000000106d85d9c clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x176dd9c)
#20 0x0000000106d85db4 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x176ddb4)
#21 0x0000000106d837ec clang::CodeGen::CodeGenModule::Release() (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x176b7ec)
#22 0x0000000106e370a8 (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x181f0a8)
#23 0x0000000106d69870 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x1751870)
#24 0x00000001057e5a30 clang::ParseAST(clang::Sema&, bool, bool) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x1cda30)
#25 0x000000010784e408 clang::FrontendAction::Execute() (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x2236408)
#26 0x00000001077d31d8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x21bb1d8)
#27 0x00000001078cd7bc clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/local/libexec/llvm-19/lib/libclang-cpp.dylib+0x22b57bc)
#28 0x0000000100afd9c4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/local/libexec/llvm-19/bin/clang+0x1000099c4)
#29 0x0000000100afb018 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) (/opt/local/libexec/llvm-19/bin/clang+0x100007018)
#30 0x0000000100afa44c clang_main(int, char**, llvm::ToolContext const&) (/opt/local/libexec/llvm-19/bin/clang+0x10000644c)
#31 0x0000000100b06470 main (/opt/local/libexec/llvm-19/bin/clang+0x100012470)
#32 0x00000001989320e0
clang++: error: unable to execute command: Segmentation fault: 11
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 19.1.7
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /opt/local/libexec/llvm-19/bin
clang++: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: /var/folders/c1/9gdm_twx72q20qy1qy3bcqvr0000gn/T/a-7ca65a.cpp
clang++: note: diagnostic msg: /var/folders/c1/9gdm_twx72q20qy1qy3bcqvr0000gn/T/a-7ca65a.sh
clang++: note: diagnostic msg: Crash backtrace is located in
clang++: note: diagnostic msg: /Users/diego/Library/Logs/DiagnosticReports/clang_<YYYY-MM-DD-HHMMSS>_<hostname>.crash
clang++: note: diagnostic msg: (choose the .crash file that corresponds to your crash)
clang++: note: diagnostic msg:
********************
Additional Details
- Clang version: 19.1.7
- Target: arm64-apple-darwin23.5.0
- Compile flags:
-v -std=c++20 -Wall -O0 -g
Attachments
Preprocessed source file, run script, crash back-trace, as requested.
Metadata
Metadata
Assignees
Labels
clang:codegenIR generation bugs: mangling, exceptions, etc.IR generation bugs: mangling, exceptions, etc.crashPrefer [crash-on-valid] or [crash-on-invalid]Prefer [crash-on-valid] or [crash-on-invalid]duplicateResolved as duplicateResolved as duplicateregression:18Regression in 18 releaseRegression in 18 release