[clang] 22cf54a - Replace `T(x)` with `reinterpret_cast<T>(x)` everywhere it means reinterpret_cast. NFC.
Arthur O'Dwyer via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 22 16:54:42 PST 2020
Author: Arthur O'Dwyer
Date: 2020-12-22T19:54:29-05:00
New Revision: 22cf54a7fba670642c121684ac3c7ff7e35dfa5c
URL: https://github.com/llvm/llvm-project/commit/22cf54a7fba670642c121684ac3c7ff7e35dfa5c
DIFF: https://github.com/llvm/llvm-project/commit/22cf54a7fba670642c121684ac3c7ff7e35dfa5c.diff
LOG: Replace `T(x)` with `reinterpret_cast<T>(x)` everywhere it means reinterpret_cast. NFC.
Differential Revision: https://reviews.llvm.org/D76572
Added:
Modified:
clang/lib/CodeGen/CGCall.h
llvm/include/llvm/IR/SymbolTableListTraits.h
llvm/include/llvm/Object/Binary.h
llvm/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
llvm/lib/Object/COFFObjectFile.cpp
llvm/lib/Object/ELFObjectFile.cpp
llvm/lib/Object/XCOFFObjectFile.cpp
llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGCall.h b/clang/lib/CodeGen/CGCall.h
index 509ca43a9784..e3d9fec6d363 100644
--- a/clang/lib/CodeGen/CGCall.h
+++ b/clang/lib/CodeGen/CGCall.h
@@ -110,7 +110,8 @@ class CGCallee {
/// Construct a callee. Call this constructor directly when this
/// isn't a direct call.
CGCallee(const CGCalleeInfo &abstractInfo, llvm::Value *functionPtr)
- : KindOrFunctionPointer(SpecialKind(uintptr_t(functionPtr))) {
+ : KindOrFunctionPointer(
+ SpecialKind(reinterpret_cast<uintptr_t>(functionPtr))) {
AbstractInfo = abstractInfo;
assert(functionPtr && "configuring callee without function pointer");
assert(functionPtr->getType()->isPointerTy());
@@ -186,7 +187,8 @@ class CGCallee {
}
void setFunctionPointer(llvm::Value *functionPtr) {
assert(isOrdinary());
- KindOrFunctionPointer = SpecialKind(uintptr_t(functionPtr));
+ KindOrFunctionPointer =
+ SpecialKind(reinterpret_cast<uintptr_t>(functionPtr));
}
bool isVirtual() const {
diff --git a/llvm/include/llvm/IR/SymbolTableListTraits.h b/llvm/include/llvm/IR/SymbolTableListTraits.h
index 5b793e5dbf28..8af712374bfa 100644
--- a/llvm/include/llvm/IR/SymbolTableListTraits.h
+++ b/llvm/include/llvm/IR/SymbolTableListTraits.h
@@ -76,9 +76,11 @@ class SymbolTableListTraits : public ilist_alloc_traits<ValueSubClass> {
/// getListOwner - Return the object that owns this list. If this is a list
/// of instructions, it returns the BasicBlock that owns them.
ItemParentClass *getListOwner() {
- size_t Offset(size_t(&((ItemParentClass*)nullptr->*ItemParentClass::
- getSublistAccess(static_cast<ValueSubClass*>(nullptr)))));
- ListTy *Anchor(static_cast<ListTy *>(this));
+ size_t Offset = reinterpret_cast<size_t>(
+ &((ItemParentClass *)nullptr->*ItemParentClass::getSublistAccess(
+ static_cast<ValueSubClass *>(
+ nullptr))));
+ ListTy *Anchor = static_cast<ListTy *>(this);
return reinterpret_cast<ItemParentClass*>(reinterpret_cast<char*>(Anchor)-
Offset);
}
diff --git a/llvm/include/llvm/Object/Binary.h b/llvm/include/llvm/Object/Binary.h
index e12e512d68b8..dd98e1143e25 100644
--- a/llvm/include/llvm/Object/Binary.h
+++ b/llvm/include/llvm/Object/Binary.h
@@ -165,8 +165,8 @@ class Binary {
static Error checkOffset(MemoryBufferRef M, uintptr_t Addr,
const uint64_t Size) {
if (Addr + Size < Addr || Addr + Size < Size ||
- Addr + Size > uintptr_t(M.getBufferEnd()) ||
- Addr < uintptr_t(M.getBufferStart())) {
+ Addr + Size > reinterpret_cast<uintptr_t>(M.getBufferEnd()) ||
+ Addr < reinterpret_cast<uintptr_t>(M.getBufferStart())) {
return errorCodeToError(object_error::unexpected_eof);
}
return Error::success();
diff --git a/llvm/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
index 8fa83f515910..354b638b47a2 100644
--- a/llvm/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
@@ -145,9 +145,10 @@ void OcamlGCMetadataPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
report_fatal_error("Function '" + FI.getFunction().getName() +
"' is too large for the ocaml GC! "
"Frame size " +
- Twine(FrameSize) + ">= 65536.\n"
- "(" +
- Twine(uintptr_t(&FI)) + ")");
+ Twine(FrameSize) +
+ ">= 65536.\n"
+ "(" +
+ Twine(reinterpret_cast<uintptr_t>(&FI)) + ")");
}
AP.OutStreamer->AddComment("live roots for " +
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp
index c0902597fadf..2e44a38ccdaa 100644
--- a/llvm/lib/Object/COFFObjectFile.cpp
+++ b/llvm/lib/Object/COFFObjectFile.cpp
@@ -57,7 +57,7 @@ static bool checkSize(MemoryBufferRef M, std::error_code &EC, uint64_t Size) {
template <typename T>
static Error getObject(const T *&Obj, MemoryBufferRef M, const void *Ptr,
const uint64_t Size = sizeof(T)) {
- uintptr_t Addr = uintptr_t(Ptr);
+ uintptr_t Addr = reinterpret_cast<uintptr_t>(Ptr);
if (Error E = Binary::checkOffset(M, Addr, Size))
return E;
Obj = reinterpret_cast<const T *>(Addr);
@@ -103,10 +103,11 @@ const coff_symbol_type *COFFObjectFile::toSymb(DataRefImpl Ref) const {
const coff_symbol_type *Addr =
reinterpret_cast<const coff_symbol_type *>(Ref.p);
- assert(!checkOffset(Data, uintptr_t(Addr), sizeof(*Addr)));
+ assert(!checkOffset(Data, reinterpret_cast<uintptr_t>(Addr), sizeof(*Addr)));
#ifndef NDEBUG
// Verify that the symbol points to a valid entry in the symbol table.
- uintptr_t Offset = uintptr_t(Addr) - uintptr_t(base());
+ uintptr_t Offset =
+ reinterpret_cast<uintptr_t>(Addr) - reinterpret_cast<uintptr_t>(base());
assert((Offset - getPointerToSymbolTable()) % sizeof(coff_symbol_type) == 0 &&
"Symbol did not point to the beginning of a symbol");
@@ -123,7 +124,8 @@ const coff_section *COFFObjectFile::toSec(DataRefImpl Ref) const {
if (Addr < SectionTable || Addr >= (SectionTable + getNumberOfSections()))
report_fatal_error("Section was outside of section table.");
- uintptr_t Offset = uintptr_t(Addr) - uintptr_t(SectionTable);
+ uintptr_t Offset = reinterpret_cast<uintptr_t>(Addr) -
+ reinterpret_cast<uintptr_t>(SectionTable);
assert(Offset % sizeof(coff_section) == 0 &&
"Section did not point to the beginning of a section");
#endif
@@ -332,7 +334,7 @@ bool COFFObjectFile::isDebugSection(StringRef SectionName) const {
unsigned COFFObjectFile::getSectionID(SectionRef Sec) const {
uintptr_t Offset =
- uintptr_t(Sec.getRawDataRefImpl().p) - uintptr_t(SectionTable);
+ Sec.getRawDataRefImpl().p - reinterpret_cast<uintptr_t>(SectionTable);
assert((Offset % sizeof(coff_section)) == 0);
return (Offset / sizeof(coff_section)) + 1;
}
@@ -376,7 +378,7 @@ getFirstReloc(const coff_section *Sec, MemoryBufferRef M, const uint8_t *Base) {
// relocations.
begin++;
}
- if (auto E = Binary::checkOffset(M, uintptr_t(begin),
+ if (auto E = Binary::checkOffset(M, reinterpret_cast<uintptr_t>(begin),
sizeof(coff_relocation) * NumRelocs)) {
consumeError(std::move(E));
return nullptr;
@@ -467,7 +469,8 @@ Error COFFObjectFile::getRvaPtr(uint32_t Addr, uintptr_t &Res) const {
uint32_t SectionEnd = Section->VirtualAddress + Section->VirtualSize;
if (SectionStart <= Addr && Addr < SectionEnd) {
uint32_t Offset = Addr - SectionStart;
- Res = uintptr_t(base()) + Section->PointerToRawData + Offset;
+ Res = reinterpret_cast<uintptr_t>(base()) + Section->PointerToRawData +
+ Offset;
return Error::success();
}
}
@@ -484,8 +487,8 @@ Error COFFObjectFile::getRvaAndSizeAsBytes(uint32_t RVA, uint32_t Size,
uint32_t OffsetIntoSection = RVA - SectionStart;
if (SectionStart <= RVA && OffsetIntoSection < Section->VirtualSize &&
Size <= Section->VirtualSize - OffsetIntoSection) {
- uintptr_t Begin =
- uintptr_t(base()) + Section->PointerToRawData + OffsetIntoSection;
+ uintptr_t Begin = reinterpret_cast<uintptr_t>(base()) +
+ Section->PointerToRawData + OffsetIntoSection;
Contents =
ArrayRef<uint8_t>(reinterpret_cast<const uint8_t *>(Begin), Size);
return Error::success();
@@ -1127,7 +1130,8 @@ Error COFFObjectFile::getSectionContents(const coff_section *Sec,
// The only thing that we need to verify is that the contents is contained
// within the file bounds. We don't need to make sure it doesn't cover other
// data, as there's nothing that says that is not allowed.
- uintptr_t ConStart = uintptr_t(base()) + Sec->PointerToRawData;
+ uintptr_t ConStart =
+ reinterpret_cast<uintptr_t>(base()) + Sec->PointerToRawData;
uint32_t SectionSize = getSectionSize(Sec);
if (Error E = checkOffset(Data, ConStart, SectionSize))
return E;
diff --git a/llvm/lib/Object/ELFObjectFile.cpp b/llvm/lib/Object/ELFObjectFile.cpp
index c654c3fd3d6c..91871a6255dc 100644
--- a/llvm/lib/Object/ELFObjectFile.cpp
+++ b/llvm/lib/Object/ELFObjectFile.cpp
@@ -73,7 +73,8 @@ ObjectFile::createELFObjectFile(MemoryBufferRef Obj, bool InitContent) {
std::pair<unsigned char, unsigned char> Ident =
getElfArchType(Obj.getBuffer());
std::size_t MaxAlignment =
- 1ULL << countTrailingZeros(uintptr_t(Obj.getBufferStart()));
+ 1ULL << countTrailingZeros(
+ reinterpret_cast<uintptr_t>(Obj.getBufferStart()));
if (MaxAlignment < 2)
return createError("Insufficient alignment");
diff --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp
index fee468584f36..b0d772b6ff21 100644
--- a/llvm/lib/Object/XCOFFObjectFile.cpp
+++ b/llvm/lib/Object/XCOFFObjectFile.cpp
@@ -31,7 +31,7 @@ static const uint16_t NoRelMask = 0x0001;
template <typename T>
static Expected<const T *> getObject(MemoryBufferRef M, const void *Ptr,
const uint64_t Size = sizeof(T)) {
- uintptr_t Addr = uintptr_t(Ptr);
+ uintptr_t Addr = reinterpret_cast<uintptr_t>(Ptr);
if (Error E = Binary::checkOffset(M, Addr, Size))
return std::move(E);
return reinterpret_cast<const T *>(Addr);
@@ -283,7 +283,7 @@ XCOFFObjectFile::getSectionContents(DataRefImpl Sec) const {
const uint8_t * ContentStart = base() + OffsetToRaw;
uint64_t SectionSize = getSectionSize(Sec);
- if (checkOffset(Data, uintptr_t(ContentStart), SectionSize))
+ if (checkOffset(Data, reinterpret_cast<uintptr_t>(ContentStart), SectionSize))
return make_error<BinaryError>();
return makeArrayRef(ContentStart,SectionSize);
diff --git a/llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp b/llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp
index a8e03a653e86..04cd432f56c5 100644
--- a/llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp
@@ -472,10 +472,11 @@ static const NodeSet *node_class(GepNode *N, NodeSymRel &Rel) {
// determining equality. The only purpose of the ordering is to eliminate
// duplication due to the commutativity of equality/non-equality.
static NodePair node_pair(GepNode *N1, GepNode *N2) {
- uintptr_t P1 = uintptr_t(N1), P2 = uintptr_t(N2);
- if (P1 <= P2)
- return std::make_pair(N1, N2);
- return std::make_pair(N2, N1);
+ uintptr_t P1 = reinterpret_cast<uintptr_t>(N1);
+ uintptr_t P2 = reinterpret_cast<uintptr_t>(N2);
+ if (P1 <= P2)
+ return std::make_pair(N1, N2);
+ return std::make_pair(N2, N1);
}
static unsigned node_hash(GepNode *N) {
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 178cca87f2d4..a82494ad1b4d 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -505,7 +505,9 @@ Expected<ArrayRef<typename ELFT::Versym>>
ELFDumper<ELFT>::getVersionTable(const Elf_Shdr &Sec, ArrayRef<Elf_Sym> *SymTab,
StringRef *StrTab) const {
assert((!SymTab && !StrTab) || (SymTab && StrTab));
- if (uintptr_t(Obj.base() + Sec.sh_offset) % sizeof(uint16_t) != 0)
+ if (reinterpret_cast<uintptr_t>(Obj.base() + Sec.sh_offset) %
+ sizeof(uint16_t) !=
+ 0)
return createError("the " + describe(Sec) + " is misaligned");
Expected<ArrayRef<Elf_Versym>> VersionsOrErr =
@@ -576,7 +578,7 @@ ELFDumper<ELFT>::getVersionDefinitions(const Elf_Shdr &Sec) const {
return createError("invalid " + describe(Sec) + ": version definition " +
Twine(I) + " goes past the end of the section");
- if (uintptr_t(VerdefBuf) % sizeof(uint32_t) != 0)
+ if (reinterpret_cast<uintptr_t>(VerdefBuf) % sizeof(uint32_t) != 0)
return createError(
"invalid " + describe(Sec) +
": found a misaligned version definition entry at offset 0x" +
@@ -598,7 +600,7 @@ ELFDumper<ELFT>::getVersionDefinitions(const Elf_Shdr &Sec) const {
const uint8_t *VerdauxBuf = VerdefBuf + D->vd_aux;
for (unsigned J = 0; J < D->vd_cnt; ++J) {
- if (uintptr_t(VerdauxBuf) % sizeof(uint32_t) != 0)
+ if (reinterpret_cast<uintptr_t>(VerdauxBuf) % sizeof(uint32_t) != 0)
return createError("invalid " + describe(Sec) +
": found a misaligned auxiliary entry at offset 0x" +
Twine::utohexstr(VerdauxBuf - Start));
@@ -644,7 +646,7 @@ ELFDumper<ELFT>::getVersionDependencies(const Elf_Shdr &Sec) const {
return createError("invalid " + describe(Sec) + ": version dependency " +
Twine(I) + " goes past the end of the section");
- if (uintptr_t(VerneedBuf) % sizeof(uint32_t) != 0)
+ if (reinterpret_cast<uintptr_t>(VerneedBuf) % sizeof(uint32_t) != 0)
return createError(
"invalid " + describe(Sec) +
": found a misaligned version dependency entry at offset 0x" +
@@ -670,7 +672,7 @@ ELFDumper<ELFT>::getVersionDependencies(const Elf_Shdr &Sec) const {
const uint8_t *VernauxBuf = VerneedBuf + Verneed->vn_aux;
for (unsigned J = 0; J < Verneed->vn_cnt; ++J) {
- if (uintptr_t(VernauxBuf) % sizeof(uint32_t) != 0)
+ if (reinterpret_cast<uintptr_t>(VernauxBuf) % sizeof(uint32_t) != 0)
return createError("invalid " + describe(Sec) +
": found a misaligned auxiliary entry at offset 0x" +
Twine::utohexstr(VernauxBuf - Start));
More information about the cfe-commits
mailing list