Fixing LLVM_BUILTIN_TRAP on Windows

Aaron Ballman aaron at aaronballman.com
Mon Feb 9 09:02:06 PST 2015


The implementation for LLVM_BUILTIN_TRAP on Windows leaves quite a bit
to be desired. Instead of relying on writing to an invalid volatile
pointer, which is hoped to result in raising an exception we can catch
with the vectored exception handler, simply raise an exception
manually.

To prevent having to #include a Win32 header from Compiler.h, this
patch forward declares the RaiseException call.

The only functional difference between the current implementation and
the new one is that RaiseException will appear on the stack traces now
when invoking this macro. Eg)

e:\llvm\2013>clang -fsyntax-only "E:\Aaron Ballman\Desktop\test.cpp"
0x755EC42D (0xDEADD0D0 0x00000001 0x00000000 0x00000000), RaiseException() + 0x5
8 bytes(s)
0x03D9F222 (0x00692018 0x00000000 0x0685E3C4 0x0685E3A0), `anonymous namespace':
:PragmaDebugHandler::HandlePragma() + 0xC2 bytes(s), e:\llvm\llvm\tools\clang\li
b\lex\pragma.cpp, line 870 + 0x13 byte(s)
0x03D997DC (0x00692018 0x00000000 0x0685E3C4 0x0685E494), clang::PragmaNamespace
::HandlePragma() + 0xBC bytes(s), e:\llvm\llvm\tools\clang\lib\lex\pragma.cpp, l
ine 95 + 0x1B byte(s)
...

instead of:

e:\llvm\2013>clang -fsyntax-only "E:\Aaron Ballman\Desktop\test.cpp"
0x03CDF1CF (0x00302018 0x00000000 0x0679E5F8 0x0679E5D4), `anonymous namespace':
:PragmaDebugHandler::HandlePragma() + 0xAF bytes(s), e:\llvm\llvm\tools\clang\li
b\lex\pragma.cpp, line 870
0x03CD979C (0x00302018 0x00000000 0x0679E5F8 0x0679E6C8), clang::PragmaNamespace
::HandlePragma() + 0xBC bytes(s), e:\llvm\llvm\tools\clang\lib\lex\pragma.cpp, l
ine 95 + 0x1B byte(s)
...

~Aaron
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Compiler.h.patch
Type: application/octet-stream
Size: 794 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150209/87807526/attachment.obj>


More information about the llvm-commits mailing list