[Clang] Clang hard crashes during codegen when compiling `dllexport` structure with virtual destructor using `-Og` for MSVC 32 bit.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Version: Clang 23.1.0.
To reproduce, compile
```c++
struct __declspec(dllexport) Test
{
virtual ~Test();
};
```
as `Test.cpp` with the command line flags `-m32 -Og -c Test.cpp` (on Windows) or `--target=i686-pc-windows-msvc -Og -c Test.cpp` (on any other target).
[Link toGodbolt.org.](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,selection:(endColumn:3,endLineNumber:4,positionColumn:3,positionLineNumber:4,selectionStartColumn:3,selectionStartLineNumber:4,startColumn:3,startLineNumber:4),source:'struct+__declspec(dllexport)+Test%0A%7B%0A%09virtual+~Test()%3B%0A%7D%3B'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:33.333333333333336,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:clang2310,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,libs:!(),options:'--target%3Di686-pc-windows-msvc+-Og',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+x86-64+clang+23.1.0+(Editor+%231)',t:'0')),k:33.333333333333336,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'x86-64+clang+23.1.0',editorid:1,fontScale:14,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+x86-64+clang+23.1.0+(Compiler+%231)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4)
Full error message:
```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-23.1.0/bin/clang++ -g -o /application/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-15.2.0 -fcolor-diagnostics -fno-crash-diagnostics --target=i686-pc-windows-msvc -Og
1. parser at end of file
2. Per-file LLVM IR generation
3. :3:10: Generating code for declaration 'Test::~Test'
#0 0x0000000003c063a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x3c063a8)
#1 0x0000000003c03cec llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x3c03cec)
#2 0x0000000003b479d8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x000078c6eb445330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x000000000453c36b clang::CodeGen::CodeGenFunction::EmitParmDecl(clang::VarDecl const&, clang::CodeGen::CodeGenFunction::ParamValue, unsigned int) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x453c36b)
#5 0x00000000044f5e55 clang::CodeGen::CodeGenFunction::EmitFunctionProlog(clang::CodeGen::CGFunctionInfo const&, llvm::Function*, clang::CodeGen::FunctionArgList const&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x44f5e55)
#6 0x0000000004223222 clang::CodeGen::CodeGenFunction::StartFunction(clang::GlobalDecl, clang::QualType, llvm::Function*, clang::CodeGen::CGFunctionInfo const&, clang::CodeGen::FunctionArgList const&, clang::SourceLocation, clang::SourceLocation) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x4223222)
#7 0x0000000004228ecd clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x4228ecd)
#8 0x00000000044ccec4 clang::CodeGen::CodeGenModule::codegenCXXStructor(clang::GlobalDecl) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x44ccec4)
#9 0x000000000430e128 (anonymous namespace)::MicrosoftCXXABI::emitCXXStructor(clang::GlobalDecl) MicrosoftCXXABI.cpp:0:0
#10 0x0000000004281d26 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x4281d26)
#11 0x000000000428fe5f clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x428fe5f)
#12 0x0000000004293113 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x4293113)
#13 0x00000000045dedde (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#14 0x00000000045dc74d clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x45dc74d)
#15 0x00000000061de94c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x61de94c)
#16 0x00000000045dd405 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x45dd405)
#17 0x00000000049113e1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x49113e1)
#18 0x00000000048a2965 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x48a2965)
#19 0x00000000049e612b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x49e612b)
#20 0x0000000000debce8 cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0xdebce8)
#21 0x0000000000de3b7b ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#22 0x0000000000de3c1d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#23 0x0000000004658a19 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#24 0x0000000003b47d93 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x3b47d93)
#25 0x000000000465945d clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#26 0x00000000046144a2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x46144a2)
#27 0x0000000004618755 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x4618755)
#28 0x00000000046235dc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x46235dc)
#29 0x0000000000de86a1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0xde86a1)
#30 0x0000000000d0d14a main (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0xd0d14a)
#31 0x000078c6eb42a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#32 0x000078c6eb42a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#33 0x0000000000de3625 _start (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0xde3625)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Program terminated with signal SIGSEGV (11)
Compiler returned: 139
```
Contributor guide
Research direction
Reproduce the crash with the provided C++ source and target flags, then inspect the code-generation stack around CodeGenFunction::EmitParmDecl, EmitFunctionProlog, and MicrosoftCXXABI::emitCXXStructor. Use the reported dllexport virtual-destructor case as the regression scenario and verify that compilation no longer hard-crashes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100