forked from OSchip/llvm-project
Make PowerOf2's constructor private.
Ban conversion from integers to PowerOf2 even if explicit to make all places we create PowerOf2 instances visible. llvm-svn: 233243
This commit is contained in:
parent
c3d18f5120
commit
48865ca64d
|
@ -30,10 +30,11 @@ class Reference;
|
||||||
// Once the conversion is done, this class will be removed.
|
// Once the conversion is done, this class will be removed.
|
||||||
class PowerOf2 {
|
class PowerOf2 {
|
||||||
public:
|
public:
|
||||||
explicit PowerOf2(uint16_t v) : _v(v) {}
|
static PowerOf2 create(uint16_t v) { return PowerOf2(v); }
|
||||||
bool operator==(const PowerOf2 &other) const { return _v == other._v; }
|
bool operator==(const PowerOf2 &other) const { return _v == other._v; }
|
||||||
uint16_t get() const { return 1 << _v; }
|
uint16_t get() const { return 1 << _v; }
|
||||||
private:
|
private:
|
||||||
|
explicit PowerOf2(uint16_t v) : _v(v) {}
|
||||||
uint16_t _v;
|
uint16_t _v;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -218,7 +219,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Alignment {
|
struct Alignment {
|
||||||
Alignment(int p2, int m = 0) : powerOf2(p2), modulus(m) {}
|
Alignment(int p2, int m = 0) : powerOf2(PowerOf2::create(p2)), modulus(m) {}
|
||||||
Alignment(PowerOf2 p2, int m = 0) : powerOf2(p2), modulus(m) {}
|
Alignment(PowerOf2 p2, int m = 0) : powerOf2(p2), modulus(m) {}
|
||||||
|
|
||||||
PowerOf2 powerOf2;
|
PowerOf2 powerOf2;
|
||||||
|
|
|
@ -479,7 +479,7 @@ bool DarwinLdDriver::parse(int argc, const char *argv[],
|
||||||
<< alignStr << "' not a valid number\n";
|
<< alignStr << "' not a valid number\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PowerOf2 align2(llvm::countTrailingZeros(alignValue));
|
PowerOf2 align2 = PowerOf2::create(llvm::countTrailingZeros(alignValue));
|
||||||
if (!llvm::isPowerOf2_64(alignValue)) {
|
if (!llvm::isPowerOf2_64(alignValue)) {
|
||||||
diagnostics << "warning: alignment for '-sectalign "
|
diagnostics << "warning: alignment for '-sectalign "
|
||||||
<< segName << " " << sectName
|
<< segName << " " << sectName
|
||||||
|
|
|
@ -108,7 +108,7 @@ LLVM_YAML_STRONG_TYPEDEF(uint32_t, SectionAttr)
|
||||||
/// can support either kind.
|
/// can support either kind.
|
||||||
struct Section {
|
struct Section {
|
||||||
Section() : type(llvm::MachO::S_REGULAR),
|
Section() : type(llvm::MachO::S_REGULAR),
|
||||||
attributes(0), alignment(0), address(0) { }
|
attributes(0), alignment(PowerOf2::create(0)), address(0) { }
|
||||||
|
|
||||||
StringRef segmentName;
|
StringRef segmentName;
|
||||||
StringRef sectionName;
|
StringRef sectionName;
|
||||||
|
|
|
@ -297,7 +297,7 @@ readBinary(std::unique_ptr<MemoryBuffer> &mb,
|
||||||
section.type = (SectionType)(read32(§->flags, isBig) &
|
section.type = (SectionType)(read32(§->flags, isBig) &
|
||||||
SECTION_TYPE);
|
SECTION_TYPE);
|
||||||
section.attributes = read32(§->flags, isBig) & SECTION_ATTRIBUTES;
|
section.attributes = read32(§->flags, isBig) & SECTION_ATTRIBUTES;
|
||||||
section.alignment = PowerOf2(read32(§->align, isBig));
|
section.alignment = PowerOf2::create(read32(§->align, isBig));
|
||||||
section.address = read64(§->addr, isBig);
|
section.address = read64(§->addr, isBig);
|
||||||
const uint8_t *content =
|
const uint8_t *content =
|
||||||
(const uint8_t *)start + read32(§->offset, isBig);
|
(const uint8_t *)start + read32(§->offset, isBig);
|
||||||
|
@ -341,7 +341,7 @@ readBinary(std::unique_ptr<MemoryBuffer> &mb,
|
||||||
SECTION_TYPE);
|
SECTION_TYPE);
|
||||||
section.attributes =
|
section.attributes =
|
||||||
read32((const uint8_t *)§->flags, isBig) & SECTION_ATTRIBUTES;
|
read32((const uint8_t *)§->flags, isBig) & SECTION_ATTRIBUTES;
|
||||||
section.alignment = PowerOf2(read32(§->align, isBig));
|
section.alignment = PowerOf2::create(read32(§->align, isBig));
|
||||||
section.address = read32(§->addr, isBig);
|
section.address = read32(§->addr, isBig);
|
||||||
const uint8_t *content =
|
const uint8_t *content =
|
||||||
(const uint8_t *)start + read32(§->offset, isBig);
|
(const uint8_t *)start + read32(§->offset, isBig);
|
||||||
|
|
|
@ -67,9 +67,9 @@ struct SectionInfo {
|
||||||
SectionInfo::SectionInfo(StringRef sg, StringRef sct, SectionType t,
|
SectionInfo::SectionInfo(StringRef sg, StringRef sct, SectionType t,
|
||||||
const MachOLinkingContext &ctxt, uint32_t attrs)
|
const MachOLinkingContext &ctxt, uint32_t attrs)
|
||||||
: segmentName(sg), sectionName(sct), type(t), attributes(attrs),
|
: segmentName(sg), sectionName(sct), type(t), attributes(attrs),
|
||||||
address(0), size(0), alignment(0),
|
address(0), size(0), alignment(PowerOf2::create(0)),
|
||||||
normalizedSectionIndex(0), finalSectionIndex(0) {
|
normalizedSectionIndex(0), finalSectionIndex(0) {
|
||||||
PowerOf2 align(0);
|
PowerOf2 align = PowerOf2::create(0);
|
||||||
if (ctxt.sectionAligned(segmentName, sectionName, align)) {
|
if (ctxt.sectionAligned(segmentName, sectionName, align)) {
|
||||||
alignment = align;
|
alignment = align;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ struct ScalarTraits<lld::PowerOf2> {
|
||||||
static StringRef input(StringRef scalar, void*, lld::PowerOf2 &result) {
|
static StringRef input(StringRef scalar, void*, lld::PowerOf2 &result) {
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
scalar.getAsInteger(10, value);
|
scalar.getAsInteger(10, value);
|
||||||
result = lld::PowerOf2(value);
|
result = lld::PowerOf2::create(value);
|
||||||
return StringRef();
|
return StringRef();
|
||||||
}
|
}
|
||||||
static bool mustQuote(StringRef) { return false; }
|
static bool mustQuote(StringRef) { return false; }
|
||||||
|
@ -290,7 +290,7 @@ struct MappingTraits<Section> {
|
||||||
io.mapRequired("section", sect.sectionName);
|
io.mapRequired("section", sect.sectionName);
|
||||||
io.mapRequired("type", sect.type);
|
io.mapRequired("type", sect.type);
|
||||||
io.mapOptional("attributes", sect.attributes);
|
io.mapOptional("attributes", sect.attributes);
|
||||||
io.mapOptional("alignment", sect.alignment, lld::PowerOf2(0));
|
io.mapOptional("alignment", sect.alignment, lld::PowerOf2::create(0));
|
||||||
io.mapRequired("address", sect.address);
|
io.mapRequired("address", sect.address);
|
||||||
if (sect.type == llvm::MachO::S_ZEROFILL) {
|
if (sect.type == llvm::MachO::S_ZEROFILL) {
|
||||||
// S_ZEROFILL sections use "size:" instead of "content:"
|
// S_ZEROFILL sections use "size:" instead of "content:"
|
||||||
|
|
|
@ -509,7 +509,7 @@ template <> struct ScalarTraits<lld::DefinedAtom::Alignment> {
|
||||||
if (scalar.getAsInteger(0, power)) {
|
if (scalar.getAsInteger(0, power)) {
|
||||||
return "malformed alignment power";
|
return "malformed alignment power";
|
||||||
}
|
}
|
||||||
value.powerOf2 = PowerOf2(llvm::Log2_64(power));
|
value.powerOf2 = PowerOf2::create(llvm::Log2_64(power));
|
||||||
if (value.modulus >= power) {
|
if (value.modulus >= power) {
|
||||||
return "malformed alignment, modulus too large for power";
|
return "malformed alignment, modulus too large for power";
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ TEST(BinaryWriterTest, obj_relocs_x86_64) {
|
||||||
text.type = S_REGULAR;
|
text.type = S_REGULAR;
|
||||||
text.attributes = SectionAttr(S_ATTR_PURE_INSTRUCTIONS
|
text.attributes = SectionAttr(S_ATTR_PURE_INSTRUCTIONS
|
||||||
| S_ATTR_SOME_INSTRUCTIONS);
|
| S_ATTR_SOME_INSTRUCTIONS);
|
||||||
text.alignment = lld::PowerOf2(4);
|
text.alignment = lld::PowerOf2::create(4);
|
||||||
text.address = 0;
|
text.address = 0;
|
||||||
const uint8_t textBytes[] = {
|
const uint8_t textBytes[] = {
|
||||||
0xe8, 0x00, 0x00, 0x00, 0x00, 0x48, 0x8b, 0x05,
|
0xe8, 0x00, 0x00, 0x00, 0x00, 0x48, 0x8b, 0x05,
|
||||||
|
@ -240,7 +240,7 @@ TEST(BinaryWriterTest, obj_relocs_x86) {
|
||||||
text.type = S_REGULAR;
|
text.type = S_REGULAR;
|
||||||
text.attributes = SectionAttr(S_ATTR_PURE_INSTRUCTIONS
|
text.attributes = SectionAttr(S_ATTR_PURE_INSTRUCTIONS
|
||||||
| S_ATTR_SOME_INSTRUCTIONS);
|
| S_ATTR_SOME_INSTRUCTIONS);
|
||||||
text.alignment = lld::PowerOf2(4);
|
text.alignment = lld::PowerOf2::create(4);
|
||||||
text.address = 0;
|
text.address = 0;
|
||||||
const uint8_t textBytes[] = {
|
const uint8_t textBytes[] = {
|
||||||
0xe8, 0xfb, 0xff, 0xff, 0xff, 0xa1, 0x00, 0x00,
|
0xe8, 0xfb, 0xff, 0xff, 0xff, 0xa1, 0x00, 0x00,
|
||||||
|
@ -350,7 +350,7 @@ TEST(BinaryWriterTest, obj_relocs_armv7) {
|
||||||
text.type = S_REGULAR;
|
text.type = S_REGULAR;
|
||||||
text.attributes = SectionAttr(S_ATTR_PURE_INSTRUCTIONS
|
text.attributes = SectionAttr(S_ATTR_PURE_INSTRUCTIONS
|
||||||
| S_ATTR_SOME_INSTRUCTIONS);
|
| S_ATTR_SOME_INSTRUCTIONS);
|
||||||
text.alignment = lld::PowerOf2(2);
|
text.alignment = lld::PowerOf2::create(2);
|
||||||
text.address = 0;
|
text.address = 0;
|
||||||
const uint8_t textBytes[] = {
|
const uint8_t textBytes[] = {
|
||||||
0xff, 0xf7, 0xfe, 0xef, 0x40, 0xf2, 0x05, 0x01,
|
0xff, 0xf7, 0xfe, 0xef, 0x40, 0xf2, 0x05, 0x01,
|
||||||
|
@ -479,7 +479,7 @@ TEST(BinaryWriterTest, obj_relocs_ppc) {
|
||||||
text.type = S_REGULAR;
|
text.type = S_REGULAR;
|
||||||
text.attributes = SectionAttr(S_ATTR_PURE_INSTRUCTIONS
|
text.attributes = SectionAttr(S_ATTR_PURE_INSTRUCTIONS
|
||||||
| S_ATTR_SOME_INSTRUCTIONS);
|
| S_ATTR_SOME_INSTRUCTIONS);
|
||||||
text.alignment = lld::PowerOf2(2);
|
text.alignment = lld::PowerOf2::create(2);
|
||||||
text.address = 0;
|
text.address = 0;
|
||||||
const uint8_t textBytes[] = {
|
const uint8_t textBytes[] = {
|
||||||
0x48, 0x00, 0x00, 0x01, 0x40, 0x82, 0xff, 0xfc,
|
0x48, 0x00, 0x00, 0x01, 0x40, 0x82, 0xff, 0xfc,
|
||||||
|
|
Loading…
Reference in New Issue