llvm.org GIT mirror llvm / 9cc7149
Change some StringRef::data() reinterpret_cast to bytes_begin() or arrayRefFromStringRef() git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357852 91177308-0d34-0410-b5e6-96231b3b80d8 Fangrui Song 7 months ago
15 changed file(s) with 24 addition(s) and 41 deletion(s). Raw diff Collapse all Expand all
102102 explicit SimpleBitstreamCursor(ArrayRef BitcodeBytes)
103103 : BitcodeBytes(BitcodeBytes) {}
104104 explicit SimpleBitstreamCursor(StringRef BitcodeBytes)
105 : BitcodeBytes(reinterpret_cast(BitcodeBytes.data()),
106 BitcodeBytes.size()) {}
105 : BitcodeBytes(arrayRefFromStringRef(BitcodeBytes)) {}
107106 explicit SimpleBitstreamCursor(MemoryBufferRef BitcodeBytes)
108107 : SimpleBitstreamCursor(BitcodeBytes.getBuffer()) {}
109108
7878 using Elf_Relr_Range = typename ELFT::RelrRange;
7979 using Elf_Phdr_Range = typename ELFT::PhdrRange;
8080
81 const uint8_t *base() const {
82 return reinterpret_cast(Buf.data());
83 }
81 const uint8_t *base() const { return Buf.bytes_begin(); }
8482
8583 size_t getBufSize() const { return Buf.size(); }
8684
7272 public:
7373 BinaryRef() = default;
7474 BinaryRef(ArrayRef Data) : Data(Data), DataIsHexString(false) {}
75 BinaryRef(StringRef Data)
76 : Data(reinterpret_cast(Data.data()), Data.size()) {}
75 BinaryRef(StringRef Data) : Data(arrayRefFromStringRef(Data)) {}
7776
7877 /// The number of bytes that are represented by this BinaryRef.
7978 /// This is the number of bytes that writeAsBinary() will write.
353353 StringRef Str = Data.getData().substr(*OffsetPtr, Value.uval);
354354 Value.data = nullptr;
355355 if (!Str.empty()) {
356 Value.data = reinterpret_cast(Str.data());
356 Value.data = Str.bytes_begin();
357357 *OffsetPtr += Value.uval;
358358 }
359359 }
665665 bool decodeInst(StringRef Symbol, MCInst &Inst, uint64_t &Size) const {
666666 MCDisassembler *Dis = Checker.Disassembler;
667667 StringRef SectionMem = Checker.getSubsectionStartingAt(Symbol);
668 ArrayRef SectionBytes(
669 reinterpret_cast(SectionMem.data()),
670 SectionMem.size());
668 ArrayRef SectionBytes(SectionMem.bytes_begin(), SectionMem.size());
671669
672670 MCDisassembler::DecodeStatus S =
673671 Dis->getInstruction(Inst, Size, SectionBytes, 0, nulls(), nulls());
25752575 Constant *ConstantDataArray::getString(LLVMContext &Context,
25762576 StringRef Str, bool AddNull) {
25772577 if (!AddNull) {
2578 const uint8_t *Data = reinterpret_cast(Str.data());
2578 const uint8_t *Data = Str.bytes_begin();
25792579 return get(Context, makeArrayRef(Data, Str.size()));
25802580 }
25812581
254254 }
255255
256256 ReadContext Ctx;
257 Ctx.Start = reinterpret_cast(getData().data());
257 Ctx.Start = getData().bytes_begin();
258258 Ctx.Ptr = Ctx.Start + 4;
259259 Ctx.End = Ctx.Start + getData().size();
260260
5858 if (Data.empty())
5959 return make_error(coveragemap_error::truncated);
6060 unsigned N = 0;
61 Result = decodeULEB128(reinterpret_cast(Data.data()), &N);
61 Result = decodeULEB128(Data.bytes_begin(), &N);
6262 if (N > Data.size())
6363 return make_error(coveragemap_error::malformed);
6464 Data = Data.substr(N);
594594 if (Data.empty())
595595 return make_error(coveragemap_error::truncated);
596596 unsigned N = 0;
597 auto ProfileNamesSize =
598 decodeULEB128(reinterpret_cast(Data.data()), &N);
597 uint64_t ProfileNamesSize = decodeULEB128(Data.bytes_begin(), &N);
599598 if (N > Data.size())
600599 return make_error(coveragemap_error::malformed);
601600 Data = Data.substr(N);
602601 if (Data.empty())
603602 return make_error(coveragemap_error::truncated);
604603 N = 0;
605 uint64_t Address =
606 decodeULEB128(reinterpret_cast(Data.data()), &N);
604 uint64_t Address = decodeULEB128(Data.bytes_begin(), &N);
607605 if (N > Data.size())
608606 return make_error(coveragemap_error::malformed);
609607 Data = Data.substr(N);
433433 }
434434
435435 Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab) {
436 const uint8_t *P = reinterpret_cast(NameStrings.data());
437 const uint8_t *EndP = reinterpret_cast(NameStrings.data() +
438 NameStrings.size());
436 const uint8_t *P = NameStrings.bytes_begin();
437 const uint8_t *EndP = NameStrings.bytes_end();
439438 while (P < EndP) {
440439 uint32_t N;
441440 uint64_t UncompressedSize = decodeULEB128(P, &N);
72747274
72757275 StringRef BytesStr;
72767276 Sections[SectIdx].getContents(BytesStr);
7277 ArrayRef Bytes(reinterpret_cast(BytesStr.data()),
7278 BytesStr.size());
7277 ArrayRef Bytes = arrayRefFromStringRef(BytesStr);
72797278 uint64_t SectAddress = Sections[SectIdx].getAddress();
72807279
72817280 bool symbolTableWorked = false;
10831083
10841084 StringRef BytesStr;
10851085 error(Section.getContents(BytesStr));
1086 ArrayRef Bytes(reinterpret_cast(BytesStr.data()),
1087 BytesStr.size());
1086 ArrayRef Bytes = arrayRefFromStringRef(BytesStr);
10881087
10891088 uint64_t VMAAdjustment = 0;
10901089 if (shouldAdjustVA(Section))
18611861
18621862 StringRef StackMapContents;
18631863 StackMapSection.getContents(StackMapContents);
1864 ArrayRef StackMapContentsArray(
1865 reinterpret_cast(StackMapContents.data()),
1866 StackMapContents.size());
1864 ArrayRef StackMapContentsArray =
1865 arrayRefFromStringRef(StackMapContents);
18671866
18681867 if (Obj->isLittleEndian())
18691868 prettyPrintStackMap(
18891888
18901889 StringRef AddrsigContents;
18911890 AddrsigSection.getContents(AddrsigContents);
1892 ArrayRef AddrsigContentsArray(
1893 reinterpret_cast(AddrsigContents.data()),
1894 AddrsigContents.size());
1891 ArrayRef AddrsigContentsArray(AddrsigContents.bytes_begin(),
1892 AddrsigContents.size());
18951893
18961894 ListScope L(W, "Addrsig");
1897 auto *Cur = reinterpret_cast(AddrsigContents.begin());
1898 auto *End = reinterpret_cast(AddrsigContents.end());
1895 const uint8_t *Cur = AddrsigContents.bytes_begin();
1896 const uint8_t *End = AddrsigContents.bytes_end();
18991897 while (Cur != End) {
19001898 unsigned Size;
19011899 const char *Err;
660660
661661 StringRef StackMapContents;
662662 StackMapSection.getContents(StackMapContents);
663 ArrayRef StackMapContentsArray(
664 reinterpret_cast(StackMapContents.data()),
665 StackMapContents.size());
663 ArrayRef StackMapContentsArray =
664 arrayRefFromStringRef(StackMapContents);
666665
667666 if (Obj->isLittleEndian())
668667 prettyPrintStackMap(
842842
843843 StringRef BytesStr;
844844 failIfError(Section.getContents(BytesStr));
845 ArrayRef Bytes(reinterpret_cast(BytesStr.data()),
846 BytesStr.size());
845 ArrayRef Bytes = arrayRefFromStringRef(BytesStr);
847846
848847 for (uint64_t Index = 0, Size = 0; Index < Section.getSize();
849848 Index += Size) {
5656 raw_svector_ostream EncodingOS(Buffer);
5757 MCDwarfLineAddr::Encode(getContext(), Params, LineDelta, AddrDelta,
5858 EncodingOS);
59 ArrayRef Encoding(reinterpret_cast(Buffer.data()),
60 Buffer.size());
61 EXPECT_EQ(ExpectedEncoding, Encoding);
59 EXPECT_EQ(ExpectedEncoding, arrayRefFromStringRef(Buffer));
6260 }
6361
6462 TEST(DwarfLineTables, TestDefaultParams) {