<div dir="ltr">I realize it's UB, so not exactly testable - but a unit test that exercises this (& that, say, asan would have failed on without the fix) would be good.</div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jan 19, 2017 at 8:34 PM Matthias Braun via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: matze<br class="gmail_msg">
Date: Thu Jan 19 22:23:08 2017<br class="gmail_msg">
New Revision: 292575<br class="gmail_msg">
<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=292575&view=rev" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=292575&view=rev</a><br class="gmail_msg">
Log:<br class="gmail_msg">
BitVector: Fix undefined behaviour<br class="gmail_msg">
<br class="gmail_msg">
Calling reset() on an empty BitVector would call memset with a nullptr<br class="gmail_msg">
argument which is undefined behaviour.<br class="gmail_msg">
<br class="gmail_msg">
This should fix the sanitizer bot.<br class="gmail_msg">
<br class="gmail_msg">
Modified:<br class="gmail_msg">
    llvm/trunk/include/llvm/ADT/BitVector.h<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/include/llvm/ADT/BitVector.h<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/BitVector.h?rev=292575&r1=292574&r2=292575&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/BitVector.h?rev=292575&r1=292574&r2=292575&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/include/llvm/ADT/BitVector.h (original)<br class="gmail_msg">
+++ llvm/trunk/include/llvm/ADT/BitVector.h Thu Jan 19 22:23:08 2017<br class="gmail_msg">
@@ -539,7 +539,8 @@ private:<br class="gmail_msg">
   }<br class="gmail_msg">
<br class="gmail_msg">
   void init_words(BitWord *B, unsigned NumWords, bool t) {<br class="gmail_msg">
-    memset(B, 0 - (int)t, NumWords*sizeof(BitWord));<br class="gmail_msg">
+    if (NumWords > 0)<br class="gmail_msg">
+      memset(B, 0 - (int)t, NumWords*sizeof(BitWord));<br class="gmail_msg">
   }<br class="gmail_msg">
<br class="gmail_msg">
   template<bool AddBits, bool InvertMask><br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
llvm-commits mailing list<br class="gmail_msg">
<a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="gmail_msg">
</blockquote></div>