From 55c2699d29730d767def564befd2bf4ffbf9a3fe Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Fri, 14 Nov 2014 07:15:43 +0000 Subject: [PATCH] Follow-up to r221913. Fix some -Wcast-qual warning reasons. llvm-svn: 221974 --- lld/lib/Core/SymbolTable.cpp | 16 ++++--- lld/lib/ReaderWriter/ELF/ELFFile.h | 5 ++- lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h | 6 +-- lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp | 4 +- lld/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp | 8 ++-- lld/lib/ReaderWriter/MachO/ArchHandler_x86.cpp | 24 ++++++----- lld/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp | 24 +++++------ .../MachO/MachONormalizedFileBinaryReader.cpp | 12 +++--- .../MachO/MachONormalizedFileBinaryUtils.h | 12 +++--- lld/lib/ReaderWriter/PECOFF/EdataPass.h | 2 +- lld/lib/ReaderWriter/PECOFF/IdataPass.cpp | 5 ++- lld/lib/ReaderWriter/PECOFF/LoadConfigPass.h | 2 +- lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp | 50 +++++++++++----------- 13 files changed, 90 insertions(+), 80 deletions(-) diff --git a/lld/lib/Core/SymbolTable.cpp b/lld/lib/Core/SymbolTable.cpp index d9cc868..b06cdec 100644 --- a/lld/lib/Core/SymbolTable.cpp +++ b/lld/lib/Core/SymbolTable.cpp @@ -187,9 +187,10 @@ bool SymbolTable::addByName(const Atom &newAtom) { case NCR_Second: useNew = true; break; - case NCR_DupDef: - switch (mergeSelect(cast(existing)->merge(), - cast(&newAtom)->merge())) { + case NCR_DupDef: { + const auto *existingDef = cast(existing); + const auto *newDef = cast(&newAtom); + switch (mergeSelect(existingDef->merge(), newDef->merge())) { case MCR_First: useNew = false; break; @@ -197,14 +198,14 @@ bool SymbolTable::addByName(const Atom &newAtom) { useNew = true; break; case MCR_Largest: { - uint64_t existingSize = sectionSize((DefinedAtom*)existing); - uint64_t newSize = sectionSize((DefinedAtom*)&newAtom); + uint64_t existingSize = sectionSize(existingDef); + uint64_t newSize = sectionSize(newDef); useNew = (newSize >= existingSize); break; } case MCR_SameSize: { - uint64_t existingSize = sectionSize((DefinedAtom*)existing); - uint64_t newSize = sectionSize((DefinedAtom*)&newAtom); + uint64_t existingSize = sectionSize(existingDef); + uint64_t newSize = sectionSize(newDef); if (existingSize == newSize) { useNew = true; break; @@ -231,6 +232,7 @@ bool SymbolTable::addByName(const Atom &newAtom) { break; } break; + } case NCR_DupUndef: { const UndefinedAtom* existingUndef = cast(existing); const UndefinedAtom* newUndef = cast(&newAtom); diff --git a/lld/lib/ReaderWriter/ELF/ELFFile.h b/lld/lib/ReaderWriter/ELF/ELFFile.h index 78950de8..c5526665 100644 --- a/lld/lib/ReaderWriter/ELF/ELFFile.h +++ b/lld/lib/ReaderWriter/ELF/ELFFile.h @@ -664,8 +664,9 @@ template std::error_code ELFFile::createAtoms() { } } - ArrayRef symbolData( - (uint8_t *)sectionContents->data() + symbol->st_value, contentSize); + ArrayRef symbolData((const uint8_t *)sectionContents->data() + + symbol->st_value, + contentSize); // If the linker finds that a section has global atoms that are in a // mergeable section, treat them as defined atoms as they shouldn't be diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h index 4cc2c97..723e4f6 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h @@ -216,9 +216,9 @@ private: case llvm::ELF::R_MIPS_32: case llvm::ELF::R_MIPS_GPREL32: case llvm::ELF::R_MIPS_PC32: - return *(int32_t *)ap; + return *(const int32_t *)ap; case llvm::ELF::R_MIPS_26: - return *(int32_t *)ap & 0x3ffffff; + return *(const int32_t *)ap & 0x3ffffff; case llvm::ELF::R_MIPS_HI16: case llvm::ELF::R_MIPS_LO16: case llvm::ELF::R_MIPS_GOT16: @@ -226,7 +226,7 @@ private: case llvm::ELF::R_MIPS_TLS_DTPREL_LO16: case llvm::ELF::R_MIPS_TLS_TPREL_HI16: case llvm::ELF::R_MIPS_TLS_TPREL_LO16: - return *(int16_t *)ap; + return *(const int16_t *)ap; case llvm::ELF::R_MIPS_CALL16: case llvm::ELF::R_MIPS_TLS_GD: case llvm::ELF::R_MIPS_TLS_LDM: diff --git a/lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp b/lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp index 65a4080..3e74d7b 100644 --- a/lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp +++ b/lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp @@ -521,7 +521,7 @@ std::error_code ArchHandler_arm::getReferenceInfo( typedef std::error_code E; const uint8_t *fixupContent = &inAtom->rawContent()[offsetInAtom]; uint64_t targetAddress; - uint32_t instruction = *(ulittle32_t *)fixupContent; + uint32_t instruction = *(const ulittle32_t *)fixupContent; int32_t displacement; switch (relocPattern(reloc)) { case ARM_THUMB_RELOC_BR22 | rPcRel | rExtern | rLength4: @@ -781,7 +781,7 @@ ArchHandler_arm::getPairReferenceInfo(const normalized::Relocation &reloc1, } const uint8_t *fixupContent = &inAtom->rawContent()[offsetInAtom]; std::error_code ec; - uint32_t instruction = *(ulittle32_t *)fixupContent; + uint32_t instruction = *(const ulittle32_t *)fixupContent; uint32_t value; uint32_t fromAddress; uint32_t toAddress; diff --git a/lld/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp b/lld/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp index c4456a8..a5c26f4 100644 --- a/lld/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp +++ b/lld/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp @@ -360,7 +360,7 @@ std::error_code ArchHandler_arm64::getReferenceInfo( return std::error_code(); case ARM64_RELOC_PAGEOFF12 | rExtern | rLength4: // ex: ldr x0, [x1, _foo@PAGEOFF] - *kind = offset12KindFromInstruction(*(little32_t *)fixupContent); + *kind = offset12KindFromInstruction(*(const little32_t *)fixupContent); if (auto ec = atomFromSymbolIndex(reloc.symbol, target)) return ec; *addend = 0; @@ -398,7 +398,7 @@ std::error_code ArchHandler_arm64::getReferenceInfo( *kind = pointer64; if (auto ec = atomFromSymbolIndex(reloc.symbol, target)) return ec; - *addend = *(little64_t *)fixupContent; + *addend = *(const little64_t *)fixupContent; return std::error_code(); case ARM64_RELOC_POINTER_TO_GOT | rExtern | rLength8: // ex: .quad _foo@GOT @@ -458,7 +458,7 @@ std::error_code ArchHandler_arm64::getPairReferenceInfo( *kind = delta64; if (auto ec = atomFromSymbolIndex(reloc2.symbol, target)) return ec; - *addend = (int64_t)*(little64_t *)fixupContent + offsetInAtom; + *addend = (int64_t)*(const little64_t *)fixupContent + offsetInAtom; return std::error_code(); case ((ARM64_RELOC_SUBTRACTOR | rExtern | rLength4) << 16 | ARM64_RELOC_UNSIGNED | rExtern | rLength4): @@ -466,7 +466,7 @@ std::error_code ArchHandler_arm64::getPairReferenceInfo( *kind = delta32; if (auto ec = atomFromSymbolIndex(reloc2.symbol, target)) return ec; - *addend = (int32_t)*(little32_t *)fixupContent + offsetInAtom; + *addend = (int32_t)*(const little32_t *)fixupContent + offsetInAtom; return std::error_code(); default: return make_dynamic_error_code(Twine("unsupported arm64 relocation pair")); diff --git a/lld/lib/ReaderWriter/MachO/ArchHandler_x86.cpp b/lld/lib/ReaderWriter/MachO/ArchHandler_x86.cpp index a2b6067..9a9ea96 100644 --- a/lld/lib/ReaderWriter/MachO/ArchHandler_x86.cpp +++ b/lld/lib/ReaderWriter/MachO/ArchHandler_x86.cpp @@ -262,18 +262,20 @@ ArchHandler_x86::getReferenceInfo(const Relocation &reloc, *kind = branch32; if (E ec = atomFromSymbolIndex(reloc.symbol, target)) return ec; - *addend = fixupAddress + 4 + (int32_t)*(little32_t *)fixupContent; + *addend = fixupAddress + 4 + (int32_t)*(const little32_t *)fixupContent; break; case GENERIC_RELOC_VANILLA | rPcRel | rLength4: // ex: call _foo (and _foo defined) *kind = branch32; - targetAddress = fixupAddress + 4 + (int32_t)*(little32_t *)fixupContent; + targetAddress = + fixupAddress + 4 + (int32_t) * (const little32_t *)fixupContent; return atomFromAddress(reloc.symbol, targetAddress, target, addend); break; case GENERIC_RELOC_VANILLA | rScattered | rPcRel | rLength4: // ex: call _foo+n (and _foo defined) *kind = branch32; - targetAddress = fixupAddress + 4 + (int32_t)*(little32_t *)fixupContent; + targetAddress = + fixupAddress + 4 + (int32_t) * (const little32_t *)fixupContent; if (E ec = atomFromAddress(0, reloc.value, target, addend)) return ec; *addend = targetAddress - reloc.value; @@ -283,18 +285,20 @@ ArchHandler_x86::getReferenceInfo(const Relocation &reloc, *kind = branch16; if (E ec = atomFromSymbolIndex(reloc.symbol, target)) return ec; - *addend = fixupAddress + 2 + (int16_t)*(little16_t *)fixupContent; + *addend = fixupAddress + 2 + (int16_t)*(const little16_t *)fixupContent; break; case GENERIC_RELOC_VANILLA | rPcRel | rLength2: // ex: callw _foo (and _foo defined) *kind = branch16; - targetAddress = fixupAddress + 2 + (int16_t)*(little16_t *)fixupContent; + targetAddress = + fixupAddress + 2 + (int16_t) * (const little16_t *)fixupContent; return atomFromAddress(reloc.symbol, targetAddress, target, addend); break; case GENERIC_RELOC_VANILLA | rScattered | rPcRel | rLength2: // ex: callw _foo+n (and _foo defined) *kind = branch16; - targetAddress = fixupAddress + 2 + (int16_t)*(little16_t *)fixupContent; + targetAddress = + fixupAddress + 2 + (int16_t) * (const little16_t *)fixupContent; if (E ec = atomFromAddress(0, reloc.value, target, addend)) return ec; *addend = targetAddress - reloc.value; @@ -308,7 +312,7 @@ ArchHandler_x86::getReferenceInfo(const Relocation &reloc, : pointer32; if (E ec = atomFromSymbolIndex(reloc.symbol, target)) return ec; - *addend = *(ulittle32_t *)fixupContent; + *addend = *(const ulittle32_t *)fixupContent; break; case GENERIC_RELOC_VANILLA | rLength4: // ex: movl _foo, %eax (and _foo defined) @@ -317,7 +321,7 @@ ArchHandler_x86::getReferenceInfo(const Relocation &reloc, *kind = ((perms & DefinedAtom::permR_X) == DefinedAtom::permR_X) ? abs32 : pointer32; - targetAddress = *(ulittle32_t *)fixupContent; + targetAddress = *(const ulittle32_t *)fixupContent; return atomFromAddress(reloc.symbol, targetAddress, target, addend); break; case GENERIC_RELOC_VANILLA | rScattered | rLength4: @@ -328,7 +332,7 @@ ArchHandler_x86::getReferenceInfo(const Relocation &reloc, : pointer32; if (E ec = atomFromAddress(0, reloc.value, target, addend)) return ec; - *addend = *(ulittle32_t *)fixupContent - reloc.value; + *addend = *(const ulittle32_t *)fixupContent - reloc.value; break; default: return make_dynamic_error_code(Twine("unsupported i386 relocation type")); @@ -364,7 +368,7 @@ ArchHandler_x86::getPairReferenceInfo(const normalized::Relocation &reloc1, GENERIC_RELOC_PAIR | rScattered | rLength4): toAddress = reloc1.value; fromAddress = reloc2.value; - value = *(little32_t *)fixupContent; + value = *(const little32_t *)fixupContent; ec = atomFromAddr(0, toAddress, target, &offsetInTo); if (ec) return ec; diff --git a/lld/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp b/lld/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp index ccab824..8a9881c 100644 --- a/lld/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp +++ b/lld/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp @@ -340,39 +340,39 @@ ArchHandler_x86_64::getReferenceInfo(const Relocation &reloc, case ripRel32: if (E ec = atomFromSymbolIndex(reloc.symbol, target)) return ec; - *addend = *(little32_t *)fixupContent; + *addend = *(const little32_t *)fixupContent; return std::error_code(); case ripRel32Minus1: if (E ec = atomFromSymbolIndex(reloc.symbol, target)) return ec; - *addend = (int32_t)*(little32_t *)fixupContent + 1; + *addend = (int32_t)*(const little32_t *)fixupContent + 1; return std::error_code(); case ripRel32Minus2: if (E ec = atomFromSymbolIndex(reloc.symbol, target)) return ec; - *addend = (int32_t)*(little32_t *)fixupContent + 2; + *addend = (int32_t)*(const little32_t *)fixupContent + 2; return std::error_code(); case ripRel32Minus4: if (E ec = atomFromSymbolIndex(reloc.symbol, target)) return ec; - *addend = (int32_t)*(little32_t *)fixupContent + 4; + *addend = (int32_t)*(const little32_t *)fixupContent + 4; return std::error_code(); case ripRel32Anon: - targetAddress = fixupAddress + 4 + *(little32_t *)fixupContent; + targetAddress = fixupAddress + 4 + *(const little32_t *)fixupContent; return atomFromAddress(reloc.symbol, targetAddress, target, addend); case ripRel32GotLoad: case ripRel32Got: if (E ec = atomFromSymbolIndex(reloc.symbol, target)) return ec; - *addend = *(little32_t *)fixupContent; + *addend = *(const little32_t *)fixupContent; return std::error_code(); case pointer64: if (E ec = atomFromSymbolIndex(reloc.symbol, target)) return ec; - *addend = *(little64_t *)fixupContent; + *addend = *(const little64_t *)fixupContent; return std::error_code(); case pointer64Anon: - targetAddress = *(little64_t *)fixupContent; + targetAddress = *(const little64_t *)fixupContent; return atomFromAddress(reloc.symbol, targetAddress, target, addend); default: llvm_unreachable("bad reloc kind"); @@ -427,18 +427,18 @@ ArchHandler_x86_64::getPairReferenceInfo(const normalized::Relocation &reloc1, case delta64: if (E ec = atomFromSymbolIndex(reloc2.symbol, target)) return ec; - *addend = (int64_t)*(little64_t *)fixupContent + offsetInAtom; + *addend = (int64_t)*(const little64_t *)fixupContent + offsetInAtom; return std::error_code(); case delta32: if (E ec = atomFromSymbolIndex(reloc2.symbol, target)) return ec; - *addend = (int32_t)*(little32_t *)fixupContent + offsetInAtom; + *addend = (int32_t)*(const little32_t *)fixupContent + offsetInAtom; return std::error_code(); case delta64Anon: - targetAddress = offsetInAtom + (int64_t)*(little64_t *)fixupContent; + targetAddress = offsetInAtom + (int64_t)*(const little64_t *)fixupContent; return atomFromAddress(reloc2.symbol, targetAddress, target, addend); case delta32Anon: - targetAddress = offsetInAtom + (int32_t)*(little32_t *)fixupContent; + targetAddress = offsetInAtom + (int32_t)*(const little32_t *)fixupContent; return atomFromAddress(reloc2.symbol, targetAddress, target, addend); default: llvm_unreachable("bad reloc pair kind"); diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp index 0884d3b..042cca7 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp @@ -300,7 +300,7 @@ readBinary(std::unique_ptr &mb, section.alignment = read32(§->align, isBig); section.address = read64(§->addr, isBig); const uint8_t *content = - (uint8_t *)start + read32(§->offset, isBig); + (const uint8_t *)start + read32(§->offset, isBig); size_t contentSize = read64(§->size, isBig); // Note: this assign() is copying the content bytes. Ideally, // we can use a custom allocator for vector to avoid the copy. @@ -340,11 +340,11 @@ readBinary(std::unique_ptr &mb, section.type = (SectionType)(read32(§->flags, isBig) & SECTION_TYPE); section.attributes = - read32((uint8_t *)§->flags, isBig) & SECTION_ATTRIBUTES; + read32((const uint8_t *)§->flags, isBig) & SECTION_ATTRIBUTES; section.alignment = read32(§->align, isBig); section.address = read32(§->addr, isBig); const uint8_t *content = - (uint8_t *)start + read32(§->offset, isBig); + (const uint8_t *)start + read32(§->offset, isBig); size_t contentSize = read32(§->size, isBig); // Note: this assign() is copying the content bytes. Ideally, // we can use a custom allocator for vector to avoid the copy. @@ -367,8 +367,8 @@ readBinary(std::unique_ptr &mb, const char *strings = start + read32(&st->stroff, isBig); const uint32_t strSize = read32(&st->strsize, isBig); // Validate string pool and symbol table all in buffer. - if (read32((uint8_t *)&st->stroff, isBig) + - read32((uint8_t *)&st->strsize, isBig) > + if (read32((const uint8_t *)&st->stroff, isBig) + + read32((const uint8_t *)&st->strsize, isBig) > objSize) return true; if (is64) { @@ -475,7 +475,7 @@ readBinary(std::unique_ptr &mb, entry.offset = read32(&dataInCode[i].offset, isBig); entry.length = read16(&dataInCode[i].length, isBig); entry.kind = - (DataRegionType)read16((uint8_t *)&dataInCode[i].kind, isBig); + (DataRegionType)read16((const uint8_t *)&dataInCode[i].kind, isBig); f->dataInCode.push_back(entry); } } diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h index fe40ed4..90ad33f 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h @@ -41,8 +41,8 @@ static inline uint16_t read16(const T *loc, bool isBig) { assert((uint64_t)loc % llvm::alignOf() == 0 && "invalid pointer alignment"); if (isBig) - return *(ubig16_t *)loc; - return *(ulittle16_t *)loc; + return *(const ubig16_t *)loc; + return *(const ulittle16_t *)loc; } template @@ -50,8 +50,8 @@ static inline uint32_t read32(const T *loc, bool isBig) { assert((uint64_t)loc % llvm::alignOf() == 0 && "invalid pointer alignment"); if (isBig) - return *(ubig32_t *)loc; - return *(ulittle32_t *)loc; + return *(const ubig32_t *)loc; + return *(const ulittle32_t *)loc; } template @@ -59,8 +59,8 @@ static inline uint64_t read64(const T *loc, bool isBig) { assert((uint64_t)loc % llvm::alignOf() == 0 && "invalid pointer alignment"); if (isBig) - return *(ubig64_t *)loc; - return *(ulittle64_t *)loc; + return *(const ubig64_t *)loc; + return *(const ulittle64_t *)loc; } inline void write16(uint8_t *loc, uint16_t value, bool isBig) { diff --git a/lld/lib/ReaderWriter/PECOFF/EdataPass.h b/lld/lib/ReaderWriter/PECOFF/EdataPass.h index 6f76c96..442be3c 100644 --- a/lld/lib/ReaderWriter/PECOFF/EdataPass.h +++ b/lld/lib/ReaderWriter/PECOFF/EdataPass.h @@ -55,7 +55,7 @@ public: ContentPermissions permissions() const override { return permR__; } template T *getContents() const { - return (T *)rawContent().data(); + return (T *)const_cast(rawContent().data()); } }; diff --git a/lld/lib/ReaderWriter/PECOFF/IdataPass.cpp b/lld/lib/ReaderWriter/PECOFF/IdataPass.cpp index 1357168..83f4c4f 100644 --- a/lld/lib/ReaderWriter/PECOFF/IdataPass.cpp +++ b/lld/lib/ReaderWriter/PECOFF/IdataPass.cpp @@ -314,7 +314,8 @@ std::map > IdataPass::groupByLoadName(MutableFile &file) { std::map uniqueAtoms; for (const SharedLibraryAtom *atom : file.sharedLibrary()) - uniqueAtoms[atom->name()] = (COFFSharedLibraryAtom *)atom; + uniqueAtoms[atom->name()] = + (COFFSharedLibraryAtom *)const_cast(atom); std::map > ret; for (auto i : uniqueAtoms) { @@ -332,7 +333,7 @@ void IdataPass::replaceSharedLibraryAtoms(MutableFile &file) { auto *sharedAtom = dyn_cast(target); if (!sharedAtom) continue; - auto *coffSharedAtom = (COFFSharedLibraryAtom *)sharedAtom; + const auto *coffSharedAtom = (const COFFSharedLibraryAtom *)sharedAtom; const DefinedAtom *entry = coffSharedAtom->getImportTableEntry(); const_cast(ref)->setTarget(entry); } diff --git a/lld/lib/ReaderWriter/PECOFF/LoadConfigPass.h b/lld/lib/ReaderWriter/PECOFF/LoadConfigPass.h index 534d956..9f4a25f 100644 --- a/lld/lib/ReaderWriter/PECOFF/LoadConfigPass.h +++ b/lld/lib/ReaderWriter/PECOFF/LoadConfigPass.h @@ -39,7 +39,7 @@ public: ContentPermissions permissions() const override { return permR__; } template T *getContents() const { - return (T *)rawContent().data(); + return (T *)const_cast(rawContent().data()); } }; diff --git a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp index 5b83f58..f41f978 100644 --- a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp +++ b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp @@ -89,7 +89,7 @@ public: DEBUG_WITH_TYPE("WriterYAML", llvm::dbgs() << "unnamed atom: creating ref-name: '" << newName << "' (" - << (void *)newName.data() << ", " + << (const void *)newName.data() << ", " << newName.size() << ")\n"); } } @@ -118,7 +118,8 @@ public: _refNames[&atom] = newName; DEBUG_WITH_TYPE("WriterYAML", llvm::dbgs() << "name collsion: creating ref-name: '" - << newName << "' (" << (void *)newName.data() + << newName << "' (" + << (const void *)newName.data() << ", " << newName.size() << ")\n"); const lld::Atom *prevAtom = pos->second; AtomToRefName::iterator pos2 = _refNames.find(prevAtom); @@ -132,7 +133,7 @@ public: DEBUG_WITH_TYPE("WriterYAML", llvm::dbgs() << "name collsion: creating ref-name: '" << newName2 << "' (" - << (void *)newName2.data() << ", " + << (const void *)newName2.data() << ", " << newName2.size() << ")\n"); } } else { @@ -141,8 +142,8 @@ public: DEBUG_WITH_TYPE("WriterYAML", llvm::dbgs() << "atom name seen for first time: '" << atom.name() << "' (" - << (void *)atom.name().data() << ", " - << atom.name().size() << ")\n"); + << (const void *)atom.name().data() + << ", " << atom.name().size() << ")\n"); } } @@ -767,8 +768,8 @@ template <> struct MappingTraits { DEBUG_WITH_TYPE("WriterYAML", llvm::dbgs() << "created Reference to name: '" << _targetName << "' (" - << (void *)_targetName.data() << ", " - << _targetName.size() << ")\n"); + << (const void *)_targetName.data() + << ", " << _targetName.size() << ")\n"); setKindNamespace(_mappedKind.ns); setKindArch(_mappedKind.arch); setKindValue(_mappedKind.value); @@ -844,8 +845,8 @@ template <> struct MappingTraits { _sectionName = f->copyString(_sectionName); DEBUG_WITH_TYPE("WriterYAML", llvm::dbgs() << "created DefinedAtom named: '" << _name - << "' (" << (void *)_name.data() << ", " - << _name.size() << ")\n"); + << "' (" << (const void *)_name.data() + << ", " << _name.size() << ")\n"); return this; } void bind(const RefNameResolver &); @@ -996,7 +997,7 @@ template <> struct MappingTraits { DEBUG_WITH_TYPE("WriterYAML", llvm::dbgs() << "created UndefinedAtom named: '" << _name - << "' (" << (void *)_name.data() << ", " + << "' (" << (const void *)_name.data() << ", " << _name.size() << ")\n"); return this; } @@ -1057,7 +1058,8 @@ template <> struct MappingTraits { DEBUG_WITH_TYPE("WriterYAML", llvm::dbgs() << "created SharedLibraryAtom named: '" - << _name << "' (" << (void *)_name.data() + << _name << "' (" + << (const void *)_name.data() << ", " << _name.size() << ")\n"); return this; } @@ -1118,8 +1120,8 @@ template <> struct MappingTraits { DEBUG_WITH_TYPE("WriterYAML", llvm::dbgs() << "created AbsoluteAtom named: '" << _name - << "' (" << (void *)_name.data() << ", " - << _name.size() << ")\n"); + << "' (" << (const void *)_name.data() + << ", " << _name.size() << ")\n"); return this; } // Extract current File object from YAML I/O parsing context @@ -1172,7 +1174,7 @@ RefNameResolver::RefNameResolver(const lld::File *file, IO &io) : _io(io) { typedef MappingTraits::NormalizedAtom NormalizedAtom; for (const lld::DefinedAtom *a : file->defined()) { - NormalizedAtom *na = (NormalizedAtom *)a; + const auto *na = (const NormalizedAtom *)a; if (!na->_refName.empty()) add(na->_refName, a); else if (!na->_name.empty()) @@ -1187,7 +1189,7 @@ RefNameResolver::RefNameResolver(const lld::File *file, IO &io) : _io(io) { typedef MappingTraits::NormalizedAtom NormAbsAtom; for (const lld::AbsoluteAtom *a : file->absolute()) { - NormAbsAtom *na = (NormAbsAtom *)a; + const auto *na = (const NormAbsAtom *)a; if (na->_refName.empty()) add(na->_name, a); else @@ -1203,16 +1205,16 @@ MappingTraits::NormalizedFile::denormalize(IO &io) { RefNameResolver nameResolver(this, io); // Now that all atoms are parsed, references can be bound. for (const lld::DefinedAtom *a : this->defined()) { - NormalizedAtom *normAtom = (NormalizedAtom *)a; + auto *normAtom = (NormalizedAtom *)const_cast(a); normAtom->bind(nameResolver); } - _definedAtoms._atoms.erase(std::remove_if(_definedAtoms._atoms.begin(), - _definedAtoms._atoms.end(), - [](const DefinedAtom *a) { - return ((NormalizedAtom *)a)->isGroupChild(); - }), - _definedAtoms._atoms.end()); + _definedAtoms._atoms.erase( + std::remove_if(_definedAtoms._atoms.begin(), _definedAtoms._atoms.end(), + [](const DefinedAtom *a) { + return ((const NormalizedAtom *)a)->isGroupChild(); + }), + _definedAtoms._atoms.end()); return this; } @@ -1222,7 +1224,7 @@ inline void MappingTraits::NormalizedAtom::bind( typedef MappingTraits::NormalizedReference NormalizedReference; for (const lld::Reference *ref : _references) { - NormalizedReference *normRef = (NormalizedReference *)ref; + auto *normRef = (NormalizedReference *)const_cast(ref); normRef->bind(resolver); } } @@ -1235,7 +1237,7 @@ inline void MappingTraits::NormalizedReference::bind( if (_mappedKind.ns == lld::Reference::KindNamespace::all && _mappedKind.value == lld::Reference::kindGroupChild) { - ((NormalizedAtom *)_target)->setGroupChild(true); + ((NormalizedAtom *)const_cast(_target))->setGroupChild(true); } } -- 2.7.4