Skip to content

error: clang frontend command failed due to signal (use -v to see invocation) #504

@debugzxcv

Description

@debugzxcv
clang++ -v -gcodeview -Xlinker "--pdb=" --static -Xclang -fasync-exceptions test.cc -o test.exe
Stack dump:
0.      Program arguments: G:/devenv/llvm-mingw-ucrt-x86_64/bin/clang-20.exe -cc1 -triple x86_64-w64-windows-gnu -emit-obj -dumpdir test.exe- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cc -static-define -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -mms-bitfields -funwind-tables=2 -fno-sized-deallocation -fno-use-init-array -target-cpu x86-64 -tune-cpu generic -gno-column-info -gcodeview -debugger-tuning=gdb -fdebug-compilation-dir=G:/src/test -object-file-name=C:/Users/ADMINI~1/AppData/Local/Temp/test-befc2f.o -v -fcoverage-compilation-dir=G:/src/test -resource-dir G:/devenv/llvm-mingw-ucrt-x86_64/lib/clang/20 -internal-isystem G:/devenv/llvm-mingw-ucrt-x86_64/x86_64-w64-mingw32/include/c++/v1 -internal-isystem G:/devenv/llvm-mingw-ucrt-x86_64/include/c++/v1 -internal-isystem G:/devenv/llvm-mingw-ucrt-x86_64/lib/clang/20/include -internal-isystem G:/devenv/llvm-mingw-ucrt-x86_64/x86_64-w64-mingw32/include -internal-isystem G:/devenv/llvm-mingw-ucrt-x86_64/x86_64-w64-mingw32/usr/include -internal-isystem G:/devenv/llvm-mingw-ucrt-x86_64/include -fdeprecated-macro -ferror-limit 19 -fmessage-length=120 -fno-use-cxa-atexit -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -exception-model=seh -fcolor-diagnostics -fasync-exceptions -faddrsig -o C:/Users/ADMINI~1/AppData/Local/Temp/test-befc2f.o -x 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 'X86 DAG->DAG Instruction Selection' on function '@_ZN12SE_ExceptionD2Ev'
Exception Code: 0xC0000005
 #0 0x00007ffbabac2e63 llvm::FastISel::selectOperator(llvm::User const*, unsigned int) (G:\devenv\llvm-mingw-ucrt-x86_64\bin\libLLVM-20.dll+0x9d2e63)
 #1 0x00007ffbabac9725 llvm::FastISel::selectInstruction(llvm::Instruction const*) (G:\devenv\llvm-mingw-ucrt-x86_64\bin\libLLVM-20.dll+0x9d9725)
 #2 0x00007ffbabc8afb6 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (G:\devenv\llvm-mingw-ucrt-x86_64\bin\libLLVM-20.dll+0xb9afb6)
 #3 0x00007ffbabc8947c llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (G:\devenv\llvm-mingw-ucrt-x86_64\bin\libLLVM-20.dll+0xb9947c)
 #4 0x00007ffbada50c5d LLVMInitializeX86AsmPrinter (G:\devenv\llvm-mingw-ucrt-x86_64\bin\libLLVM-20.dll+0x2960c5d)
 #5 0x00007ffbabc87b8d llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (G:\devenv\llvm-mingw-ucrt-x86_64\bin\libLLVM-20.dll+0xb97b8d)
 #6 0x00007ffbab6e22fb llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (G:\devenv\llvm-mingw-ucrt-x86_64\bin\libLLVM-20.dll+0x5f22fb)
 #7 0x00007ffbab3d8cb6 llvm::FPPassManager::runOnFunction(llvm::Function&) (G:\devenv\llvm-mingw-ucrt-x86_64\bin\libLLVM-20.dll+0x2e8cb6)
 #8 0x00007ffbab3e01a3 llvm::FPPassManager::runOnModule(llvm::Module&) (G:\devenv\llvm-mingw-ucrt-x86_64\bin\libLLVM-20.dll+0x2f01a3)
 #9 0x00007ffbab3d9b19 llvm::legacy::PassManagerImpl::run(llvm::Module&) (G:\devenv\llvm-mingw-ucrt-x86_64\bin\libLLVM-20.dll+0x2e9b19)
#10 0x00007ffbb7cc6bed clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, 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*) (G:\devenv\llvm-mingw-ucrt-x86_64\bin\libclang-cpp.dll+0x1366bed)
#11 0x00007ffbb80d183c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (G:\devenv\llvm-mingw-ucrt-x86_64\bin\libclang-cpp.dll+0x177183c)
#12 0x00007ffbb6b49f67 clang::ParseAST(clang::Sema&, bool, bool) (G:\devenv\llvm-mingw-ucrt-x86_64\bin\libclang-cpp.dll+0x1e9f67)
#13 0x00007ffbb8b65dcb clang::FrontendAction::Execute() (G:\devenv\llvm-mingw-ucrt-x86_64\bin\libclang-cpp.dll+0x2205dcb)
#14 0x00007ffbb8ae3f04 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (G:\devenv\llvm-mingw-ucrt-x86_64\bin\libclang-cpp.dll+0x2183f04)
#15 0x00007ffbb8be5ae2 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (G:\devenv\llvm-mingw-ucrt-x86_64\bin\libclang-cpp.dll+0x2285ae2)
#16 0x00007ff6a04568b5 (G:\devenv\llvm-mingw-ucrt-x86_64\bin\clang-20.exe+0x68b5)
#17 0x00007ff6a0453962 (G:\devenv\llvm-mingw-ucrt-x86_64\bin\clang-20.exe+0x3962)
#18 0x00007ff6a0452921 (G:\devenv\llvm-mingw-ucrt-x86_64\bin\clang-20.exe+0x2921)
#19 0x00007ff6a046063d (G:\devenv\llvm-mingw-ucrt-x86_64\bin\clang-20.exe+0x1063d)
#20 0x00007ff6a04510fe (G:\devenv\llvm-mingw-ucrt-x86_64\bin\clang-20.exe+0x10fe)
#21 0x00007ff6a04513b6 (G:\devenv\llvm-mingw-ucrt-x86_64\bin\clang-20.exe+0x13b6)
#22 0x00007ffc5f337374 (C:\Windows\System32\KERNEL32.DLL+0x17374)
#23 0x00007ffc5f47cc91 (C:\Windows\SYSTEM32\ntdll.dll+0x4cc91)
clang-20: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 20.1.7 (https://github.com/llvm/llvm-project.git 6146a88f60492b520a36f8f8f3231e15f3cc6082)
Target: x86_64-w64-windows-gnu
Thread model: posix

take from: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/set-se-translator?view=msvc-170#example-catch-se_exception-error

#include <windows.h>
#include <eh.h>
#include <stdio.h>
#include <exception>

int thrower_func( int i ) {
   int y = 0;
   int *p = &y;
   *p = i / *p;
   return 0;
}

class SE_Exception : public std::exception
{
private:
    const unsigned int nSE;
public:
    SE_Exception() noexcept : SE_Exception{ 0 } {}
    SE_Exception( unsigned int n ) noexcept : nSE{ n } {}
    unsigned int getSeNumber() const noexcept { return nSE; }
};

class Scoped_SE_Translator
{
private:
    const _se_translator_function old_SE_translator;
public:
    Scoped_SE_Translator( _se_translator_function new_SE_translator ) noexcept
        : old_SE_translator{ _set_se_translator( new_SE_translator ) } {}
    ~Scoped_SE_Translator() noexcept { _set_se_translator( old_SE_translator ); }
};

#pragma unmanaged
void my_trans_func( unsigned int u, PEXCEPTION_POINTERS )
{
    throw SE_Exception( u );
}

void DoTest()
{
    try
    {
        thrower_func( 10 );
    }
    catch( const SE_Exception& e )
    {
        printf( "Caught SE_Exception, error %8.8x\n", e.getSeNumber() );
    }
    catch(...)
    {
        printf( "Caught unexpected SEH exception.\n" );
    }
}
#pragma managed

int main() {
    Scoped_SE_Translator scoped_se_translator{ my_trans_func };

    DoTest();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions