llvm / llvm-project

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

Clang-19 crashed: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed. #96018

Open iamanonymouscs opened 1 month ago

iamanonymouscs commented 1 month ago

Clang-19 with the attribute interrupt enabled.

Compiler explorer(assertion trunck): https://godbolt.org/z/5xPr7ob1M

$cat mutant.c
__attribute__((interrupt)) void a(void()) {}

$clang-19 mutant.c
<source>:1:40: warning: omitting the parameter name in a function definition is a C23 extension [-Wc23-extensions]
    1 | __attribute__((interrupt)) void a(void()) {}
      |                                        ^
clang: /root/llvm-project/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From&) [with To = clang::PointerType; From = clang::QualType]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
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 -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1.  <eof> parser at end of file
2.  <source>:1:33: LLVM IR generation of declaration 'a'
3.  <source>:1:33: Generating code for declaration 'a'
 #0 0x0000000003a1a338 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3a1a338)
 #1 0x0000000003a1801c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3a1801c)
 #2 0x00000000039600f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007b7291a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007b7291a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007b7291a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007b7291a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007b7291a2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007b7291a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000000003f1f3c6 addX86InterruptAttrs(clang::FunctionDecl const*, llvm::GlobalValue*, clang::CodeGen::CodeGenModule&) X86.cpp:0:0
#10 0x0000000003e1c483 clang::CodeGen::CodeGenModule::setNonAliasAttributes(clang::GlobalDecl, llvm::GlobalObject*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e1c483)
#11 0x0000000003e44beb clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e44beb)
#12 0x0000000003e3f725 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e3f725)
#13 0x0000000003e3fd1b clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e3fd1b)
#14 0x0000000003e49fb3 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#15 0x00000000042feee6 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#16 0x00000000042ef468 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x42ef468)
#17 0x0000000006378464 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6378464)
#18 0x00000000042fca68 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x42fca68)
#19 0x00000000045812e9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x45812e9)
#20 0x000000000450822e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x450822e)
#21 0x000000000466896e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x466896e)
#22 0x0000000000c6d15c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc6d15c)
#23 0x0000000000c664ba ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#24 0x000000000433fd49 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
#25 0x00000000039605a4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x39605a4)
#26 0x000000000434033f 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
#27 0x00000000043061e5 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x43061e5)
#28 0x0000000004306c4d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4306c4d)
#29 0x000000000430e945 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x430e945)
#30 0x0000000000c6a665 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc6a665)
#31 0x0000000000b44244 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xb44244)
#32 0x00007b7291a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#33 0x00007b7291a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#34 0x0000000000c65f6e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc65f6e)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
llvmbot commented 1 month ago

@llvm/issue-subscribers-backend-x86

Author: Anonymous (iamanonymouscs)

Clang-19 with the attribute `interrupt` enabled. Compiler explorer(assertion trunck): https://godbolt.org/z/5xPr7ob1M ``` $cat mutant.c __attribute__((interrupt)) void a(void()) {} $clang-19 mutant.c <source>:1:40: warning: omitting the parameter name in a function definition is a C23 extension [-Wc23-extensions] 1 | __attribute__((interrupt)) void a(void()) {} | ^ clang: /root/llvm-project/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From&) [with To = clang::PointerType; From = clang::QualType]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed. 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 -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source> 1. <eof> parser at end of file 2. <source>:1:33: LLVM IR generation of declaration 'a' 3. <source>:1:33: Generating code for declaration 'a' #0 0x0000000003a1a338 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3a1a338) #1 0x0000000003a1801c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3a1801c) #2 0x00000000039600f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0 #3 0x00007b7291a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #4 0x00007b7291a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #5 0x00007b7291a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476) #6 0x00007b7291a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #7 0x00007b7291a2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b) #8 0x00007b7291a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) #9 0x0000000003f1f3c6 addX86InterruptAttrs(clang::FunctionDecl const*, llvm::GlobalValue*, clang::CodeGen::CodeGenModule&) X86.cpp:0:0 #10 0x0000000003e1c483 clang::CodeGen::CodeGenModule::setNonAliasAttributes(clang::GlobalDecl, llvm::GlobalObject*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e1c483) #11 0x0000000003e44beb clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e44beb) #12 0x0000000003e3f725 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e3f725) #13 0x0000000003e3fd1b clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e3fd1b) #14 0x0000000003e49fb3 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0 #15 0x00000000042feee6 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0 #16 0x00000000042ef468 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x42ef468) #17 0x0000000006378464 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6378464) #18 0x00000000042fca68 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x42fca68) #19 0x00000000045812e9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x45812e9) #20 0x000000000450822e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x450822e) #21 0x000000000466896e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x466896e) #22 0x0000000000c6d15c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc6d15c) #23 0x0000000000c664ba ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0 #24 0x000000000433fd49 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 #25 0x00000000039605a4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x39605a4) #26 0x000000000434033f 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 #27 0x00000000043061e5 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x43061e5) #28 0x0000000004306c4d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4306c4d) #29 0x000000000430e945 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x430e945) #30 0x0000000000c6a665 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc6a665) #31 0x0000000000b44244 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xb44244) #32 0x00007b7291a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #33 0x00007b7291a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #34 0x0000000000c65f6e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc65f6e) clang: error: clang frontend command failed with exit code 134 (use -v to see invocation) Compiler returned: 134 ```
shafik commented 1 month ago

Looks like it works with a void*: https://godbolt.org/z/rooavjjqK

It looks like it should be valid.