]> granicus.if.org Git - llvm/commitdiff
Change some StringRef::data() reinterpret_cast to bytes_begin() or arrayRefFromString...
authorFangrui Song <maskray@google.com>
Sun, 7 Apr 2019 03:58:42 +0000 (03:58 +0000)
committerFangrui Song <maskray@google.com>
Sun, 7 Apr 2019 03:58:42 +0000 (03:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357852 91177308-0d34-0410-b5e6-96231b3b80d8

15 files changed:
include/llvm/Bitcode/BitstreamReader.h
include/llvm/Object/ELF.h
include/llvm/ObjectYAML/YAML.h
lib/DebugInfo/DWARF/DWARFFormValue.cpp
lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
lib/IR/Constants.cpp
lib/Object/WasmObjectFile.cpp
lib/ProfileData/Coverage/CoverageMappingReader.cpp
lib/ProfileData/InstrProf.cpp
tools/llvm-objdump/MachODump.cpp
tools/llvm-objdump/llvm-objdump.cpp
tools/llvm-readobj/COFFDumper.cpp
tools/llvm-readobj/MachODumper.cpp
tools/sancov/sancov.cpp
unittests/MC/DwarfLineTables.cpp

index 90cbe7b4b1e3219f8738203dceb596019f82617c..03a7fb8758b03d0196163185c76c0e1880ad34d7 100644 (file)
@@ -103,8 +103,7 @@ public:
   explicit SimpleBitstreamCursor(ArrayRef<uint8_t> BitcodeBytes)
       : BitcodeBytes(BitcodeBytes) {}
   explicit SimpleBitstreamCursor(StringRef BitcodeBytes)
-      : BitcodeBytes(reinterpret_cast<const uint8_t *>(BitcodeBytes.data()),
-                     BitcodeBytes.size()) {}
+      : BitcodeBytes(arrayRefFromStringRef(BitcodeBytes)) {}
   explicit SimpleBitstreamCursor(MemoryBufferRef BitcodeBytes)
       : SimpleBitstreamCursor(BitcodeBytes.getBuffer()) {}
 
index a49f7128c64b690c4b44c627da0643c8ad689b6e..a1c9ddacd78877b2a39d9b3425dc331d9a4842ad 100644 (file)
@@ -79,9 +79,7 @@ public:
   using Elf_Relr_Range = typename ELFT::RelrRange;
   using Elf_Phdr_Range = typename ELFT::PhdrRange;
 
-  const uint8_t *base() const {
-    return reinterpret_cast<const uint8_t *>(Buf.data());
-  }
+  const uint8_t *base() const { return Buf.bytes_begin(); }
 
   size_t getBufSize() const { return Buf.size(); }
 
index a14bfbc5f38a36a6000ea6f44d71b6b186b5b029..37014109a615407d91dbb5ebe91080dbcda5c17d 100644 (file)
@@ -73,8 +73,7 @@ class BinaryRef {
 public:
   BinaryRef() = default;
   BinaryRef(ArrayRef<uint8_t> Data) : Data(Data), DataIsHexString(false) {}
-  BinaryRef(StringRef Data)
-      : Data(reinterpret_cast<const uint8_t *>(Data.data()), Data.size()) {}
+  BinaryRef(StringRef Data) : Data(arrayRefFromStringRef(Data)) {}
 
   /// The number of bytes that are represented by this BinaryRef.
   /// This is the number of bytes that writeAsBinary() will write.
index 4129593848c0f139ab7f4b8531d386d9fa751afa..bdc2e54b3e9e63a97d38b3869d3ca171ba5d2a7c 100644 (file)
@@ -354,7 +354,7 @@ bool DWARFFormValue::extractValue(const DWARFDataExtractor &Data,
     StringRef Str = Data.getData().substr(*OffsetPtr, Value.uval);
     Value.data = nullptr;
     if (!Str.empty()) {
-      Value.data = reinterpret_cast<const uint8_t *>(Str.data());
+      Value.data = Str.bytes_begin();
       *OffsetPtr += Value.uval;
     }
   }
index 642c381aaf912b5e0d5089a8aed9aee87be21aba..28c8a69939eb8daf372ec59c0b45c69063e2e920 100644 (file)
@@ -666,9 +666,7 @@ private:
   bool decodeInst(StringRef Symbol, MCInst &Inst, uint64_t &Size) const {
     MCDisassembler *Dis = Checker.Disassembler;
     StringRef SectionMem = Checker.getSubsectionStartingAt(Symbol);
-    ArrayRef<uint8_t> SectionBytes(
-        reinterpret_cast<const uint8_t *>(SectionMem.data()),
-        SectionMem.size());
+    ArrayRef<uint8_t> SectionBytes(SectionMem.bytes_begin(), SectionMem.size());
 
     MCDisassembler::DecodeStatus S =
         Dis->getInstruction(Inst, Size, SectionBytes, 0, nulls(), nulls());
index a1619921f8b4490d0431aa254619f9d12e21c3b7..00c722651ed8df3b1fc8596eb1e1ec6c4223b0bb 100644 (file)
@@ -2576,7 +2576,7 @@ Constant *ConstantDataArray::getFP(LLVMContext &Context,
 Constant *ConstantDataArray::getString(LLVMContext &Context,
                                        StringRef Str, bool AddNull) {
   if (!AddNull) {
-    const uint8_t *Data = reinterpret_cast<const uint8_t *>(Str.data());
+    const uint8_t *Data = Str.bytes_begin();
     return get(Context, makeArrayRef(Data, Str.size()));
   }
 
index 9d521544593afa2dec56b36a6bb93e4a7d836959..16645002a6d698de0a5dce3d0f53258e44ba18ad 100644 (file)
@@ -255,7 +255,7 @@ WasmObjectFile::WasmObjectFile(MemoryBufferRef Buffer, Error &Err)
   }
 
   ReadContext Ctx;
-  Ctx.Start = reinterpret_cast<const uint8_t *>(getData().data());
+  Ctx.Start = getData().bytes_begin();
   Ctx.Ptr = Ctx.Start + 4;
   Ctx.End = Ctx.Start + getData().size();
 
index 3724329e132e18517e704e45c985f2674dcdea81..fd522dc309e4855e996bc5365b93e3aca5bcf959 100644 (file)
@@ -59,7 +59,7 @@ Error RawCoverageReader::readULEB128(uint64_t &Result) {
   if (Data.empty())
     return make_error<CoverageMapError>(coveragemap_error::truncated);
   unsigned N = 0;
-  Result = decodeULEB128(reinterpret_cast<const uint8_t *>(Data.data()), &N);
+  Result = decodeULEB128(Data.bytes_begin(), &N);
   if (N > Data.size())
     return make_error<CoverageMapError>(coveragemap_error::malformed);
   Data = Data.substr(N);
@@ -595,16 +595,14 @@ static Error loadTestingFormat(StringRef Data, InstrProfSymtab &ProfileNames,
   if (Data.empty())
     return make_error<CoverageMapError>(coveragemap_error::truncated);
   unsigned N = 0;
-  auto ProfileNamesSize =
-      decodeULEB128(reinterpret_cast<const uint8_t *>(Data.data()), &N);
+  uint64_t ProfileNamesSize = decodeULEB128(Data.bytes_begin(), &N);
   if (N > Data.size())
     return make_error<CoverageMapError>(coveragemap_error::malformed);
   Data = Data.substr(N);
   if (Data.empty())
     return make_error<CoverageMapError>(coveragemap_error::truncated);
   N = 0;
-  uint64_t Address =
-      decodeULEB128(reinterpret_cast<const uint8_t *>(Data.data()), &N);
+  uint64_t Address = decodeULEB128(Data.bytes_begin(), &N);
   if (N > Data.size())
     return make_error<CoverageMapError>(coveragemap_error::malformed);
   Data = Data.substr(N);
index ccb651a22b30ef9fe37b8d943b745f8933720875..91a3d173111337fce0c6f8fecbbac508778b7c19 100644 (file)
@@ -434,9 +434,8 @@ Error collectPGOFuncNameStrings(ArrayRef<GlobalVariable *> NameVars,
 }
 
 Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab) {
-  const uint8_t *P = reinterpret_cast<const uint8_t *>(NameStrings.data());
-  const uint8_t *EndP = reinterpret_cast<const uint8_t *>(NameStrings.data() +
-                                                          NameStrings.size());
+  const uint8_t *P = NameStrings.bytes_begin();
+  const uint8_t *EndP = NameStrings.bytes_end();
   while (P < EndP) {
     uint32_t N;
     uint64_t UncompressedSize = decodeULEB128(P, &N);
index dc60ee1f0c6f1fe269a2599500bcf78dcc3e5679..b2c528695011ee625754256156c8625a1e1f9aea 100644 (file)
@@ -7275,8 +7275,7 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
 
     StringRef BytesStr;
     Sections[SectIdx].getContents(BytesStr);
-    ArrayRef<uint8_t> Bytes(reinterpret_cast<const uint8_t *>(BytesStr.data()),
-                            BytesStr.size());
+    ArrayRef<uint8_t> Bytes = arrayRefFromStringRef(BytesStr);
     uint64_t SectAddress = Sections[SectIdx].getAddress();
 
     bool symbolTableWorked = false;
index 4f0446a31443d880b503214dbb851f7a74232bde..b035cfa7c094889ae40285e1984fa34109d7fc5d 100644 (file)
@@ -1084,8 +1084,7 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
 
     StringRef BytesStr;
     error(Section.getContents(BytesStr));
-    ArrayRef<uint8_t> Bytes(reinterpret_cast<const uint8_t *>(BytesStr.data()),
-                            BytesStr.size());
+    ArrayRef<uint8_t> Bytes = arrayRefFromStringRef(BytesStr);
 
     uint64_t VMAAdjustment = 0;
     if (shouldAdjustVA(Section))
index 481838ed36622152c3bb0f268a07acebcde5bc65..334203c0d99fa074062ae2d6ce77ad6728dd6ed0 100644 (file)
@@ -1862,9 +1862,8 @@ void COFFDumper::printStackMap() const {
 
   StringRef StackMapContents;
   StackMapSection.getContents(StackMapContents);
-  ArrayRef<uint8_t> StackMapContentsArray(
-      reinterpret_cast<const uint8_t*>(StackMapContents.data()),
-      StackMapContents.size());
+  ArrayRef<uint8_t> StackMapContentsArray =
+      arrayRefFromStringRef(StackMapContents);
 
   if (Obj->isLittleEndian())
     prettyPrintStackMap(
@@ -1890,13 +1889,12 @@ void COFFDumper::printAddrsig() {
 
   StringRef AddrsigContents;
   AddrsigSection.getContents(AddrsigContents);
-  ArrayRef<uint8_t> AddrsigContentsArray(
-      reinterpret_cast<const uint8_t*>(AddrsigContents.data()),
-      AddrsigContents.size());
+  ArrayRef<uint8_t> AddrsigContentsArray(AddrsigContents.bytes_begin(),
+                                         AddrsigContents.size());
 
   ListScope L(W, "Addrsig");
-  auto *Cur = reinterpret_cast<const uint8_t *>(AddrsigContents.begin());
-  auto *End = reinterpret_cast<const uint8_t *>(AddrsigContents.end());
+  const uint8_t *Cur = AddrsigContents.bytes_begin();
+  const uint8_t *End = AddrsigContents.bytes_end();
   while (Cur != End) {
     unsigned Size;
     const char *Err;
index 1c3e33806b7137576e4e61a1ef8ae7ec4a44a1df..0cb954c1ed8e533db1385a0e705a50a294d7f959 100644 (file)
@@ -661,9 +661,8 @@ void MachODumper::printStackMap() const {
 
   StringRef StackMapContents;
   StackMapSection.getContents(StackMapContents);
-  ArrayRef<uint8_t> StackMapContentsArray(
-      reinterpret_cast<const uint8_t*>(StackMapContents.data()),
-      StackMapContents.size());
+  ArrayRef<uint8_t> StackMapContentsArray =
+      arrayRefFromStringRef(StackMapContents);
 
   if (Obj->isLittleEndian())
     prettyPrintStackMap(
index cd149a5b03f1adf6c3bbed574d513b8c969a9616..31949a7c5bc0d38c413cbac336de48851be320cb 100644 (file)
@@ -843,8 +843,7 @@ static void getObjectCoveragePoints(const object::ObjectFile &O,
 
     StringRef BytesStr;
     failIfError(Section.getContents(BytesStr));
-    ArrayRef<uint8_t> Bytes(reinterpret_cast<const uint8_t *>(BytesStr.data()),
-                            BytesStr.size());
+    ArrayRef<uint8_t> Bytes = arrayRefFromStringRef(BytesStr);
 
     for (uint64_t Index = 0, Size = 0; Index < Section.getSize();
          Index += Size) {
index 95ae72bceac3555a798169f859048474d78a9abd..af1250daee5a113b574913ea79368c52d3344a46 100644 (file)
@@ -57,9 +57,7 @@ void verifyEncoding(MCDwarfLineTableParams Params, int LineDelta, int AddrDelta,
   raw_svector_ostream EncodingOS(Buffer);
   MCDwarfLineAddr::Encode(getContext(), Params, LineDelta, AddrDelta,
                           EncodingOS);
-  ArrayRef<uint8_t> Encoding(reinterpret_cast<uint8_t *>(Buffer.data()),
-                             Buffer.size());
-  EXPECT_EQ(ExpectedEncoding, Encoding);
+  EXPECT_EQ(ExpectedEncoding, arrayRefFromStringRef(Buffer));
 }
 
 TEST(DwarfLineTables, TestDefaultParams) {