[llvm-commits] [lld] r152565 - in /lld/trunk: lib/Core/YamlReader.cpp tools/lld-core/lld-core.cpp
Michael J. Spencer
bigcheesegs at gmail.com
Mon Mar 12 11:13:37 PDT 2012
Author: mspencer
Date: Mon Mar 12 13:13:36 2012
New Revision: 152565
URL: http://llvm.org/viewvc/llvm-project?rev=152565&view=rev
Log:
Audit uses of StringRef::getAsInteger.
Modified:
lld/trunk/lib/Core/YamlReader.cpp
lld/trunk/tools/lld-core/lld-core.cpp
Modified: lld/trunk/lib/Core/YamlReader.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/YamlReader.cpp?rev=152565&r1=152564&r2=152565&view=diff
==============================================================================
--- lld/trunk/lib/Core/YamlReader.cpp (original)
+++ lld/trunk/lib/Core/YamlReader.cpp Mon Mar 12 13:13:36 2012
@@ -764,13 +764,10 @@
}
void YAMLAtomState::setAlign2(const char *s) {
- llvm::StringRef str(s);
- uint32_t res;
- str.getAsInteger(10, res);
- _alignment.powerOf2 = static_cast<uint16_t>(res);
+ if (llvm::StringRef(s).getAsInteger(10, _alignment.powerOf2))
+ _alignment.powerOf2 = 1;
}
-
void YAMLAtomState::setFixupKind(const char *s) {
_ref._kind = _platform.kindFromString(llvm::StringRef(s));
}
@@ -915,7 +912,7 @@
}
else if (strcmp(entry->key, KeyValues::sizeKeyword) == 0) {
llvm::StringRef val = entry->value;
- if ( val.getAsInteger(0, atomState._size) )
+ if (val.getAsInteger(0, atomState._size))
return make_error_code(yaml_reader_error::illegal_value);
haveAtom = true;
}
@@ -956,9 +953,9 @@
haveFixup = true;
}
else if (strcmp(entry->key, KeyValues::fixupsOffsetKeyword) == 0) {
- llvm::APInt Val;
- llvm::StringRef(entry->value).getAsInteger(0, Val);
- atomState._ref._offsetInAtom = Val.getZExtValue();
+ if (llvm::StringRef(entry->value).getAsInteger(0,
+ atomState._ref._offsetInAtom))
+ return make_error_code(yaml_reader_error::illegal_value);
haveFixup = true;
}
else if (strcmp(entry->key, KeyValues::fixupsTargetKeyword) == 0) {
@@ -966,19 +963,9 @@
haveFixup = true;
}
else if (strcmp(entry->key, KeyValues::fixupsAddendKeyword) == 0) {
- llvm::APInt Val;
- // HACK: getAsInteger for APInt doesn't handle negative values
- // the same as other getAsInteger functions. And getAsInteger
- // doesn't work on all platforms for {,u}int64_t. So manually
- // handle this until getAsInteger is fixed.
- bool IsNeg = false;
llvm::StringRef Addend(entry->value);
- if (Addend.find('-') == 0) {
- IsNeg = true;
- Addend = Addend.substr(1);
- }
- Addend.getAsInteger(0, Val);
- atomState._ref._addend = Val.getSExtValue() * (IsNeg ? -1 : 1);
+ if (Addend.getAsInteger(0, atomState._ref._addend))
+ return make_error_code(yaml_reader_error::illegal_value);
haveFixup = true;
}
}
Modified: lld/trunk/tools/lld-core/lld-core.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/tools/lld-core/lld-core.cpp?rev=152565&r1=152564&r2=152565&view=diff
==============================================================================
--- lld/trunk/tools/lld-core/lld-core.cpp (original)
+++ lld/trunk/tools/lld-core/lld-core.cpp Mon Mar 12 13:13:36 2012
@@ -269,7 +269,8 @@
return p->value;
}
int k;
- kindName.getAsInteger(0, k);
+ if (kindName.getAsInteger(0, k))
+ k = 0;
return k;
}
More information about the llvm-commits
mailing list