<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 13, 2014 at 11:15 PM, Simon Atanasyan <span dir="ltr"><<a href="mailto:simon@atanasyan.com" target="_blank">simon@atanasyan.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: atanasyan<br>
Date: Fri Nov 14 01:15:43 2014<br>
New Revision: 221974<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=221974&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=221974&view=rev</a><br>
Log:<br>
Follow-up to r221913. Fix some -Wcast-qual warning reasons.<br>
<br>
Modified:<br>
lld/trunk/lib/Core/SymbolTable.cpp<br>
lld/trunk/lib/ReaderWriter/ELF/ELFFile.h<br>
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h<br>
lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp<br>
lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp<br>
lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp<br>
lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp<br>
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp<br>
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h<br>
lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.h<br>
lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp<br>
lld/trunk/lib/ReaderWriter/PECOFF/LoadConfigPass.h<br>
lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp<br>
<br>
Modified: lld/trunk/lib/Core/SymbolTable.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/SymbolTable.cpp?rev=221974&r1=221973&r2=221974&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/SymbolTable.cpp?rev=221974&r1=221973&r2=221974&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/Core/SymbolTable.cpp (original)<br>
+++ lld/trunk/lib/Core/SymbolTable.cpp Fri Nov 14 01:15:43 2014<br>
@@ -187,9 +187,10 @@ bool SymbolTable::addByName(const Atom &<br>
case NCR_Second:<br>
useNew = true;<br>
break;<br>
- case NCR_DupDef:<br>
- switch (mergeSelect(cast<DefinedAtom>(existing)->merge(),<br>
- cast<DefinedAtom>(&newAtom)->merge())) {<br>
+ case NCR_DupDef: {<br>
+ const auto *existingDef = cast<DefinedAtom>(existing);<br>
+ const auto *newDef = cast<DefinedAtom>(&newAtom);<br></blockquote><div><br></div><div>These casts should already be safe & could remain as they were before, I believe. the llvm::cast machinery preserves const without having to specify it explicitly.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ switch (mergeSelect(existingDef->merge(), newDef->merge())) {<br>
case MCR_First:<br>
useNew = false;<br>
break;<br>
@@ -197,14 +198,14 @@ bool SymbolTable::addByName(const Atom &<br>
useNew = true;<br>
break;<br>
case MCR_Largest: {<br>
- uint64_t existingSize = sectionSize((DefinedAtom*)existing);<br>
- uint64_t newSize = sectionSize((DefinedAtom*)&newAtom);<br>
+ uint64_t existingSize = sectionSize(existingDef);<br>
+ uint64_t newSize = sectionSize(newDef);<br>
useNew = (newSize >= existingSize);<br>
break;<br>
}<br>
case MCR_SameSize: {<br>
- uint64_t existingSize = sectionSize((DefinedAtom*)existing);<br>
- uint64_t newSize = sectionSize((DefinedAtom*)&newAtom);<br>
+ uint64_t existingSize = sectionSize(existingDef);<br>
+ uint64_t newSize = sectionSize(newDef);<br>
if (existingSize == newSize) {<br>
useNew = true;<br>
break;<br>
@@ -231,6 +232,7 @@ bool SymbolTable::addByName(const Atom &<br>
break;<br>
}<br>
break;<br>
+ }<br>
case NCR_DupUndef: {<br>
const UndefinedAtom* existingUndef = cast<UndefinedAtom>(existing);<br>
const UndefinedAtom* newUndef = cast<UndefinedAtom>(&newAtom);<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFFile.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFFile.h?rev=221974&r1=221973&r2=221974&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFFile.h?rev=221974&r1=221973&r2=221974&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/ELF/ELFFile.h (original)<br>
+++ lld/trunk/lib/ReaderWriter/ELF/ELFFile.h Fri Nov 14 01:15:43 2014<br>
@@ -664,8 +664,9 @@ template <class ELFT> std::error_code EL<br>
}<br>
}<br>
<br>
- ArrayRef<uint8_t> symbolData(<br>
- (uint8_t *)sectionContents->data() + symbol->st_value, contentSize);<br>
+ ArrayRef<uint8_t> symbolData((const uint8_t *)sectionContents->data() +<br>
+ symbol->st_value,<br>
+ contentSize);<br>
<br>
// If the linker finds that a section has global atoms that are in a<br>
// mergeable section, treat them as defined atoms as they shouldn't be<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h?rev=221974&r1=221973&r2=221974&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h?rev=221974&r1=221973&r2=221974&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h (original)<br>
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h Fri Nov 14 01:15:43 2014<br>
@@ -216,9 +216,9 @@ private:<br>
case llvm::ELF::R_MIPS_32:<br>
case llvm::ELF::R_MIPS_GPREL32:<br>
case llvm::ELF::R_MIPS_PC32:<br>
- return *(int32_t *)ap;<br>
+ return *(const int32_t *)ap;<br></blockquote><div><br>This and all casts like it are likely UB (if the underlying pointer is just pointing to bytes, not an actual int32_t object) and we should be using our utility functions (I forget where they are or what they're called) that can read from bytes into ints, etc (using memcpy, the blessed way to do this in a well defined manner).<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
case llvm::ELF::R_MIPS_26:<br>
- return *(int32_t *)ap & 0x3ffffff;<br>
+ return *(const int32_t *)ap & 0x3ffffff;<br>
case llvm::ELF::R_MIPS_HI16:<br>
case llvm::ELF::R_MIPS_LO16:<br>
case llvm::ELF::R_MIPS_GOT16:<br>
@@ -226,7 +226,7 @@ private:<br>
case llvm::ELF::R_MIPS_TLS_DTPREL_LO16:<br>
case llvm::ELF::R_MIPS_TLS_TPREL_HI16:<br>
case llvm::ELF::R_MIPS_TLS_TPREL_LO16:<br>
- return *(int16_t *)ap;<br>
+ return *(const int16_t *)ap;<br>
case llvm::ELF::R_MIPS_CALL16:<br>
case llvm::ELF::R_MIPS_TLS_GD:<br>
case llvm::ELF::R_MIPS_TLS_LDM:<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp?rev=221974&r1=221973&r2=221974&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp?rev=221974&r1=221973&r2=221974&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp (original)<br>
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp Fri Nov 14 01:15:43 2014<br>
@@ -521,7 +521,7 @@ std::error_code ArchHandler_arm::getRefe<br>
typedef std::error_code E;<br>
const uint8_t *fixupContent = &inAtom->rawContent()[offsetInAtom];<br>
uint64_t targetAddress;<br>
- uint32_t instruction = *(ulittle32_t *)fixupContent;<br>
+ uint32_t instruction = *(const ulittle32_t *)fixupContent;<br>
int32_t displacement;<br>
switch (relocPattern(reloc)) {<br>
case ARM_THUMB_RELOC_BR22 | rPcRel | rExtern | rLength4:<br>
@@ -781,7 +781,7 @@ ArchHandler_arm::getPairReferenceInfo(co<br>
}<br>
const uint8_t *fixupContent = &inAtom->rawContent()[offsetInAtom];<br>
std::error_code ec;<br>
- uint32_t instruction = *(ulittle32_t *)fixupContent;<br>
+ uint32_t instruction = *(const ulittle32_t *)fixupContent;<br>
uint32_t value;<br>
uint32_t fromAddress;<br>
uint32_t toAddress;<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp?rev=221974&r1=221973&r2=221974&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp?rev=221974&r1=221973&r2=221974&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp (original)<br>
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp Fri Nov 14 01:15:43 2014<br>
@@ -360,7 +360,7 @@ std::error_code ArchHandler_arm64::getRe<br>
return std::error_code();<br>
case ARM64_RELOC_PAGEOFF12 | rExtern | rLength4:<br>
// ex: ldr x0, [x1, _foo@PAGEOFF]<br>
- *kind = offset12KindFromInstruction(*(little32_t *)fixupContent);<br>
+ *kind = offset12KindFromInstruction(*(const little32_t *)fixupContent);<br>
if (auto ec = atomFromSymbolIndex(reloc.symbol, target))<br>
return ec;<br>
*addend = 0;<br>
@@ -398,7 +398,7 @@ std::error_code ArchHandler_arm64::getRe<br>
*kind = pointer64;<br>
if (auto ec = atomFromSymbolIndex(reloc.symbol, target))<br>
return ec;<br>
- *addend = *(little64_t *)fixupContent;<br>
+ *addend = *(const little64_t *)fixupContent;<br>
return std::error_code();<br>
case ARM64_RELOC_POINTER_TO_GOT | rExtern | rLength8:<br>
// ex: .quad _foo@GOT<br>
@@ -458,7 +458,7 @@ std::error_code ArchHandler_arm64::getPa<br>
*kind = delta64;<br>
if (auto ec = atomFromSymbolIndex(reloc2.symbol, target))<br>
return ec;<br>
- *addend = (int64_t)*(little64_t *)fixupContent + offsetInAtom;<br>
+ *addend = (int64_t)*(const little64_t *)fixupContent + offsetInAtom;<br>
return std::error_code();<br>
case ((ARM64_RELOC_SUBTRACTOR | rExtern | rLength4) << 16 |<br>
ARM64_RELOC_UNSIGNED | rExtern | rLength4):<br>
@@ -466,7 +466,7 @@ std::error_code ArchHandler_arm64::getPa<br>
*kind = delta32;<br>
if (auto ec = atomFromSymbolIndex(reloc2.symbol, target))<br>
return ec;<br>
- *addend = (int32_t)*(little32_t *)fixupContent + offsetInAtom;<br>
+ *addend = (int32_t)*(const little32_t *)fixupContent + offsetInAtom;<br>
return std::error_code();<br>
default:<br>
return make_dynamic_error_code(Twine("unsupported arm64 relocation pair"));<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp?rev=221974&r1=221973&r2=221974&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp?rev=221974&r1=221973&r2=221974&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp (original)<br>
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp Fri Nov 14 01:15:43 2014<br>
@@ -262,18 +262,20 @@ ArchHandler_x86::getReferenceInfo(const<br>
*kind = branch32;<br>
if (E ec = atomFromSymbolIndex(reloc.symbol, target))<br>
return ec;<br>
- *addend = fixupAddress + 4 + (int32_t)*(little32_t *)fixupContent;<br>
+ *addend = fixupAddress + 4 + (int32_t)*(const little32_t *)fixupContent;<br>
break;<br>
case GENERIC_RELOC_VANILLA | rPcRel | rLength4:<br>
// ex: call _foo (and _foo defined)<br>
*kind = branch32;<br>
- targetAddress = fixupAddress + 4 + (int32_t)*(little32_t *)fixupContent;<br>
+ targetAddress =<br>
+ fixupAddress + 4 + (int32_t) * (const little32_t *)fixupContent;<br>
return atomFromAddress(reloc.symbol, targetAddress, target, addend);<br>
break;<br>
case GENERIC_RELOC_VANILLA | rScattered | rPcRel | rLength4:<br>
// ex: call _foo+n (and _foo defined)<br>
*kind = branch32;<br>
- targetAddress = fixupAddress + 4 + (int32_t)*(little32_t *)fixupContent;<br>
+ targetAddress =<br>
+ fixupAddress + 4 + (int32_t) * (const little32_t *)fixupContent;<br>
if (E ec = atomFromAddress(0, reloc.value, target, addend))<br>
return ec;<br>
*addend = targetAddress - reloc.value;<br>
@@ -283,18 +285,20 @@ ArchHandler_x86::getReferenceInfo(const<br>
*kind = branch16;<br>
if (E ec = atomFromSymbolIndex(reloc.symbol, target))<br>
return ec;<br>
- *addend = fixupAddress + 2 + (int16_t)*(little16_t *)fixupContent;<br>
+ *addend = fixupAddress + 2 + (int16_t)*(const little16_t *)fixupContent;<br>
break;<br>
case GENERIC_RELOC_VANILLA | rPcRel | rLength2:<br>
// ex: callw _foo (and _foo defined)<br>
*kind = branch16;<br>
- targetAddress = fixupAddress + 2 + (int16_t)*(little16_t *)fixupContent;<br>
+ targetAddress =<br>
+ fixupAddress + 2 + (int16_t) * (const little16_t *)fixupContent;<br>
return atomFromAddress(reloc.symbol, targetAddress, target, addend);<br>
break;<br>
case GENERIC_RELOC_VANILLA | rScattered | rPcRel | rLength2:<br>
// ex: callw _foo+n (and _foo defined)<br>
*kind = branch16;<br>
- targetAddress = fixupAddress + 2 + (int16_t)*(little16_t *)fixupContent;<br>
+ targetAddress =<br>
+ fixupAddress + 2 + (int16_t) * (const little16_t *)fixupContent;<br>
if (E ec = atomFromAddress(0, reloc.value, target, addend))<br>
return ec;<br>
*addend = targetAddress - reloc.value;<br>
@@ -308,7 +312,7 @@ ArchHandler_x86::getReferenceInfo(const<br>
: pointer32;<br>
if (E ec = atomFromSymbolIndex(reloc.symbol, target))<br>
return ec;<br>
- *addend = *(ulittle32_t *)fixupContent;<br>
+ *addend = *(const ulittle32_t *)fixupContent;<br>
break;<br>
case GENERIC_RELOC_VANILLA | rLength4:<br>
// ex: movl _foo, %eax (and _foo defined)<br>
@@ -317,7 +321,7 @@ ArchHandler_x86::getReferenceInfo(const<br>
*kind =<br>
((perms & DefinedAtom::permR_X) == DefinedAtom::permR_X) ? abs32<br>
: pointer32;<br>
- targetAddress = *(ulittle32_t *)fixupContent;<br>
+ targetAddress = *(const ulittle32_t *)fixupContent;<br>
return atomFromAddress(reloc.symbol, targetAddress, target, addend);<br>
break;<br>
case GENERIC_RELOC_VANILLA | rScattered | rLength4:<br>
@@ -328,7 +332,7 @@ ArchHandler_x86::getReferenceInfo(const<br>
: pointer32;<br>
if (E ec = atomFromAddress(0, reloc.value, target, addend))<br>
return ec;<br>
- *addend = *(ulittle32_t *)fixupContent - reloc.value;<br>
+ *addend = *(const ulittle32_t *)fixupContent - reloc.value;<br>
break;<br>
default:<br>
return make_dynamic_error_code(Twine("unsupported i386 relocation type"));<br>
@@ -364,7 +368,7 @@ ArchHandler_x86::getPairReferenceInfo(co<br>
GENERIC_RELOC_PAIR | rScattered | rLength4):<br>
toAddress = reloc1.value;<br>
fromAddress = reloc2.value;<br>
- value = *(little32_t *)fixupContent;<br>
+ value = *(const little32_t *)fixupContent;<br>
ec = atomFromAddr(0, toAddress, target, &offsetInTo);<br>
if (ec)<br>
return ec;<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp?rev=221974&r1=221973&r2=221974&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp?rev=221974&r1=221973&r2=221974&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp (original)<br>
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp Fri Nov 14 01:15:43 2014<br>
@@ -340,39 +340,39 @@ ArchHandler_x86_64::getReferenceInfo(con<br>
case ripRel32:<br>
if (E ec = atomFromSymbolIndex(reloc.symbol, target))<br>
return ec;<br>
- *addend = *(little32_t *)fixupContent;<br>
+ *addend = *(const little32_t *)fixupContent;<br>
return std::error_code();<br>
case ripRel32Minus1:<br>
if (E ec = atomFromSymbolIndex(reloc.symbol, target))<br>
return ec;<br>
- *addend = (int32_t)*(little32_t *)fixupContent + 1;<br>
+ *addend = (int32_t)*(const little32_t *)fixupContent + 1;<br>
return std::error_code();<br>
case ripRel32Minus2:<br>
if (E ec = atomFromSymbolIndex(reloc.symbol, target))<br>
return ec;<br>
- *addend = (int32_t)*(little32_t *)fixupContent + 2;<br>
+ *addend = (int32_t)*(const little32_t *)fixupContent + 2;<br>
return std::error_code();<br>
case ripRel32Minus4:<br>
if (E ec = atomFromSymbolIndex(reloc.symbol, target))<br>
return ec;<br>
- *addend = (int32_t)*(little32_t *)fixupContent + 4;<br>
+ *addend = (int32_t)*(const little32_t *)fixupContent + 4;<br>
return std::error_code();<br>
case ripRel32Anon:<br>
- targetAddress = fixupAddress + 4 + *(little32_t *)fixupContent;<br>
+ targetAddress = fixupAddress + 4 + *(const little32_t *)fixupContent;<br>
return atomFromAddress(reloc.symbol, targetAddress, target, addend);<br>
case ripRel32GotLoad:<br>
case ripRel32Got:<br>
if (E ec = atomFromSymbolIndex(reloc.symbol, target))<br>
return ec;<br>
- *addend = *(little32_t *)fixupContent;<br>
+ *addend = *(const little32_t *)fixupContent;<br>
return std::error_code();<br>
case pointer64:<br>
if (E ec = atomFromSymbolIndex(reloc.symbol, target))<br>
return ec;<br>
- *addend = *(little64_t *)fixupContent;<br>
+ *addend = *(const little64_t *)fixupContent;<br>
return std::error_code();<br>
case pointer64Anon:<br>
- targetAddress = *(little64_t *)fixupContent;<br>
+ targetAddress = *(const little64_t *)fixupContent;<br>
return atomFromAddress(reloc.symbol, targetAddress, target, addend);<br>
default:<br>
llvm_unreachable("bad reloc kind");<br>
@@ -427,18 +427,18 @@ ArchHandler_x86_64::getPairReferenceInfo<br>
case delta64:<br>
if (E ec = atomFromSymbolIndex(reloc2.symbol, target))<br>
return ec;<br>
- *addend = (int64_t)*(little64_t *)fixupContent + offsetInAtom;<br>
+ *addend = (int64_t)*(const little64_t *)fixupContent + offsetInAtom;<br>
return std::error_code();<br>
case delta32:<br>
if (E ec = atomFromSymbolIndex(reloc2.symbol, target))<br>
return ec;<br>
- *addend = (int32_t)*(little32_t *)fixupContent + offsetInAtom;<br>
+ *addend = (int32_t)*(const little32_t *)fixupContent + offsetInAtom;<br>
return std::error_code();<br>
case delta64Anon:<br>
- targetAddress = offsetInAtom + (int64_t)*(little64_t *)fixupContent;<br>
+ targetAddress = offsetInAtom + (int64_t)*(const little64_t *)fixupContent;<br>
return atomFromAddress(reloc2.symbol, targetAddress, target, addend);<br>
case delta32Anon:<br>
- targetAddress = offsetInAtom + (int32_t)*(little32_t *)fixupContent;<br>
+ targetAddress = offsetInAtom + (int32_t)*(const little32_t *)fixupContent;<br>
return atomFromAddress(reloc2.symbol, targetAddress, target, addend);<br>
default:<br>
llvm_unreachable("bad reloc pair kind");<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp?rev=221974&r1=221973&r2=221974&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp?rev=221974&r1=221973&r2=221974&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp (original)<br>
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp Fri Nov 14 01:15:43 2014<br>
@@ -300,7 +300,7 @@ readBinary(std::unique_ptr<MemoryBuffer><br>
section.alignment = read32(§->align, isBig);<br>
section.address = read64(§->addr, isBig);<br>
const uint8_t *content =<br>
- (uint8_t *)start + read32(§->offset, isBig);<br>
+ (const uint8_t *)start + read32(§->offset, isBig);<br>
size_t contentSize = read64(§->size, isBig);<br>
// Note: this assign() is copying the content bytes. Ideally,<br>
// we can use a custom allocator for vector to avoid the copy.<br>
@@ -340,11 +340,11 @@ readBinary(std::unique_ptr<MemoryBuffer><br>
section.type = (SectionType)(read32(§->flags, isBig) &<br>
SECTION_TYPE);<br>
section.attributes =<br>
- read32((uint8_t *)§->flags, isBig) & SECTION_ATTRIBUTES;<br>
+ read32((const uint8_t *)§->flags, isBig) & SECTION_ATTRIBUTES;<br>
section.alignment = read32(§->align, isBig);<br>
section.address = read32(§->addr, isBig);<br>
const uint8_t *content =<br>
- (uint8_t *)start + read32(§->offset, isBig);<br>
+ (const uint8_t *)start + read32(§->offset, isBig);<br>
size_t contentSize = read32(§->size, isBig);<br>
// Note: this assign() is copying the content bytes. Ideally,<br>
// we can use a custom allocator for vector to avoid the copy.<br>
@@ -367,8 +367,8 @@ readBinary(std::unique_ptr<MemoryBuffer><br>
const char *strings = start + read32(&st->stroff, isBig);<br>
const uint32_t strSize = read32(&st->strsize, isBig);<br>
// Validate string pool and symbol table all in buffer.<br>
- if (read32((uint8_t *)&st->stroff, isBig) +<br>
- read32((uint8_t *)&st->strsize, isBig) ><br>
+ if (read32((const uint8_t *)&st->stroff, isBig) +<br>
+ read32((const uint8_t *)&st->strsize, isBig) ><br>
objSize)<br>
return true;<br>
if (is64) {<br>
@@ -475,7 +475,7 @@ readBinary(std::unique_ptr<MemoryBuffer><br>
entry.offset = read32(&dataInCode[i].offset, isBig);<br>
entry.length = read16(&dataInCode[i].length, isBig);<br>
entry.kind =<br>
- (DataRegionType)read16((uint8_t *)&dataInCode[i].kind, isBig);<br>
+ (DataRegionType)read16((const uint8_t *)&dataInCode[i].kind, isBig);<br>
f->dataInCode.push_back(entry);<br>
}<br>
}<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h?rev=221974&r1=221973&r2=221974&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h?rev=221974&r1=221973&r2=221974&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h (original)<br>
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h Fri Nov 14 01:15:43 2014<br>
@@ -41,8 +41,8 @@ static inline uint16_t read16(const T *l<br>
assert((uint64_t)loc % llvm::alignOf<T>() == 0 &&<br>
"invalid pointer alignment");<br>
if (isBig)<br>
- return *(ubig16_t *)loc;<br>
- return *(ulittle16_t *)loc;<br>
+ return *(const ubig16_t *)loc;<br>
+ return *(const ulittle16_t *)loc;<br>
}<br>
<br>
template<typename T><br>
@@ -50,8 +50,8 @@ static inline uint32_t read32(const T *l<br>
assert((uint64_t)loc % llvm::alignOf<T>() == 0 &&<br>
"invalid pointer alignment");<br>
if (isBig)<br>
- return *(ubig32_t *)loc;<br>
- return *(ulittle32_t *)loc;<br>
+ return *(const ubig32_t *)loc;<br>
+ return *(const ulittle32_t *)loc;<br>
}<br>
<br>
template<typename T><br>
@@ -59,8 +59,8 @@ static inline uint64_t read64(const T *l<br>
assert((uint64_t)loc % llvm::alignOf<T>() == 0 &&<br>
"invalid pointer alignment");<br>
if (isBig)<br>
- return *(ubig64_t *)loc;<br>
- return *(ulittle64_t *)loc;<br>
+ return *(const ubig64_t *)loc;<br>
+ return *(const ulittle64_t *)loc;<br>
}<br>
<br>
inline void write16(uint8_t *loc, uint16_t value, bool isBig) {<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.h?rev=221974&r1=221973&r2=221974&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.h?rev=221974&r1=221973&r2=221974&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.h (original)<br>
+++ lld/trunk/lib/ReaderWriter/PECOFF/EdataPass.h Fri Nov 14 01:15:43 2014<br>
@@ -55,7 +55,7 @@ public:<br>
ContentPermissions permissions() const override { return permR__; }<br>
<br>
template <typename T> T *getContents() const {<br>
- return (T *)rawContent().data();<br>
+ return (T *)const_cast<uint8_t *>(rawContent().data());<br>
}<br>
};<br>
<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp?rev=221974&r1=221973&r2=221974&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp?rev=221974&r1=221973&r2=221974&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp (original)<br>
+++ lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp Fri Nov 14 01:15:43 2014<br>
@@ -314,7 +314,8 @@ std::map<StringRef, std::vector<COFFShar<br>
IdataPass::groupByLoadName(MutableFile &file) {<br>
std::map<StringRef, COFFSharedLibraryAtom *> uniqueAtoms;<br>
for (const SharedLibraryAtom *atom : file.sharedLibrary())<br>
- uniqueAtoms[atom->name()] = (COFFSharedLibraryAtom *)atom;<br>
+ uniqueAtoms[atom->name()] =<br>
+ (COFFSharedLibraryAtom *)const_cast<SharedLibraryAtom *>(atom);<br>
<br>
std::map<StringRef, std::vector<COFFSharedLibraryAtom *> > ret;<br>
for (auto i : uniqueAtoms) {<br>
@@ -332,7 +333,7 @@ void IdataPass::replaceSharedLibraryAtom<br>
auto *sharedAtom = dyn_cast<SharedLibraryAtom>(target);<br>
if (!sharedAtom)<br>
continue;<br>
- auto *coffSharedAtom = (COFFSharedLibraryAtom *)sharedAtom;<br>
+ const auto *coffSharedAtom = (const COFFSharedLibraryAtom *)sharedAtom;<br>
const DefinedAtom *entry = coffSharedAtom->getImportTableEntry();<br>
const_cast<Reference *>(ref)->setTarget(entry);<br>
}<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/PECOFF/LoadConfigPass.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/LoadConfigPass.h?rev=221974&r1=221973&r2=221974&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/LoadConfigPass.h?rev=221974&r1=221973&r2=221974&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/PECOFF/LoadConfigPass.h (original)<br>
+++ lld/trunk/lib/ReaderWriter/PECOFF/LoadConfigPass.h Fri Nov 14 01:15:43 2014<br>
@@ -39,7 +39,7 @@ public:<br>
ContentPermissions permissions() const override { return permR__; }<br>
<br>
template <typename T> T *getContents() const {<br>
- return (T *)rawContent().data();<br>
+ return (T *)const_cast<uint8_t *>(rawContent().data());<br>
}<br>
};<br>
<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=221974&r1=221973&r2=221974&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=221974&r1=221973&r2=221974&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp (original)<br>
+++ lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp Fri Nov 14 01:15:43 2014<br>
@@ -89,7 +89,7 @@ public:<br>
DEBUG_WITH_TYPE("WriterYAML",<br>
llvm::dbgs() << "unnamed atom: creating ref-name: '"<br>
<< newName << "' ("<br>
- << (void *)newName.data() << ", "<br>
+ << (const void *)newName.data() << ", "<br>
<< newName.size() << ")\n");<br>
}<br>
}<br>
@@ -118,7 +118,8 @@ public:<br>
_refNames[&atom] = newName;<br>
DEBUG_WITH_TYPE("WriterYAML",<br>
llvm::dbgs() << "name collsion: creating ref-name: '"<br>
- << newName << "' (" << (void *)newName.data()<br>
+ << newName << "' ("<br>
+ << (const void *)newName.data()<br>
<< ", " << newName.size() << ")\n");<br>
const lld::Atom *prevAtom = pos->second;<br>
AtomToRefName::iterator pos2 = _refNames.find(prevAtom);<br>
@@ -132,7 +133,7 @@ public:<br>
DEBUG_WITH_TYPE("WriterYAML",<br>
llvm::dbgs() << "name collsion: creating ref-name: '"<br>
<< newName2 << "' ("<br>
- << (void *)newName2.data() << ", "<br>
+ << (const void *)newName2.data() << ", "<br>
<< newName2.size() << ")\n");<br>
}<br>
} else {<br>
@@ -141,8 +142,8 @@ public:<br>
DEBUG_WITH_TYPE("WriterYAML", llvm::dbgs()<br>
<< "atom name seen for first time: '"<br>
<< <a href="http://atom.name" target="_blank">atom.name</a>() << "' ("<br>
- << (void *)<a href="http://atom.name" target="_blank">atom.name</a>().data() << ", "<br>
- << <a href="http://atom.name" target="_blank">atom.name</a>().size() << ")\n");<br>
+ << (const void *)<a href="http://atom.name" target="_blank">atom.name</a>().data()<br>
+ << ", " << <a href="http://atom.name" target="_blank">atom.name</a>().size() << ")\n");<br>
}<br>
}<br>
<br>
@@ -767,8 +768,8 @@ template <> struct MappingTraits<const l<br>
DEBUG_WITH_TYPE("WriterYAML", llvm::dbgs()<br>
<< "created Reference to name: '"<br>
<< _targetName << "' ("<br>
- << (void *)_targetName.data() << ", "<br>
- << _targetName.size() << ")\n");<br>
+ << (const void *)_targetName.data()<br>
+ << ", " << _targetName.size() << ")\n");<br>
setKindNamespace(_mappedKind.ns);<br>
setKindArch(_mappedKind.arch);<br>
setKindValue(_mappedKind.value);<br>
@@ -844,8 +845,8 @@ template <> struct MappingTraits<const l<br>
_sectionName = f->copyString(_sectionName);<br>
DEBUG_WITH_TYPE("WriterYAML",<br>
llvm::dbgs() << "created DefinedAtom named: '" << _name<br>
- << "' (" << (void *)_name.data() << ", "<br>
- << _name.size() << ")\n");<br>
+ << "' (" << (const void *)_name.data()<br>
+ << ", " << _name.size() << ")\n");<br>
return this;<br>
}<br>
void bind(const RefNameResolver &);<br>
@@ -996,7 +997,7 @@ template <> struct MappingTraits<const l<br>
<br>
DEBUG_WITH_TYPE("WriterYAML",<br>
llvm::dbgs() << "created UndefinedAtom named: '" << _name<br>
- << "' (" << (void *)_name.data() << ", "<br>
+ << "' (" << (const void *)_name.data() << ", "<br>
<< _name.size() << ")\n");<br>
return this;<br>
}<br>
@@ -1057,7 +1058,8 @@ template <> struct MappingTraits<const l<br>
<br>
DEBUG_WITH_TYPE("WriterYAML",<br>
llvm::dbgs() << "created SharedLibraryAtom named: '"<br>
- << _name << "' (" << (void *)_name.data()<br>
+ << _name << "' ("<br>
+ << (const void *)_name.data()<br>
<< ", " << _name.size() << ")\n");<br>
return this;<br>
}<br>
@@ -1118,8 +1120,8 @@ template <> struct MappingTraits<const l<br>
<br>
DEBUG_WITH_TYPE("WriterYAML",<br>
llvm::dbgs() << "created AbsoluteAtom named: '" << _name<br>
- << "' (" << (void *)_name.data() << ", "<br>
- << _name.size() << ")\n");<br>
+ << "' (" << (const void *)_name.data()<br>
+ << ", " << _name.size() << ")\n");<br>
return this;<br>
}<br>
// Extract current File object from YAML I/O parsing context<br>
@@ -1172,7 +1174,7 @@ RefNameResolver::RefNameResolver(const l<br>
typedef MappingTraits<const lld::DefinedAtom *>::NormalizedAtom<br>
NormalizedAtom;<br>
for (const lld::DefinedAtom *a : file->defined()) {<br>
- NormalizedAtom *na = (NormalizedAtom *)a;<br>
+ const auto *na = (const NormalizedAtom *)a;<br>
if (!na->_refName.empty())<br>
add(na->_refName, a);<br>
else if (!na->_name.empty())<br>
@@ -1187,7 +1189,7 @@ RefNameResolver::RefNameResolver(const l<br>
<br>
typedef MappingTraits<const lld::AbsoluteAtom *>::NormalizedAtom NormAbsAtom;<br>
for (const lld::AbsoluteAtom *a : file->absolute()) {<br>
- NormAbsAtom *na = (NormAbsAtom *)a;<br>
+ const auto *na = (const NormAbsAtom *)a;<br>
if (na->_refName.empty())<br>
add(na->_name, a);<br>
else<br>
@@ -1203,16 +1205,16 @@ MappingTraits<const lld::File *>::Normal<br>
RefNameResolver nameResolver(this, io);<br>
// Now that all atoms are parsed, references can be bound.<br>
for (const lld::DefinedAtom *a : this->defined()) {<br>
- NormalizedAtom *normAtom = (NormalizedAtom *)a;<br>
+ auto *normAtom = (NormalizedAtom *)const_cast<DefinedAtom *>(a);<br>
normAtom->bind(nameResolver);<br>
}<br>
<br>
- _definedAtoms._atoms.erase(std::remove_if(_definedAtoms._atoms.begin(),<br>
- _definedAtoms._atoms.end(),<br>
- [](const DefinedAtom *a) {<br>
- return ((NormalizedAtom *)a)->isGroupChild();<br>
- }),<br>
- _definedAtoms._atoms.end());<br>
+ _definedAtoms._atoms.erase(<br>
+ std::remove_if(_definedAtoms._atoms.begin(), _definedAtoms._atoms.end(),<br>
+ [](const DefinedAtom *a) {<br>
+ return ((const NormalizedAtom *)a)->isGroupChild();<br>
+ }),<br>
+ _definedAtoms._atoms.end());<br>
<br>
return this;<br>
}<br>
@@ -1222,7 +1224,7 @@ inline void MappingTraits<const lld::Def<br>
typedef MappingTraits<const lld::Reference *>::NormalizedReference<br>
NormalizedReference;<br>
for (const lld::Reference *ref : _references) {<br>
- NormalizedReference *normRef = (NormalizedReference *)ref;<br>
+ auto *normRef = (NormalizedReference *)const_cast<Reference *>(ref);<br>
normRef->bind(resolver);<br>
}<br>
}<br>
@@ -1235,7 +1237,7 @@ inline void MappingTraits<const lld::Ref<br>
<br>
if (_mappedKind.ns == lld::Reference::KindNamespace::all &&<br>
_mappedKind.value == lld::Reference::kindGroupChild) {<br>
- ((NormalizedAtom *)_target)->setGroupChild(true);<br>
+ ((NormalizedAtom *)const_cast<Atom *>(_target))->setGroupChild(true);<br>
}<br>
}<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>