llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.34k stars 12.13k forks source link

`clang++-17`, `clang++-18` and `clang++-19` segfault when using aliased ARM64 SVE intrinsic types #107609

Open bashimao opened 2 months ago

bashimao commented 2 months ago

The following compiles with clang++-16, clang++-17 and clang++18:

#include <arm_sve.h>
#include <iostream>

int main(int,const char*[]) {
  svbool_t pg{svptrue_b8()};
  svint8_t a{svdup_s8(1)};
  svint8_t b{svdup_s8(2)};

  svint8_t c = svadd_s8_x(pg, a, b);

  std::cout << svaddv_s8(pg, c) << '\n';
}

But, if you alias the vector type with using as in the following:

#include <arm_sve.h>
#include <iostream>

using vec_t = svint8_t;

int main(int,const char*[]) {
  svbool_t pg{svptrue_b8()};
  vec_t a{svdup_s8(1)};
  vec_t b{svdup_s8(2)};

  vec_t c = svadd_s8_x(pg, a, b);

  std::cout << svaddv_s8(pg, c) << '\n';
}

and compile it:

clang++-18 -march=armv9-a main.cpp
clang++-17 -march=armv9-a main.cpp

both clang++-18 and clang++-17 will just die with segfault.

clang++-18 -march=armv9-a main.cpp
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-18/bin/clang -cc1 -triple aarch64-unknown-linux-gnu -emit-obj -mrelax-all -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=non-leaf -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu generic -target-feature +v9a -target-feature +crc -target-feature +dotprod -target-feature +complxnum -target-feature +fp-armv8 -target-feature +fullfp16 -target-feature +jsconv -target-feature +lse -target-feature +pauth -target-feature +ras -target-feature +rcpc -target-feature +rdm -target-feature +neon -target-feature +sve -target-feature +sve2 -target-abi aapcs -debugger-tuning=gdb -fdebug-compilation-dir=/monkey-wrench/minimal-sample -fcoverage-compilation-dir=/monkey-wrench/minimal-sample -resource-dir /usr/lib/llvm-18/lib/clang/18 -internal-isystem /usr/bin/../lib/gcc/aarch64-linux-gnu/13/../../../../include/c++/13 -internal-isystem /usr/bin/../lib/gcc/aarch64-linux-gnu/13/../../../../include/aarch64-linux-gnu/c++/13 -internal-isystem /usr/bin/../lib/gcc/aarch64-linux-gnu/13/../../../../include/c++/13/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/aarch64-linux-gnu/13/../../../../aarch64-linux-gnu/include -internal-externc-isystem /usr/include/aarch64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -target-feature +outline-atomics -target-feature -fmv -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/main-ad1a30.o -x c++ main.cpp
1.      main.cpp:19:1: current parser token 'int'
2.      main.cpp:6:5: LLVM IR generation of declaration 'main'
3.      main.cpp:6:5: Generating code for declaration 'main'
 #0 0x0000e82423ecd398 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xd9d398)
 #1 0x0000e82423ecb5a8 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xd9b5a8)
 #2 0x0000e82423ecdafc (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xd9dafc)
 #3 0x0000e8242e2009d0 (linux-vdso.so.1+0x9d0)
 #4 0x0000e8242401a3f8 llvm::LLVMContext::shouldDiscardValueNames() const (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xeea3f8)
 #5 0x0000e8242407b854 llvm::Value::setNameImpl(llvm::Twine const&) (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xf4b854)
 #6 0x0000e8242407bc10 llvm::Value::setName(llvm::Twine const&) (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xf4bc10)
 #7 0x0000e8242c2b6bd4 clang::CodeGen::CGBuilderInserter::InsertHelper(llvm::Instruction*, llvm::Twine const&, llvm::BasicBlock*, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, false, false, void, true>, false, false>) const (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1f36bd4)
 #8 0x0000e8242bf8ab58 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1c0ab58)
 #9 0x0000e8242c13ebe4 clang::CodeGen::CodeGenFunction::EmitStoreOfScalar(llvm::Value*, clang::CodeGen::Address, bool, clang::QualType, clang::CodeGen::LValueBaseInfo, clang::CodeGen::TBAAAccessInfo, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1dbebe4)
#10 0x0000e8242c13ee54 clang::CodeGen::CodeGenFunction::EmitStoreOfScalar(llvm::Value*, clang::CodeGen::LValue, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1dbee54)
#11 0x0000e8242c12df44 clang::CodeGen::CodeGenFunction::EmitStoreThroughLValue(clang::CodeGen::RValue, clang::CodeGen::LValue, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1dadf44)
#12 0x0000e8242c1145b4 clang::CodeGen::CodeGenFunction::EmitScalarInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1d945b4)
#13 0x0000e8242c1185b0 clang::CodeGen::CodeGenFunction::EmitExprAsInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1d985b0)
#14 0x0000e8242c1164f8 clang::CodeGen::CodeGenFunction::EmitAutoVarInit(clang::CodeGen::CodeGenFunction::AutoVarEmission const&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1d964f8)
#15 0x0000e8242c112c3c clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1d92c3c)
#16 0x0000e8242c112940 clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1d92940)
#17 0x0000e8242c25bc44 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1edbc44)
#18 0x0000e8242c25afe4 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1edafe4)
#19 0x0000e8242c264700 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1ee4700)
#20 0x0000e8242c2b2420 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1f32420)
#21 0x0000e8242c2b2e48 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1f32e48)
#22 0x0000e8242c2d2ab8 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1f52ab8)
#23 0x0000e8242c2cbb28 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1f4bb28)
#24 0x0000e8242c2cf72c clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1f4f72c)
#25 0x0000e8242c2ca78c clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1f4a78c)
#26 0x0000e8242c36bd58 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1febd58)
#27 0x0000e8242c2a5658 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1f25658)
#28 0x0000e8242af0a610 clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0xb8a610)
#29 0x0000e8242ccbfa34 clang::FrontendAction::Execute() (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x293fa34)
#30 0x0000e8242cc50590 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x28d0590)
#31 0x0000e8242cd38e4c clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x29b8e4c)
#32 0x0000ab1a073521c4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-18/bin/clang+0x121c4)
#33 0x0000ab1a0734fbac (/usr/lib/llvm-18/bin/clang+0xfbac)
#34 0x0000ab1a0734ed00 clang_main(int, char**, llvm::ToolContext const&) (/usr/lib/llvm-18/bin/clang+0xed00)
#35 0x0000ab1a0735ae40 main (/usr/lib/llvm-18/bin/clang+0x1ae40)
#36 0x0000e82422d084c4 (/lib/aarch64-linux-gnu/libc.so.6+0x284c4)
#37 0x0000e82422d08598 __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x28598)
#38 0x0000ab1a0734c970 _start (/usr/lib/llvm-18/bin/clang+0xc970)
clang++-18: error: unable to execute command: Segmentation fault (core dumped)
clang++-18: error: clang frontend command failed due to signal (use -v to see invocation)
Ubuntu clang version 18.1.3 (1ubuntu1)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang++-18: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++-18: note: diagnostic msg: /tmp/main-2c0338.cpp
clang++-18: note: diagnostic msg: /tmp/main-2c0338.sh
clang++-18: note: diagnostic msg:

********************

This code can be compiled with clang++-16 though. So, something was somewhat recently changed that broke it.

main-2c0338.cpp.txt main-2c0338.sh.txt

llvmbot commented 2 months ago

@llvm/issue-subscribers-clang-codegen

Author: Matthias Langer (bashimao)

The following compiles with clang++-16, clang++-17 and clang++18: ``` #include <arm_sve.h> #include <iostream> int main(int,const char*[]) { svbool_t pg{svptrue_b8()}; svint8_t a{svdup_s8(1)}; svint8_t b{svdup_s8(2)}; svint8_t c = svadd_s8_x(pg, a, b); std::cout << svaddv_s8(pg, c) << '\n'; } ``` But, if you alias the vector type with `using` as in the following: ``` #include <arm_sve.h> #include <iostream> using vec_t = svint8_t; int main(int,const char*[]) { svbool_t pg{svptrue_b8()}; vec_t a{svdup_s8(1)}; vec_t b{svdup_s8(2)}; vec_t c = svadd_s8_x(pg, a, b); std::cout << svaddv_s8(pg, c) << '\n'; } ``` and compile it: ``` clang++-18 -march=armv9-a main.cpp clang++-17 -march=armv9-a main.cpp ``` both `clang++-18` and `clang++-17` will just die with segfault. ``` clang++-18 -march=armv9-a main.cpp 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-18/bin/clang -cc1 -triple aarch64-unknown-linux-gnu -emit-obj -mrelax-all -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=non-leaf -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu generic -target-feature +v9a -target-feature +crc -target-feature +dotprod -target-feature +complxnum -target-feature +fp-armv8 -target-feature +fullfp16 -target-feature +jsconv -target-feature +lse -target-feature +pauth -target-feature +ras -target-feature +rcpc -target-feature +rdm -target-feature +neon -target-feature +sve -target-feature +sve2 -target-abi aapcs -debugger-tuning=gdb -fdebug-compilation-dir=/monkey-wrench/minimal-sample -fcoverage-compilation-dir=/monkey-wrench/minimal-sample -resource-dir /usr/lib/llvm-18/lib/clang/18 -internal-isystem /usr/bin/../lib/gcc/aarch64-linux-gnu/13/../../../../include/c++/13 -internal-isystem /usr/bin/../lib/gcc/aarch64-linux-gnu/13/../../../../include/aarch64-linux-gnu/c++/13 -internal-isystem /usr/bin/../lib/gcc/aarch64-linux-gnu/13/../../../../include/c++/13/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/aarch64-linux-gnu/13/../../../../aarch64-linux-gnu/include -internal-externc-isystem /usr/include/aarch64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -target-feature +outline-atomics -target-feature -fmv -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/main-ad1a30.o -x c++ main.cpp 1. main.cpp:19:1: current parser token 'int' 2. main.cpp:6:5: LLVM IR generation of declaration 'main' 3. main.cpp:6:5: Generating code for declaration 'main' #0 0x0000e82423ecd398 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xd9d398) #1 0x0000e82423ecb5a8 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xd9b5a8) #2 0x0000e82423ecdafc (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xd9dafc) #3 0x0000e8242e2009d0 (linux-vdso.so.1+0x9d0) #4 0x0000e8242401a3f8 llvm::LLVMContext::shouldDiscardValueNames() const (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xeea3f8) #5 0x0000e8242407b854 llvm::Value::setNameImpl(llvm::Twine const&) (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xf4b854) #6 0x0000e8242407bc10 llvm::Value::setName(llvm::Twine const&) (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xf4bc10) #7 0x0000e8242c2b6bd4 clang::CodeGen::CGBuilderInserter::InsertHelper(llvm::Instruction*, llvm::Twine const&, llvm::BasicBlock*, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, false, false, void, true>, false, false>) const (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1f36bd4) #8 0x0000e8242bf8ab58 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1c0ab58) #9 0x0000e8242c13ebe4 clang::CodeGen::CodeGenFunction::EmitStoreOfScalar(llvm::Value*, clang::CodeGen::Address, bool, clang::QualType, clang::CodeGen::LValueBaseInfo, clang::CodeGen::TBAAAccessInfo, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1dbebe4) #10 0x0000e8242c13ee54 clang::CodeGen::CodeGenFunction::EmitStoreOfScalar(llvm::Value*, clang::CodeGen::LValue, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1dbee54) #11 0x0000e8242c12df44 clang::CodeGen::CodeGenFunction::EmitStoreThroughLValue(clang::CodeGen::RValue, clang::CodeGen::LValue, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1dadf44) #12 0x0000e8242c1145b4 clang::CodeGen::CodeGenFunction::EmitScalarInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1d945b4) #13 0x0000e8242c1185b0 clang::CodeGen::CodeGenFunction::EmitExprAsInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1d985b0) #14 0x0000e8242c1164f8 clang::CodeGen::CodeGenFunction::EmitAutoVarInit(clang::CodeGen::CodeGenFunction::AutoVarEmission const&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1d964f8) #15 0x0000e8242c112c3c clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1d92c3c) #16 0x0000e8242c112940 clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1d92940) #17 0x0000e8242c25bc44 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1edbc44) #18 0x0000e8242c25afe4 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1edafe4) #19 0x0000e8242c264700 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1ee4700) #20 0x0000e8242c2b2420 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1f32420) #21 0x0000e8242c2b2e48 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1f32e48) #22 0x0000e8242c2d2ab8 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1f52ab8) #23 0x0000e8242c2cbb28 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1f4bb28) #24 0x0000e8242c2cf72c clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1f4f72c) #25 0x0000e8242c2ca78c clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1f4a78c) #26 0x0000e8242c36bd58 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1febd58) #27 0x0000e8242c2a5658 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1f25658) #28 0x0000e8242af0a610 clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0xb8a610) #29 0x0000e8242ccbfa34 clang::FrontendAction::Execute() (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x293fa34) #30 0x0000e8242cc50590 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x28d0590) #31 0x0000e8242cd38e4c clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x29b8e4c) #32 0x0000ab1a073521c4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-18/bin/clang+0x121c4) #33 0x0000ab1a0734fbac (/usr/lib/llvm-18/bin/clang+0xfbac) #34 0x0000ab1a0734ed00 clang_main(int, char**, llvm::ToolContext const&) (/usr/lib/llvm-18/bin/clang+0xed00) #35 0x0000ab1a0735ae40 main (/usr/lib/llvm-18/bin/clang+0x1ae40) #36 0x0000e82422d084c4 (/lib/aarch64-linux-gnu/libc.so.6+0x284c4) #37 0x0000e82422d08598 __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x28598) #38 0x0000ab1a0734c970 _start (/usr/lib/llvm-18/bin/clang+0xc970) clang++-18: error: unable to execute command: Segmentation fault (core dumped) clang++-18: error: clang frontend command failed due to signal (use -v to see invocation) Ubuntu clang version 18.1.3 (1ubuntu1) Target: aarch64-unknown-linux-gnu Thread model: posix InstalledDir: /usr/bin clang++-18: note: diagnostic msg: ******************** PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang++-18: note: diagnostic msg: /tmp/main-2c0338.cpp clang++-18: note: diagnostic msg: /tmp/main-2c0338.sh clang++-18: note: diagnostic msg: ******************** ``` This code can be compiled with `clang++-16` though. So, something was somewhat recently changed that broke it. [main-2c0338.cpp.txt](https://github.com/user-attachments/files/16910995/main-2c0338.cpp.txt) [main-2c0338.sh.txt](https://github.com/user-attachments/files/16910996/main-2c0338.sh.txt)
EugeneZelenko commented 2 months ago

Could you please try 19 or main branch? https://godbolt.org should be helpful.

bashimao commented 2 months ago

@EugeneZelenko It compiles on Godbolt. I compile for ARM64 on ARM64. I suppose the Godbolt compiler cross compiles on x86 for ARM64. So maybe this problem is just limited to the ARM64-compiled version of Clang?

bashimao commented 2 months ago

@EugeneZelenko https://godbolt.org/z/d4aeYnaM4

bashimao commented 2 months ago

@EugeneZelenko Regarding clang-19. Yes same problem.

wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 19
clang++-19 -march=armv9-a main.cpp

Result:

$ clang++-19 -march=armv9-a main.cpp
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-19/bin/clang -cc1 -triple aarch64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=non-leaf -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu generic -target-feature +v9a -target-feature +bti -target-feature +ccidx -target-feature +complxnum -target-feature +crc -target-feature +dit -target-feature +dotprod -target-feature +flagm -target-feature +fp-armv8 -target-feature +fullfp16 -target-feature +jsconv -target-feature +lse -target-feature +neon -target-feature +pauth -target-feature +predres -target-feature +ras -target-feature +rcpc -target-feature +rdm -target-feature +sb -target-feature +ssbs -target-feature +sve -target-feature +sve2 -target-abi aapcs -debugger-tuning=gdb -fdebug-compilation-dir=/monkey-wrench/minimal-sample -fcoverage-compilation-dir=/monkey-wrench/minimal-sample -resource-dir /usr/lib/llvm-19/lib/clang/19 -internal-isystem /usr/lib/gcc/aarch64-linux-gnu/13/../../../../include/c++/13 -internal-isystem /usr/lib/gcc/aarch64-linux-gnu/13/../../../../include/aarch64-linux-gnu/c++/13 -internal-isystem /usr/lib/gcc/aarch64-linux-gnu/13/../../../../include/c++/13/backward -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/aarch64-linux-gnu/13/../../../../aarch64-linux-gnu/include -internal-externc-isystem /usr/include/aarch64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -target-feature +outline-atomics -target-feature -fmv -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/main-226fbc.o -x c++ main.cpp
1.      main.cpp:19:1: current parser token 'int'
2.      main.cpp:6:5: LLVM IR generation of declaration 'main'
3.      main.cpp:6:5: Generating code for declaration 'main'
 #0 0x0000f90fb5115e7c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.1+0xeb5e7c)
 #1 0x0000f90fb5113ec0 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.1+0xeb3ec0)
 #2 0x0000f90fb51165e0 (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.1+0xeb65e0)
 #3 0x0000f90fbfd009d0 (linux-vdso.so.1+0x9d0)
 #4 0x0000f90fb5268a08 llvm::LLVMContext::shouldDiscardValueNames() const (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.1+0x1008a08)
 #5 0x0000f90fb52d1010 llvm::Value::setNameImpl(llvm::Twine const&) (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.1+0x1071010)
 #6 0x0000f90fb52d13d0 llvm::Value::setName(llvm::Twine const&) (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.1+0x10713d0)
 #7 0x0000f90fbdbe12c4 clang::CodeGen::CGBuilderInserter::InsertHelper(llvm::Instruction*, llvm::Twine const&, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, false, false, void, true, llvm::BasicBlock>, false, false>) const (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x21e12c4)
 #8 0x0000f90fbd8a2808 (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1ea2808)
 #9 0x0000f90fbda61adc clang::CodeGen::CodeGenFunction::EmitStoreOfScalar(llvm::Value*, clang::CodeGen::Address, bool, clang::QualType, clang::CodeGen::LValueBaseInfo, clang::CodeGen::TBAAAccessInfo, bool, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2061adc)
#10 0x0000f90fbda61d50 clang::CodeGen::CodeGenFunction::EmitStoreOfScalar(llvm::Value*, clang::CodeGen::LValue, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2061d50)
#11 0x0000f90fbda50424 clang::CodeGen::CodeGenFunction::EmitStoreThroughLValue(clang::CodeGen::RValue, clang::CodeGen::LValue, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2050424)
#12 0x0000f90fbda35bd0 clang::CodeGen::CodeGenFunction::EmitScalarInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2035bd0)
#13 0x0000f90fbda3a358 clang::CodeGen::CodeGenFunction::EmitExprAsInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x203a358)
#14 0x0000f90fbda37e30 clang::CodeGen::CodeGenFunction::EmitAutoVarInit(clang::CodeGen::CodeGenFunction::AutoVarEmission const&) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2037e30)
#15 0x0000f90fbda34188 clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2034188)
#16 0x0000f90fbda33e8c clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2033e8c)
#17 0x0000f90fbdb81454 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2181454)
#18 0x0000f90fbdb800f0 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x21800f0)
#19 0x0000f90fbdb8af6c clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x218af6c)
#20 0x0000f90fbdbdd74c clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x21dd74c)
#21 0x0000f90fbdbfdc1c clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x21fdc1c)
#22 0x0000f90fbdbf6b20 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x21f6b20)
#23 0x0000f90fbdbfa598 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x21fa598)
#24 0x0000f90fbdbf586c clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x21f586c)
#25 0x0000f90fbdc999d8 (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x22999d8)
#26 0x0000f90fbdbcf37c clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x21cf37c)
#27 0x0000f90fbc641840 clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xc41840)
#28 0x0000f90fbe6933c0 clang::FrontendAction::Execute() (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2c933c0)
#29 0x0000f90fbe61c554 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2c1c554)
#30 0x0000f90fbe7108f8 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2d108f8)
#31 0x0000c01920cb0fd4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-19/bin/clang+0x10fd4)
#32 0x0000c01920cae6b8 (/usr/lib/llvm-19/bin/clang+0xe6b8)
#33 0x0000c01920cad738 clang_main(int, char**, llvm::ToolContext const&) (/usr/lib/llvm-19/bin/clang+0xd738)
#34 0x0000c01920cba21c main (/usr/lib/llvm-19/bin/clang+0x1a21c)
#35 0x0000f90fb3d484c4 (/lib/aarch64-linux-gnu/libc.so.6+0x284c4)
#36 0x0000f90fb3d48598 __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x28598)
#37 0x0000c01920cac4b0 _start (/usr/lib/llvm-19/bin/clang+0xc4b0)
clang++-19: error: unable to execute command: Segmentation fault (core dumped)
clang++-19: error: clang frontend command failed due to signal (use -v to see invocation)
Ubuntu clang version 19.1.0 (++20240903073245+9b6180ed2ecb-1~exp1~20240903073259.29)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin
clang++-19: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++-19: note: diagnostic msg: /tmp/main-d238cc.cpp
clang++-19: note: diagnostic msg: /tmp/main-d238cc.sh
clang++-19: note: diagnostic msg:

********************
pinskia commented 2 months ago

Same issue in GCC: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116595

I think it is the same issue can be reproduced with the RISC-V V intrinsic types too.

bashimao commented 2 months ago

@pinskia Not sure. I compiles flawlessly on GCC-12, 13, and 14. Also, this doesn't happen with ARM Neon intrinsic types. Only with SVE intrinsic types.