>> +void __ubsan::__ubsan_handle_divrem_overflow<div>For consistency with asan/tsan you may want to move public functions out of __ubsan namespace (just have them __ubsan_foo). </div><div>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)</div>
<div><br></div><div>--kcc </div><div><br><br><div class="gmail_quote">On Thu, Oct 4, 2012 at 2:36 PM, Kostya Serebryany <span dir="ltr"><<a href="mailto:kcc@google.com" target="_blank">kcc@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><br></div><div>asan/tsan/msan generally avoid #including system headers, especially in .h files. </div><div>Once you start porting the code to non-linux, you'll know why. </div>
<div>compiler-rt/lib/sanitizer_common contains lots of useful stuff that allows you to avoid using system headers. </div>
<div>WDYT? </div><div><br></div><div>--kcc </div><div class="HOEnZb"><div class="h5"><div><br></div><div><br></div><br><br><div class="gmail_quote">On Thu, Oct 4, 2012 at 12:36 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<div><br></div><div>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):</div>


<div><br></div><div><div><font face="courier new, monospace">$ echo '</font></div><div><font face="courier new, monospace">typedef int X;</font></div><div><font face="courier new, monospace">int main(int argc, char**) {</font></div>


<div><font face="courier new, monospace">  return *(X*)argc;</font></div><div><font face="courier new, monospace">}' | ./bin/clang -x c++ - -fcatch-undefined-behavior</font></div><div><font face="courier new, monospace">$ ./a.out </font></div>


<div><font face="courier new, monospace"><b><stdin>:4:10: <font color="#cc0000">fatal error:</font> load of misaligned address 0x1 for type 'X' (aka 'int'), which requires 4 byte alignment</b></font></div>


<div><font face="courier new, monospace">zsh: illegal hardware instruction (core dumped)  ./a.out</font></div></div><div><font face="courier new, monospace">$</font></div><div><br></div><div>I've left -ftrapv's behavior alone, for now at least.</div>


<div><br></div><div>Review appreciated!</div><div><br></div><div>Thanks,</div><div>Richard</div>
</blockquote></div><br>
</div></div></blockquote></div><br></div>