[lld] r303149 - [ELF] - Use llvm::to_integer() instead of StringRef::getAsInteger().

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue May 16 01:19:27 PDT 2017


Author: grimar
Date: Tue May 16 03:19:25 2017
New Revision: 303149

URL: http://llvm.org/viewvc/llvm-project?rev=303149&view=rev
Log:
[ELF] - Use llvm::to_integer() instead of StringRef::getAsInteger().

Switch to llvm::to_integer() everywhere in LLD instead of 
StringRef::getAsInteger() because API of latter is confusing. 
It returns true on error and false otherwise what makes reading 
the code incomfortable.

Differential revision: https://reviews.llvm.org/D33187

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/ScriptParser.cpp
    lld/trunk/ELF/Strings.cpp
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=303149&r1=303148&r2=303149&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Tue May 16 03:19:25 2017
@@ -284,7 +284,7 @@ static int getInteger(opt::InputArgList
   int V = Default;
   if (auto *Arg = Args.getLastArg(Key)) {
     StringRef S = Arg->getValue();
-    if (S.getAsInteger(10, V))
+    if (!to_integer(S, V, 10))
       error(Arg->getSpelling() + ": number expected, but got " + S);
   }
   return V;
@@ -311,7 +311,7 @@ static uint64_t getZOptionValue(opt::Inp
     if (Pos != StringRef::npos && Key == Value.substr(0, Pos)) {
       Value = Value.substr(Pos + 1);
       uint64_t Result;
-      if (Value.getAsInteger(0, Result))
+      if (!to_integer(Value, Result))
         error("invalid " + Key + ": " + Value);
       return Result;
     }
@@ -522,7 +522,7 @@ static uint64_t parseSectionAddress(Stri
   uint64_t VA = 0;
   if (S.startswith("0x"))
     S = S.drop_front(2);
-  if (S.getAsInteger(16, VA))
+  if (!to_integer(S, VA, 16))
     error("invalid argument: " + toString(Arg));
   return VA;
 }
@@ -886,7 +886,7 @@ static uint64_t getImageBase(opt::InputA
 
   StringRef S = Arg->getValue();
   uint64_t V;
-  if (S.getAsInteger(0, V)) {
+  if (!to_integer(S, V)) {
     error("-image-base: number expected, but got " + S);
     return 0;
   }

Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=303149&r1=303148&r2=303149&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Tue May 16 03:19:25 2017
@@ -639,7 +639,7 @@ ScriptParser::readOutputSectionDescripti
 // We are compatible with ld.gold because it's easier to implement.
 uint32_t ScriptParser::parseFill(StringRef Tok) {
   uint32_t V = 0;
-  if (Tok.getAsInteger(0, V))
+  if (!to_integer(Tok, V))
     setError("invalid filler expression: " + Tok);
 
   uint32_t Buf;
@@ -778,23 +778,23 @@ static Optional<uint64_t> parseInt(Strin
 
   // Hexadecimal
   uint64_t Val;
-  if (Tok.startswith_lower("0x") && !Tok.substr(2).getAsInteger(16, Val))
+  if (Tok.startswith_lower("0x") && to_integer(Tok.substr(2), Val, 16))
     return Val;
-  if (Tok.endswith_lower("H") && !Tok.drop_back().getAsInteger(16, Val))
+  if (Tok.endswith_lower("H") && to_integer(Tok.drop_back(), Val, 16))
     return Val;
 
   // Decimal
   if (Tok.endswith_lower("K")) {
-    if (Tok.drop_back().getAsInteger(10, Val))
+    if (!to_integer(Tok.drop_back(), Val, 10))
       return None;
     return Val * 1024;
   }
   if (Tok.endswith_lower("M")) {
-    if (Tok.drop_back().getAsInteger(10, Val))
+    if (!to_integer(Tok.drop_back(), Val, 10))
       return None;
     return Val * 1024 * 1024;
   }
-  if (Tok.getAsInteger(10, Val))
+  if (!to_integer(Tok, Val, 10))
     return None;
   return Val;
 }

Modified: lld/trunk/ELF/Strings.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Strings.cpp?rev=303149&r1=303148&r2=303149&view=diff
==============================================================================
--- lld/trunk/ELF/Strings.cpp (original)
+++ lld/trunk/ELF/Strings.cpp Tue May 16 03:19:25 2017
@@ -46,7 +46,7 @@ int elf::getPriority(StringRef S) {
   if (Pos == StringRef::npos)
     return 65536;
   int V;
-  if (S.substr(Pos + 1).getAsInteger(10, V))
+  if (!to_integer(S.substr(Pos + 1), V, 10))
     return 65536;
   return V;
 }
@@ -68,7 +68,7 @@ std::vector<uint8_t> elf::parseHex(Strin
     StringRef B = S.substr(0, 2);
     S = S.substr(2);
     uint8_t H;
-    if (B.getAsInteger(16, H)) {
+    if (!to_integer(B, H, 16)) {
       error("not a hexadecimal value: " + B);
       return {};
     }

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=303149&r1=303148&r2=303149&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue May 16 03:19:25 2017
@@ -1590,7 +1590,7 @@ template <class ELFT> uint64_t Writer<EL
   if (SymbolBody *B = Symtab<ELFT>::X->find(Config->Entry))
     return B->getVA();
   uint64_t Addr;
-  if (!Config->Entry.getAsInteger(0, Addr))
+  if (to_integer(Config->Entry, Addr))
     return Addr;
 
   // Case 4




More information about the llvm-commits mailing list