[llvm-commits] [PATCH] Add -fcatch-undefined-behavior runtime library

Kostya Serebryany kcc at google.com
Thu Oct 4 03:36:32 PDT 2012


asan/tsan/msan generally avoid #including system headers, especially in .h
files.
Once you start porting the code to non-linux, you'll know why.
compiler-rt/lib/sanitizer_common contains lots of useful stuff that allows
you to avoid using system headers.
WDYT?

--kcc




On Thu, Oct 4, 2012 at 12:36 PM, Richard Smith <richard at metafoo.co.uk>wrote:

> Hi,
>
> The attached patches to compiler-rt and Clang add a new runtime library
> which -fcatch-undefined-behavior will call into when it detects undefined
> behavior. Output looks like this (complete with Clang-style highlighting if
> it's writing to a terminal):
>
> $ echo '
> typedef int X;
> int main(int argc, char**) {
>   return *(X*)argc;
> }' | ./bin/clang -x c++ - -fcatch-undefined-behavior
> $ ./a.out
> *<stdin>:4:10: fatal error: load of misaligned address 0x1 for type 'X'
> (aka 'int'), which requires 4 byte alignment*
> zsh: illegal hardware instruction (core dumped)  ./a.out
> $
>
> I've left -ftrapv's behavior alone, for now at least.
>
> Review appreciated!
>
> Thanks,
> Richard
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121004/9f966c3c/attachment.html>


More information about the llvm-commits mailing list