llvm / llvm-project

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

Clang segmentation fault when compiling SVE code under macOS #107527

Open SadiinsoSnowfall opened 2 months ago

SadiinsoSnowfall commented 2 months ago

Compiling the following snippet on clang 18.1.8, installed via homebrew on macOS, causes a segfault when targeting SVE (any vector width):

#include <arm_sve.h>

void test(svbool_t t, svint32_t a, svint32_t b) {
    svsub_s32_m(t, a, b);
}

int main() {}

The code was compiled using the following command:

clang -march=armv8-a+sve -msve-vector-bits=128 test.cpp

Compiler output:

PLEASE submit a bug report to https://github.com/Homebrew/homebrew-core/issues and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.  Program arguments: /opt/homebrew/Cellar/llvm/18.1.8/bin/clang-18 -cc1 -triple arm64-apple-macosx15.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -ffp-contract=on -fno-rounding-math -funwind-tables=1 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -fbuiltin-headers-in-system-modules -fdefine-target-os-macros -target-cpu apple-m1 -target-feature +zcm -target-feature +zcz -target-feature +v8a -target-feature +fp-armv8 -target-feature +fullfp16 -target-feature +neon -target-feature +sve -target-abi darwinpcs -mvscale-max=1 -mvscale-min=1 -debugger-tuning=lldb -fdebug-compilation-dir=/tmp -target-linker-version 1053.12 -fcoverage-compilation-dir=/tmp -resource-dir /opt/homebrew/Cellar/llvm/18.1.8/lib/clang/18 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -internal-isystem /opt/homebrew/opt/llvm/bin/../include/c++/v1 -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/local/include -internal-isystem /opt/homebrew/Cellar/llvm/18.1.8/lib/clang/18/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include -fdeprecated-macro -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/_c/4w43161s72x8kd5w24cp7vlm0000gn/T/test-789251.o -x c++ test.cpp
1.  <eof> parser at end of file
2.  Code generation
3.  Running pass 'Function Pass Manager' on module 'test.cpp'.
4.  Running pass 'AArch64 Instruction Selection' on function '@_Z4testu10__SVBool_tu11__SVInt32_tS0_'
 #0 0x0000000118c7dd60 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libLLVM.dylib+0x4695d60)
 #1 0x0000000118c7e134 SignalHandler(int) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libLLVM.dylib+0x4696134)
 #2 0x000000018388c184 (/usr/lib/system/libsystem_platform.dylib+0x180484184)
 #3 0x0000000116b7a3b8 llvm::AArch64TargetLowering::LowerFormalArguments(llvm::SDValue, unsigned int, bool, llvm::SmallVectorImpl<llvm::ISD::InputArg> const&, llvm::SDLoc const&, llvm::SelectionDAG&, llvm::SmallVectorImpl<llvm::SDValue>&) const (/opt/homebrew/Cellar/llvm/18.1.8/lib/libLLVM.dylib+0x25923b8)
 #4 0x00000001151f4648 llvm::SelectionDAGISel::LowerArguments(llvm::Function const&) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libLLVM.dylib+0xc0c648)
 #5 0x000000011527faf8 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libLLVM.dylib+0xc97af8)
 #6 0x000000011527e578 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libLLVM.dylib+0xc96578)
 #7 0x0000000114c41054 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libLLVM.dylib+0x659054)
 #8 0x00000001148fc0e4 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libLLVM.dylib+0x3140e4)
 #9 0x00000001148f03ec llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libLLVM.dylib+0x3083ec)
#10 0x00000001085220cc clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libclang-cpp.dylib+0x15960cc)
#11 0x00000001088c7644 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libclang-cpp.dylib+0x193b644)
#12 0x00000001071970f8 clang::ParseAST(clang::Sema&, bool, bool) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libclang-cpp.dylib+0x20b0f8)
#13 0x0000000109028dd4 clang::FrontendAction::Execute() (/opt/homebrew/Cellar/llvm/18.1.8/lib/libclang-cpp.dylib+0x209cdd4)
#14 0x0000000108fabad4 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libclang-cpp.dylib+0x201fad4)
#15 0x000000010907bc28 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libclang-cpp.dylib+0x20efc28)
#16 0x0000000102526b28 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/homebrew/Cellar/llvm/18.1.8/bin/clang-18+0x100006b28)
#17 0x0000000102525218 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) (/opt/homebrew/Cellar/llvm/18.1.8/bin/clang-18+0x100005218)
#18 0x0000000102523dac clang_main(int, char**, llvm::ToolContext const&) (/opt/homebrew/Cellar/llvm/18.1.8/bin/clang-18+0x100003dac)
#19 0x0000000102530e38 main (/opt/homebrew/Cellar/llvm/18.1.8/bin/clang-18+0x100010e38)
#20 0x00000001834d4274
clang: error: unable to execute command: Segmentation fault: 11
clang: error: clang frontend command failed due to signal (use -v to see invocation)
Homebrew clang version 18.1.8
Target: arm64-apple-darwin24.1.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin

This issue might be related to #49751, and manifested under clang 18.1.8 on macOS 15.1 on an apple M3 based machine.

llvmbot commented 2 months ago

@llvm/issue-subscribers-backend-aarch64

Author: Sadiinso (SadiinsoSnowfall)

Compiling the following snippet on `clang 18.1.8`, installed via homebrew on macOS, causes a segfault when targeting SVE (any vector width): ```c++ #include <arm_sve.h> void test(svbool_t t, svint32_t a, svint32_t b) { svsub_s32_m(t, a, b); } int main() {} ``` The code was compiled using the following command: ``` clang -march=armv8-a+sve -msve-vector-bits=128 test.cpp ``` Compiler output: ``` PLEASE submit a bug report to https://github.com/Homebrew/homebrew-core/issues and include the crash backtrace, preprocessed source, and associated run script. Stack dump: 0. Program arguments: /opt/homebrew/Cellar/llvm/18.1.8/bin/clang-18 -cc1 -triple arm64-apple-macosx15.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -ffp-contract=on -fno-rounding-math -funwind-tables=1 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -fbuiltin-headers-in-system-modules -fdefine-target-os-macros -target-cpu apple-m1 -target-feature +zcm -target-feature +zcz -target-feature +v8a -target-feature +fp-armv8 -target-feature +fullfp16 -target-feature +neon -target-feature +sve -target-abi darwinpcs -mvscale-max=1 -mvscale-min=1 -debugger-tuning=lldb -fdebug-compilation-dir=/tmp -target-linker-version 1053.12 -fcoverage-compilation-dir=/tmp -resource-dir /opt/homebrew/Cellar/llvm/18.1.8/lib/clang/18 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -internal-isystem /opt/homebrew/opt/llvm/bin/../include/c++/v1 -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/local/include -internal-isystem /opt/homebrew/Cellar/llvm/18.1.8/lib/clang/18/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include -fdeprecated-macro -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/_c/4w43161s72x8kd5w24cp7vlm0000gn/T/test-789251.o -x c++ test.cpp 1. <eof> parser at end of file 2. Code generation 3. Running pass 'Function Pass Manager' on module 'test.cpp'. 4. Running pass 'AArch64 Instruction Selection' on function '@_Z4testu10__SVBool_tu11__SVInt32_tS0_' #0 0x0000000118c7dd60 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libLLVM.dylib+0x4695d60) #1 0x0000000118c7e134 SignalHandler(int) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libLLVM.dylib+0x4696134) #2 0x000000018388c184 (/usr/lib/system/libsystem_platform.dylib+0x180484184) #3 0x0000000116b7a3b8 llvm::AArch64TargetLowering::LowerFormalArguments(llvm::SDValue, unsigned int, bool, llvm::SmallVectorImpl<llvm::ISD::InputArg> const&, llvm::SDLoc const&, llvm::SelectionDAG&, llvm::SmallVectorImpl<llvm::SDValue>&) const (/opt/homebrew/Cellar/llvm/18.1.8/lib/libLLVM.dylib+0x25923b8) #4 0x00000001151f4648 llvm::SelectionDAGISel::LowerArguments(llvm::Function const&) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libLLVM.dylib+0xc0c648) #5 0x000000011527faf8 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libLLVM.dylib+0xc97af8) #6 0x000000011527e578 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libLLVM.dylib+0xc96578) #7 0x0000000114c41054 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libLLVM.dylib+0x659054) #8 0x00000001148fc0e4 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libLLVM.dylib+0x3140e4) #9 0x00000001148f03ec llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libLLVM.dylib+0x3083ec) #10 0x00000001085220cc clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libclang-cpp.dylib+0x15960cc) #11 0x00000001088c7644 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libclang-cpp.dylib+0x193b644) #12 0x00000001071970f8 clang::ParseAST(clang::Sema&, bool, bool) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libclang-cpp.dylib+0x20b0f8) #13 0x0000000109028dd4 clang::FrontendAction::Execute() (/opt/homebrew/Cellar/llvm/18.1.8/lib/libclang-cpp.dylib+0x209cdd4) #14 0x0000000108fabad4 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libclang-cpp.dylib+0x201fad4) #15 0x000000010907bc28 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/homebrew/Cellar/llvm/18.1.8/lib/libclang-cpp.dylib+0x20efc28) #16 0x0000000102526b28 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/homebrew/Cellar/llvm/18.1.8/bin/clang-18+0x100006b28) #17 0x0000000102525218 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) (/opt/homebrew/Cellar/llvm/18.1.8/bin/clang-18+0x100005218) #18 0x0000000102523dac clang_main(int, char**, llvm::ToolContext const&) (/opt/homebrew/Cellar/llvm/18.1.8/bin/clang-18+0x100003dac) #19 0x0000000102530e38 main (/opt/homebrew/Cellar/llvm/18.1.8/bin/clang-18+0x100010e38) #20 0x00000001834d4274 clang: error: unable to execute command: Segmentation fault: 11 clang: error: clang frontend command failed due to signal (use -v to see invocation) Homebrew clang version 18.1.8 Target: arm64-apple-darwin24.1.0 Thread model: posix InstalledDir: /opt/homebrew/opt/llvm/bin ``` This issue might be related to #49751, and manifested under `clang 18.1.8` on macOS 15.1 on an apple M3 based machine.
EugeneZelenko commented 2 months ago

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

SadiinsoSnowfall commented 2 months ago

I cannot reproduce the problem on the x86 version of clang, I will try to get the main branch running locally.

SadiinsoSnowfall commented 2 months ago

Ok I can reproduce the ICE with the mainline version built locally (clang-20git)