[lld] r234841 - Define make_dynamic_error_code(const char *).

Rui Ueyama ruiu at google.com
Mon Apr 13 19:34:09 PDT 2015


Author: ruiu
Date: Mon Apr 13 21:34:09 2015
New Revision: 234841

URL: http://llvm.org/viewvc/llvm-project?rev=234841&view=rev
Log:
Define make_dynamic_error_code(const char *).

The function took either StringRef or Twine. Since string literals are
ambiguous when resolving the overloading, many code calls used this
function with explicit type conversion. That led awkward code like
make_dynamic_error_code(Twine("Error occurred")).

This patch adds a function definition for string literals, so that
you can directly call the function with literals.

Modified:
    lld/trunk/include/lld/Core/Error.h
    lld/trunk/lib/Core/Error.cpp
    lld/trunk/lib/Driver/GnuLdDriver.cpp
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFlagsMerger.cpp
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
    lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h
    lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp
    lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp
    lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp
    lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp
    lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
    lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp

Modified: lld/trunk/include/lld/Core/Error.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Error.h?rev=234841&r1=234840&r2=234841&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Error.h (original)
+++ lld/trunk/include/lld/Core/Error.h Mon Apr 13 21:34:09 2015
@@ -50,6 +50,7 @@ inline std::error_code make_error_code(L
 /// supplied error string.
 /// Note:  Once ErrorOr<> is updated to work with errors other than error_code,
 /// this can be updated to return some other kind of error.
+std::error_code make_dynamic_error_code(const char *msg);
 std::error_code make_dynamic_error_code(StringRef msg);
 std::error_code make_dynamic_error_code(const Twine &msg);
 

Modified: lld/trunk/lib/Core/Error.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Error.cpp?rev=234841&r1=234840&r2=234841&view=diff
==============================================================================
--- lld/trunk/lib/Core/Error.cpp (original)
+++ lld/trunk/lib/Core/Error.cpp Mon Apr 13 21:34:09 2015
@@ -107,6 +107,10 @@ private:
 
 static dynamic_error_category categorySingleton;
 
+std::error_code make_dynamic_error_code(const char *msg) {
+  return make_dynamic_error_code(StringRef(msg));
+}
+
 std::error_code make_dynamic_error_code(StringRef msg) {
   return std::error_code(categorySingleton.add(msg), categorySingleton);
 }

Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=234841&r1=234840&r2=234841&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Mon Apr 13 21:34:09 2015
@@ -124,7 +124,7 @@ getFileMagic(StringRef path, llvm::sys::
   case llvm::sys::fs::file_magic::unknown:
     return std::error_code();
   default:
-    return make_dynamic_error_code(StringRef("unknown type of object file"));
+    return make_dynamic_error_code("unknown type of object file");
   }
 }
 

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFlagsMerger.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFlagsMerger.cpp?rev=234841&r1=234840&r2=234841&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFlagsMerger.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFlagsMerger.cpp Mon Apr 13 21:34:09 2015
@@ -69,14 +69,14 @@ std::error_code MipsELFFlagsMerger::merg
   // Check bitness.
   if (_is64Bit != (newClass == ELFCLASS64))
     return make_dynamic_error_code(
-        Twine("Bitness is incompatible with that of the selected target"));
+        "Bitness is incompatible with that of the selected target");
 
   // We support two ABI: O32 and N64. The last one does not have
   // the corresponding ELF flag.
   uint32_t inAbi = newFlags & EF_MIPS_ABI;
   uint32_t supportedAbi = _is64Bit ? 0 : uint32_t(EF_MIPS_ABI_O32);
   if (inAbi != supportedAbi)
-    return make_dynamic_error_code(Twine("Unsupported ABI"));
+    return make_dynamic_error_code("Unsupported ABI");
 
   // ... and reduced set of architectures ...
   uint32_t newArch = newFlags & EF_MIPS_ARCH;
@@ -94,12 +94,12 @@ std::error_code MipsELFFlagsMerger::merg
   case EF_MIPS_ARCH_64R6:
     break;
   default:
-    return make_dynamic_error_code(Twine("Unsupported instruction set"));
+    return make_dynamic_error_code("Unsupported instruction set");
   }
 
   // ... and still do not support MIPS-16 extension.
   if (newFlags & EF_MIPS_ARCH_ASE_M16)
-    return make_dynamic_error_code(Twine("Unsupported extension: MIPS16"));
+    return make_dynamic_error_code("Unsupported extension: MIPS16");
 
   // PIC code is inherently CPIC and may not set CPIC flag explicitly.
   // Ensure that this flag will exist in the linked file.
@@ -129,14 +129,13 @@ std::error_code MipsELFFlagsMerger::merg
   // Check mixing -mnan=2008 / -mnan=legacy modules.
   if ((newFlags & EF_MIPS_NAN2008) != (_flags & EF_MIPS_NAN2008))
     return make_dynamic_error_code(
-        Twine("Linking -mnan=2008 and -mnan=legacy modules"));
+        "Linking -mnan=2008 and -mnan=legacy modules");
 
   // Check ISA compatibility and update the extension flag.
   uint32_t oldArch = _flags & EF_MIPS_ARCH;
   if (!matchMipsISA(newArch, oldArch)) {
     if (!matchMipsISA(oldArch, newArch))
-      return make_dynamic_error_code(
-          Twine("Linking modules with incompatible ISA"));
+      return make_dynamic_error_code("Linking modules with incompatible ISA");
     _flags &= ~EF_MIPS_ARCH;
     _flags |= newArch;
   }

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp?rev=234841&r1=234840&r2=234841&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp Mon Apr 13 21:34:09 2015
@@ -350,8 +350,7 @@ static std::error_code adjustJumpOpCode(
   uint32_t opCross = toMicro ? 0x1d : 0x3c;
 
   if ((tgt & 1) != toMicro)
-    return make_dynamic_error_code(
-        Twine("Incorrect bit 0 for the jalx target"));
+    return make_dynamic_error_code("Incorrect bit 0 for the jalx target");
 
   if (tgt & 2)
     return make_dynamic_error_code(Twine("The jalx target 0x") +

Modified: lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h?rev=234841&r1=234840&r2=234841&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/TargetHandler.h Mon Apr 13 21:34:09 2015
@@ -18,15 +18,15 @@ namespace lld {
 namespace elf {
 
 inline std::error_code make_unhandled_reloc_error() {
-  return make_dynamic_error_code(Twine("Unhandled reference type"));
+  return make_dynamic_error_code("Unhandled reference type");
 }
 
 inline std::error_code make_out_of_range_reloc_error() {
-  return make_dynamic_error_code(Twine("Relocation out of range"));
+  return make_dynamic_error_code("Relocation out of range");
 }
 
 inline std::error_code make_unaligned_range_reloc_error() {
-  return make_dynamic_error_code(Twine("Relocation not aligned"));
+  return make_dynamic_error_code("Relocation not aligned");
 }
 
 } // end namespace elf

Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp?rev=234841&r1=234840&r2=234841&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp Mon Apr 13 21:34:09 2015
@@ -619,7 +619,7 @@ std::error_code ArchHandler_arm::getRefe
     *addend += (clearThumbBit(instruction, *target) - reloc.value);
     return std::error_code();
   default:
-    return make_dynamic_error_code(Twine("unsupported arm relocation type"));
+    return make_dynamic_error_code("unsupported arm relocation type");
   }
   return std::error_code();
 }
@@ -777,7 +777,7 @@ ArchHandler_arm::getPairReferenceInfo(co
     pointerDiff = true;
     break;
   default:
-    return make_dynamic_error_code(Twine("unsupported arm relocation pair"));
+    return make_dynamic_error_code("unsupported arm relocation pair");
   }
   const uint8_t *fixupContent = &inAtom->rawContent()[offsetInAtom];
   std::error_code ec;
@@ -800,8 +800,8 @@ ArchHandler_arm::getPairReferenceInfo(co
     if (ec)
       return ec;
     if (scatterable && (fromTarget != inAtom))
-      return make_dynamic_error_code(Twine("SECTDIFF relocation where "
-                                           "subtrahend label is not in atom"));
+      return make_dynamic_error_code(
+          "SECTDIFF relocation where subtrahend label is not in atom");
     *kind = delta32;
     value = clearThumbBit(instruction, *target);
     *addend = (int32_t)(value - (toAddress - fixupAddress));
@@ -815,29 +815,28 @@ ArchHandler_arm::getPairReferenceInfo(co
     if (ec)
       return ec;
     if (fromTarget != inAtom)
-      return make_dynamic_error_code(
-          Twine("ARM_RELOC_HALF_SECTDIFF relocation "
-                "where subtrahend label is not in atom"));
+      return make_dynamic_error_code("ARM_RELOC_HALF_SECTDIFF relocation "
+                                     "where subtrahend label is not in atom");
     other16 = (reloc2.offset & 0xFFFF);
     if (thumbReloc) {
       if (top) {
         if (!isThumbMovt(instruction))
-          return make_dynamic_error_code(Twine("expected movt instruction"));
+          return make_dynamic_error_code("expected movt instruction");
       }
       else {
         if (!isThumbMovw(instruction))
-          return make_dynamic_error_code(Twine("expected movw instruction"));
+          return make_dynamic_error_code("expected movw instruction");
       }
       instruction16 = getWordFromThumbMov(instruction);
     }
     else {
       if (top) {
         if (!isArmMovt(instruction))
-          return make_dynamic_error_code(Twine("expected movt instruction"));
+          return make_dynamic_error_code("expected movt instruction");
       }
       else {
         if (!isArmMovw(instruction))
-          return make_dynamic_error_code(Twine("expected movw instruction"));
+          return make_dynamic_error_code("expected movw instruction");
       }
       instruction16 = getWordFromArmMov(instruction);
     }
@@ -854,22 +853,22 @@ ArchHandler_arm::getPairReferenceInfo(co
     if (thumbReloc) {
       if (top) {
         if (!isThumbMovt(instruction))
-          return make_dynamic_error_code(Twine("expected movt instruction"));
+          return make_dynamic_error_code("expected movt instruction");
       }
       else {
         if (!isThumbMovw(instruction))
-          return make_dynamic_error_code(Twine("expected movw instruction"));
+          return make_dynamic_error_code("expected movw instruction");
       }
       instruction16 = getWordFromThumbMov(instruction);
     }
     else {
       if (top) {
         if (!isArmMovt(instruction))
-          return make_dynamic_error_code(Twine("expected movt instruction"));
+          return make_dynamic_error_code("expected movt instruction");
       }
       else {
         if (!isArmMovw(instruction))
-          return make_dynamic_error_code(Twine("expected movw instruction"));
+          return make_dynamic_error_code("expected movw instruction");
       }
       instruction16 = getWordFromArmMov(instruction);
     }

Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp?rev=234841&r1=234840&r2=234841&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp Mon Apr 13 21:34:09 2015
@@ -437,7 +437,7 @@ std::error_code ArchHandler_arm64::getRe
     *addend = 0;
     return std::error_code();
   default:
-    return make_dynamic_error_code(Twine("unsupported arm64 relocation type"));
+    return make_dynamic_error_code("unsupported arm64 relocation type");
   }
 }
 
@@ -491,7 +491,7 @@ std::error_code ArchHandler_arm64::getPa
     *addend = (int32_t)*(const little32_t *)fixupContent + offsetInAtom;
     return std::error_code();
   default:
-    return make_dynamic_error_code(Twine("unsupported arm64 relocation pair"));
+    return make_dynamic_error_code("unsupported arm64 relocation pair");
   }
 }
 

Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp?rev=234841&r1=234840&r2=234841&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp Mon Apr 13 21:34:09 2015
@@ -334,7 +334,7 @@ ArchHandler_x86::getReferenceInfo(const
     *addend = *(const ulittle32_t *)fixupContent - reloc.value;
     break;
   default:
-    return make_dynamic_error_code(Twine("unsupported i386 relocation type"));
+    return make_dynamic_error_code("unsupported i386 relocation type");
   }
   return std::error_code();
 }
@@ -376,8 +376,8 @@ ArchHandler_x86::getPairReferenceInfo(co
       return ec;
     if (fromTarget != inAtom) {
       if (*target != inAtom)
-        return make_dynamic_error_code(Twine("SECTDIFF relocation where "
-                                             "neither target is in atom"));
+        return make_dynamic_error_code(
+            "SECTDIFF relocation where neither target is in atom");
       *kind = negDelta32;
       *addend = toAddress - value - fromAddress;
       *target = fromTarget;
@@ -400,7 +400,7 @@ ArchHandler_x86::getPairReferenceInfo(co
     return std::error_code();
     break;
   default:
-    return make_dynamic_error_code(Twine("unsupported i386 relocation type"));
+    return make_dynamic_error_code("unsupported i386 relocation type");
   }
 }
 

Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp?rev=234841&r1=234840&r2=234841&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp Mon Apr 13 21:34:09 2015
@@ -331,7 +331,7 @@ ArchHandler_x86_64::getReferenceInfo(con
   typedef std::error_code E;
   *kind = kindFromReloc(reloc);
   if (*kind == invalid)
-    return make_dynamic_error_code(Twine("unknown type"));
+    return make_dynamic_error_code("unknown type");
   const uint8_t *fixupContent = &inAtom->rawContent()[offsetInAtom];
   uint64_t targetAddress;
   switch (*kind) {
@@ -413,7 +413,7 @@ ArchHandler_x86_64::getPairReferenceInfo
                                    Reference::Addend *addend) {
   *kind = kindFromRelocPair(reloc1, reloc2);
   if (*kind == invalid)
-    return make_dynamic_error_code(Twine("unknown pair"));
+    return make_dynamic_error_code("unknown pair");
   const uint8_t *fixupContent = &inAtom->rawContent()[offsetInAtom];
   typedef std::error_code E;
   uint64_t targetAddress;
@@ -421,7 +421,7 @@ ArchHandler_x86_64::getPairReferenceInfo
   if (E ec = atomFromSymbolIndex(reloc1.symbol, &fromTarget))
     return ec;
   if (fromTarget != inAtom)
-    return make_dynamic_error_code(Twine("pointer diff not in base atom"));
+    return make_dynamic_error_code("pointer diff not in base atom");
   switch (*kind) {
   case delta64:
     if (E ec = atomFromSymbolIndex(reloc2.symbol, target))

Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp?rev=234841&r1=234840&r2=234841&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp Mon Apr 13 21:34:09 2015
@@ -558,17 +558,17 @@ std::error_code convertRelocs(const Sect
         *result = target;
         return std::error_code();
       }
-      return make_dynamic_error_code(Twine("no atom found for defined symbol"));
+      return make_dynamic_error_code("no atom found for defined symbol");
     } else if ((sym->type & N_TYPE) == N_UNDF) {
       const lld::Atom *target = file.findUndefAtom(sym->name);
       if (target) {
         *result = target;
         return std::error_code();
       }
-      return make_dynamic_error_code(Twine("no undefined atom found for sym"));
+      return make_dynamic_error_code("no undefined atom found for sym");
     } else {
       // Search undefs
-      return make_dynamic_error_code(Twine("no atom found for symbol"));
+      return make_dynamic_error_code("no atom found for symbol");
     }
   };
 

Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp?rev=234841&r1=234840&r2=234841&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp Mon Apr 13 21:34:09 2015
@@ -257,7 +257,7 @@ public:
 
     // Check if the total size is valid.
     if (std::size_t(end - buf) != sizeof(COFF::ImportHeader) + dataSize)
-      return make_dynamic_error_code(StringRef("Broken import library"));
+      return make_dynamic_error_code("Broken import library");
 
     uint16_t hint = read16le(buf + offsetof(COFF::ImportHeader, OrdinalHint));
     StringRef symbolName(buf + sizeof(COFF::ImportHeader));





More information about the llvm-commits mailing list