llvm / llvm/llvm-project

clang trunk: assertion failed in cast<PointerType> during codegen of UINTR interrupt handler with malformed/duplicate parameter list

Open
#173,899 2 comments 0 reactions 0 assignees View on GitHub
clang:codegen crash generated by fuzzer
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## Compiler Explorer: https://godbolt.org/z/PcTP5179v

- clang start crashing on `Trunk`
- generated by fuzzer

## Console
```console
clang: /root/llvm-project/llvm/include/llvm/Support/Casting.h:560: decltype(auto) llvm::cast(const From&) [with To = clang::PointerType; From = clang::QualType]: Assertion `isa(Val) && "cast() 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 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics
1. parser at end of file
2. :4:1: LLVM IR generation of declaration 'UINTR_handler'
3. :4:1: Generating code for declaration 'UINTR_handler'
#0 0x0000000004301458 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4301458)
#1 0x00000000042fe884 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x42fe884)
#2 0x0000000004243628 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007cb78fa42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007cb78fa969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007cb78fa42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007cb78fa287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x00007cb78fa2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x00007cb78fa39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x0000000004ac98b5 addX86InterruptAttrs(clang::FunctionDecl const*, llvm::GlobalValue*, clang::CodeGen::CodeGenModule&) X86.cpp:0:0
#10 0x00000000048cca1b clang::CodeGen::CodeGenModule::setNonAliasAttributes(clang::GlobalDecl, llvm::GlobalObject*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48cca1b)
#11 0x00000000048fb16d clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48fb16d)
#12 0x00000000048f5df4 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48f5df4)
#13 0x00000000048f65d3 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48f65d3)
#14 0x0000000004901b63 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#15 0x0000000004c65379 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#16 0x0000000004c55ea4 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c55ea4)
#17 0x0000000006a1e374 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6a1e374)
#18 0x0000000004c62788 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c62788)
#19 0x0000000004f58e05 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f58e05)
#20 0x0000000004ed909e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4ed909e)
#21 0x000000000505318d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x505318d)
#22 0x0000000000de63ec cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xde63ec)
#23 0x0000000000ddce3a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#24 0x0000000000ddcfbd int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#25 0x0000000004cd4e59 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#26 0x0000000004243ac4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4243ac4)
#27 0x0000000004cd546f clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#28 0x0000000004c95f52 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c95f52)
#29 0x0000000004c96efe clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c96efe)
#30 0x0000000004c9e355 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c9e355)
#31 0x0000000000de27e1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xde27e1)
#32 0x0000000000c8d114 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc8d114)
#33 0x00007cb78fa29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#34 0x00007cb78fa29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#35 0x0000000000ddc8d5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xddc8d5)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```

## Code
```c
#include
typedef unsigned int uword_t __attribute__ ( ( mode ( __word__ ) ) ) ;
void __attribute__ ( ( target ( "general-regs-only" ) , interrupt ) )
UINTR_handler ( struct __uintr_frame
UINTR_handler ( struct __uintr_frame * p , uword_t uirrv ) , uword_t uirrv ) { }
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided C source with the Compiler Explorer link or the clang command, then inspect addX86InterruptAttrs in X86.cpp, where the stack trace shows the assertion occurs during UINTR handler code generation. Done means the malformed or duplicate parameter-list input no longer aborts clang during LLVM IR generation.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.