summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/DataExtractor.cpp
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2019-06-24 23:45:18 +0000
committerDavid Blaikie <dblaikie@gmail.com>2019-06-24 23:45:18 +0000
commitf895e1bded031fb503bd12ad25d7139d6a6ee6c0 (patch)
treeaad2b82a2470f8b9c44ee3d45edfedf469f51702 /llvm/lib/Support/DataExtractor.cpp
parent323b89f101bc3cbee2f064ce4ca1e50a54d081ba (diff)
downloadbcm5719-llvm-f895e1bded031fb503bd12ad25d7139d6a6ee6c0.tar.gz
bcm5719-llvm-f895e1bded031fb503bd12ad25d7139d6a6ee6c0.zip
DataExtractor: use decodeSLEB128 to implement getSLEB128
Should've been NFC, but turns out DataExtractor had better test coverage for decoding SLEB128 than the decodeSLEB128 did - revealing a couple of bugs (one in the error handling, another in sign extension). So fixed those to get the DataExtractor tests passing again. llvm-svn: 364253
Diffstat (limited to 'llvm/lib/Support/DataExtractor.cpp')
-rw-r--r--llvm/lib/Support/DataExtractor.cpp31
1 files changed, 10 insertions, 21 deletions
diff --git a/llvm/lib/Support/DataExtractor.cpp b/llvm/lib/Support/DataExtractor.cpp
index 4b26718c68c..673bbb4d06f 100644
--- a/llvm/lib/Support/DataExtractor.cpp
+++ b/llvm/lib/Support/DataExtractor.cpp
@@ -160,26 +160,15 @@ uint64_t DataExtractor::getULEB128(uint32_t *offset_ptr) const {
}
int64_t DataExtractor::getSLEB128(uint32_t *offset_ptr) const {
- int64_t result = 0;
- if (Data.empty())
- return 0;
+ assert(*offset_ptr <= Data.size());
- unsigned shift = 0;
- uint32_t offset = *offset_ptr;
- uint8_t byte = 0;
-
- while (isValidOffset(offset)) {
- byte = Data[offset++];
- result |= uint64_t(byte & 0x7f) << shift;
- shift += 7;
- if ((byte & 0x80) == 0) {
- // Sign bit of byte is 2nd high order bit (0x40)
- if (shift < 64 && (byte & 0x40))
- result |= -(1ULL << shift);
-
- *offset_ptr = offset;
- return result;
- }
- }
- return 0;
+ const char *error;
+ unsigned bytes_read;
+ int64_t result = decodeSLEB128(
+ reinterpret_cast<const uint8_t *>(Data.data() + *offset_ptr), &bytes_read,
+ reinterpret_cast<const uint8_t *>(Data.data() + Data.size()), &error);
+ if (error)
+ return 0;
+ *offset_ptr += bytes_read;
+ return result;
}
OpenPOWER on IntegriCloud