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

Kostya Serebryany kcc at google.com
Thu Oct 4 03:58:21 PDT 2012


>> +void __ubsan::__ubsan_handle_divrem_overflow
For consistency with asan/tsan you may want to move public functions out of
__ubsan namespace (just have them __ubsan_foo).
The "__" guaranties that no legal program will have the same symbol, while
the simple extern "C" name may slightly simplify debugging (e.g. setting a
break point, etc)

--kcc


On Thu, Oct 4, 2012 at 2:36 PM, Kostya Serebryany <kcc at google.com> wrote:

>
> 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/01a6fcc7/attachment.html>


More information about the llvm-commits mailing list