<div dir="ltr">Hi David, <div><br></div><div>Looks like the ubsan bot is unhappy: </div><div><a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/33102/steps/check-llvm%20ubsan/logs/stdio">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/33102/steps/check-llvm%20ubsan/logs/stdio</a><br></div><div><br></div><div><pre style="font-family:"Courier New",courier,monotype,monospace;color:rgb(0,0,0);font-size:medium"><span class="gmail-stdout">llvm/include/llvm/Support/LEB128.h:179:36: runtime error: left shift of 127 by 63 places cannot be represented in type 'int64_t' (aka 'long')
    #0 0x18803fc in llvm::decodeSLEB128(unsigned char const*, unsigned int*, unsigned char const*, char const**) /b/sanitizer-x86_64-linux-fast/build/llvm/include/llvm/Support/LEB128.h:179:36
    #1 0x1a4cb23 in llvm::DataExtractor::getSLEB128(unsigned int*) const /b/sanitizer-x86_64-linux-fast/build/llvm/lib/Support/DataExtractor.cpp:167:20
    #2 0x18ba814 in llvm::DWARFFormValue::skipValue(llvm::dwarf::Form, llvm::DataExtractor, unsigned int*, llvm::dwarf::FormParams) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp:180:21
    #3 0x18fb1ae in llvm::DWARFDebugInfoEntry::extractFast(llvm::DWARFUnit const&, unsigned int*, llvm::DWARFDataExtractor const&, unsigned int, unsigned int) /b/sanitizer-x86_64-linux-fast/build/llvm/lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp:60:17</span></pre></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 24, 2019 at 4:45 PM David Blaikie 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: dblaikie<br>
Date: Mon Jun 24 16:45:18 2019<br>
New Revision: 364253<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=364253&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=364253&view=rev</a><br>
Log:<br>
DataExtractor: use decodeSLEB128 to implement getSLEB128<br>
<br>
Should've been NFC, but turns out DataExtractor had better test coverage<br>
for decoding SLEB128 than the decodeSLEB128 did - revealing a couple of<br>
bugs (one in the error handling, another in sign extension). So fixed<br>
those to get the DataExtractor tests passing again.<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/Support/LEB128.h<br>
    llvm/trunk/lib/Support/DataExtractor.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/Support/LEB128.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/LEB128.h?rev=364253&r1=364252&r2=364253&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/LEB128.h?rev=364253&r1=364252&r2=364253&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Support/LEB128.h (original)<br>
+++ llvm/trunk/include/llvm/Support/LEB128.h Mon Jun 24 16:45:18 2019<br>
@@ -165,6 +165,8 @@ inline int64_t decodeSLEB128(const uint8<br>
   int64_t Value = 0;<br>
   unsigned Shift = 0;<br>
   uint8_t Byte;<br>
+  if (error)<br>
+    *error = nullptr;<br>
   do {<br>
     if (end && p == end) {<br>
       if (error)<br>
@@ -177,8 +179,8 @@ inline int64_t decodeSLEB128(const uint8<br>
     Value |= (int64_t(Byte & 0x7f) << Shift);<br>
     Shift += 7;<br>
   } while (Byte >= 128);<br>
-  // Sign extend negative numbers.<br>
-  if (Byte & 0x40)<br>
+  // Sign extend negative numbers if needed.<br>
+  if (Shift < 64 && (Byte & 0x40))<br>
     Value |= (-1ULL) << Shift;<br>
   if (n)<br>
     *n = (unsigned)(p - orig_p);<br>
<br>
Modified: llvm/trunk/lib/Support/DataExtractor.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/DataExtractor.cpp?rev=364253&r1=364252&r2=364253&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/DataExtractor.cpp?rev=364253&r1=364252&r2=364253&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/DataExtractor.cpp (original)<br>
+++ llvm/trunk/lib/Support/DataExtractor.cpp Mon Jun 24 16:45:18 2019<br>
@@ -160,26 +160,15 @@ uint64_t DataExtractor::getULEB128(uint3<br>
 }<br>
<br>
 int64_t DataExtractor::getSLEB128(uint32_t *offset_ptr) const {<br>
-  int64_t result = 0;<br>
-  if (Data.empty())<br>
-    return 0;<br>
-<br>
-  unsigned shift = 0;<br>
-  uint32_t offset = *offset_ptr;<br>
-  uint8_t byte = 0;<br>
+  assert(*offset_ptr <= Data.size());<br>
<br>
-  while (isValidOffset(offset)) {<br>
-    byte = Data[offset++];<br>
-    result |= uint64_t(byte & 0x7f) << shift;<br>
-    shift += 7;<br>
-    if ((byte & 0x80) == 0) {<br>
-      // Sign bit of byte is 2nd high order bit (0x40)<br>
-      if (shift < 64 && (byte & 0x40))<br>
-        result |= -(1ULL << shift);<br>
-<br>
-      *offset_ptr = offset;<br>
-      return result;<br>
-    }<br>
-  }<br>
-  return 0;<br>
+  const char *error;<br>
+  unsigned bytes_read;<br>
+  int64_t result = decodeSLEB128(<br>
+      reinterpret_cast<const uint8_t *>(Data.data() + *offset_ptr), &bytes_read,<br>
+      reinterpret_cast<const uint8_t *>(Data.data() + Data.size()), &error);<br>
+  if (error)<br>
+    return 0;<br>
+  *offset_ptr += bytes_read;<br>
+  return result;<br>
 }<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>