Skip to content

AArch64: Clang SVE checks incomplete, resulting in invalid code being accepted and hitting assertion failures in LLVM #94766

@hvdijk

Description

@hvdijk

Please consider the following invalid program that gets rejected as it should:

__SVInt8_t foo();
void f() { auto v = foo(); } // SVE vector type '__SVInt8_t' cannot be used in a target without sve

However, this is rejected because of the definition of v, not because of the call to foo(), so no clang error is generated for

__SVInt8_t foo();
void f() { foo(); }

But this does not and cannot work, and crashes during codegen, no special options needed:

fatal error: error in backend: Invalid size request on a scalable vector.
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: bin/clang -c test.cc
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module 'test.cc'.
4.	Running pass 'AArch64 Instruction Selection' on function '@_Z1fv'
 #0 0x0000ac95542f5eb8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (bin/clang+0x3d45eb8)
 #1 0x0000ac95542f35e0 llvm::sys::RunSignalHandlers() (bin/clang+0x3d435e0)
 #2 0x0000ac9554245d60 llvm::CrashRecoveryContext::HandleExit(int) (bin/clang+0x3c95d60)
 #3 0x0000ac95542edd34 llvm::sys::Process::Exit(int, bool) (bin/clang+0x3d3dd34)
 #4 0x0000ac95517a72f0 LLVMErrorHandler(void*, char const*, bool) cc1_main.cpp:0:0
 #5 0x0000ac95542527dc llvm::report_fatal_error(llvm::Twine const&, bool) (bin/clang+0x3ca27dc)
 #6 0x0000ac9554252968 (bin/clang+0x3ca2968)
 #7 0x0000ac955429ccdc (bin/clang+0x3ceccdc)
 #8 0x0000ac955429cd04 llvm::TypeSize::operator unsigned long() const (bin/clang+0x3cecd04)
 #9 0x0000ac955527fa40 llvm::TargetLowering::LowerCallTo(llvm::TargetLowering::CallLoweringInfo&) const (bin/clang+0x4ccfa40)
#10 0x0000ac955528aa44 llvm::SelectionDAGBuilder::lowerInvokable(llvm::TargetLowering::CallLoweringInfo&, llvm::BasicBlock const*) (bin/clang+0x4cdaa44)
#11 0x0000ac95552a1384 llvm::SelectionDAGBuilder::LowerCallTo(llvm::CallBase const&, llvm::SDValue, bool, bool, llvm::BasicBlock const*, llvm::TargetLowering::PtrAuthInfo const*) (bin/clang+0x4cf1384)
#12 0x0000ac95552c6808 llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) (bin/clang+0x4d16808)
#13 0x0000ac955534a6e0 llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true>, false, true>, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true>, false, true>, bool&) (bin/clang+0x4d9a6e0)
#14 0x0000ac955534b6ac llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (bin/clang+0x4d9b6ac)
#15 0x0000ac955534cb40 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (bin/clang+0x4d9cb40)
#16 0x0000ac955533bb0c llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (bin/clang+0x4d8bb0c)
#17 0x0000ac955370ff48 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#18 0x0000ac9553cbb304 llvm::FPPassManager::runOnFunction(llvm::Function&) (bin/clang+0x370b304)
#19 0x0000ac9553cbb6dc llvm::FPPassManager::runOnModule(llvm::Module&) (bin/clang+0x370b6dc)
#20 0x0000ac9553cbc270 llvm::legacy::PassManagerImpl::run(llvm::Module&) (bin/clang+0x370c270)
#21 0x0000ac9554551850 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::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (bin/clang+0x3fa1850)
#22 0x0000ac9554af4f7c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (bin/clang+0x4544f7c)
#23 0x0000ac95564a2968 clang::ParseAST(clang::Sema&, bool, bool) (bin/clang+0x5ef2968)
#24 0x0000ac9554d3c7e8 clang::FrontendAction::Execute() (bin/clang+0x478c7e8)
#25 0x0000ac9554cd86ec clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (bin/clang+0x47286ec)
#26 0x0000ac9554dfe2f8 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (bin/clang+0x484e2f8)
#27 0x0000ac95517a91ac cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (bin/clang+0x11f91ac)
#28 0x0000ac95517a2f24 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#29 0x0000ac9554b32fd0 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#30 0x0000ac9554245c80 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (bin/clang+0x3c95c80)
#31 0x0000ac9554b34088 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#32 0x0000ac9554aff2e0 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (bin/clang+0x454f2e0)
#33 0x0000ac9554affbb8 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (bin/clang+0x454fbb8)
#34 0x0000ac9554b0bd88 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (bin/clang+0x455bd88)
#35 0x0000ac95517a6948 clang_main(int, char**, llvm::ToolContext const&) (bin/clang+0x11f6948)
#36 0x0000ac95516be330 main (bin/clang+0x110e330)
#37 0x0000e14e328284c4 (/lib/aarch64-linux-gnu/libc.so.6+0x284c4)
#38 0x0000e14e32828598 __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x28598)
#39 0x0000ac95517a2530 _start (bin/clang+0x11f2530)
clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 19.0.0git (https://github.com/llvm/llvm-project 3fefb3c598db995433093ed158c08368809b3f78)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/harald/llvm-project/main/build/aarch64-linux/bin
Build config: +assertions
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: /tmp/test-7b926c.cpp
clang: note: diagnostic msg: /tmp/test-7b926c.sh
clang: note: diagnostic msg:

********************
$ cat /tmp/test-7b926c.cpp
# 1 "<built-in>"
# 1 "test.cc"
__SVInt8_t foo();
void f() { foo(); }

$ cat /tmp/test-7b926c.sh
# Crash reproducer for clang version 19.0.0git (https://github.com/llvm/llvm-project 3fefb3c598db995433093ed158c08368809b3f78)
# Driver args: "-c" "test.cc"
# Original command:  "/home/harald/llvm-project/main/build/aarch64-linux/bin/clang-19" "-cc1" "-triple" "aarch64-unknown-linux-gnu" "-emit-obj" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "test.cc" "-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" "+v8a" "-target-feature" "+fp-armv8" "-target-feature" "+neon" "-target-abi" "aapcs" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/home/harald/llvm-project/main/build/aarch64-linux" "-fcoverage-compilation-dir=/home/harald/llvm-project/main/build/aarch64-linux" "-resource-dir" "/home/harald/llvm-project/main/build/aarch64-linux/lib/clang/19" "-internal-isystem" "/usr/lib/gcc/aarch64-linux-gnu/14/../../../../include/c++/14" "-internal-isystem" "/usr/lib/gcc/aarch64-linux-gnu/14/../../../../include/aarch64-linux-gnu/c++/14" "-internal-isystem" "/usr/lib/gcc/aarch64-linux-gnu/14/../../../../include/c++/14/backward" "-internal-isystem" "/home/harald/llvm-project/main/build/aarch64-linux/lib/clang/19/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/aarch64-linux-gnu/14/../../../../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" "test.o" "-x" "c++" "test.cc"
 "/home/harald/llvm-project/main/build/aarch64-linux/bin/clang-19" "-cc1" "-triple" "aarch64-unknown-linux-gnu" "-emit-obj" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "test.cc" "-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" "+v8a" "-target-feature" "+fp-armv8" "-target-feature" "+neon" "-target-abi" "aapcs" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/home/harald/llvm-project/main/build/aarch64-linux" "-fcoverage-compilation-dir=/home/harald/llvm-project/main/build/aarch64-linux" "-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" "-x" "c++" "test-7b926c.cpp"

Metadata

Metadata

Assignees

No one assigned

    Labels

    SVEARM Scalable Vector Extensionsclang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions