[lldb] Fix UBSan regression in GetSLEB128
authorJan Kratochvil <jan.kratochvil@redhat.com>
Fri, 5 Jun 2020 09:59:26 +0000 (11:59 +0200)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Fri, 5 Jun 2020 10:00:44 +0000 (12:00 +0200)
It regressed recently by my: https://reviews.llvm.org/D81119

lldb/source/Utility/DataExtractor.cpp

index 5f4abb8..023190b 100644 (file)
@@ -930,8 +930,10 @@ int64_t DataExtractor::GetSLEB128(offset_t *offset_ptr) const {
     }
 
     // Sign bit of byte is 2nd high order bit (0x40)
-    if (shift < size && (byte & 0x40))
-      result |= -(static_cast<int64_t>(1) << shift);
+    if (shift < size && (byte & 0x40)) {
+      // -(static_cast<int64_t>(1) << 63) errors on the negation with UBSan.
+      result |= -(static_cast<uint64_t>(1) << shift);
+    }
 
     *offset_ptr += bytecount;
     return result;