[llvm] bdc35b0 - [Object] Deduplicate the three createError functions

Raphael Isemann via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 11 07:37:16 PDT 2021


Author: Raphael Isemann
Date: 2021-10-11T16:36:57+02:00
New Revision: bdc35b0efca9445950990fe642f18c3d82ab1299

URL: https://github.com/llvm/llvm-project/commit/bdc35b0efca9445950990fe642f18c3d82ab1299
DIFF: https://github.com/llvm/llvm-project/commit/bdc35b0efca9445950990fe642f18c3d82ab1299.diff

LOG: [Object] Deduplicate the three createError functions

The Object library currently has three identical functions that translate a
Twine into a parser error. Until recently these functions have coexisted
peacefully, but since D110320 Clang with enabled modules is now diagnosing that
we have several definitions of `createError` in Object.

This patch just merges them all and puts them into Object's `Error.h` where the
error code for `parse_failed` is also defined which seems cleaner and unbreaks
the bots.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D111541

Added: 
    

Modified: 
    llvm/include/llvm/Object/ELF.h
    llvm/include/llvm/Object/Error.h
    llvm/lib/Object/COFFModuleDefinition.cpp
    llvm/lib/Object/XCOFFObjectFile.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h
index c5f966891bd02..b7af7795b8c9f 100644
--- a/llvm/include/llvm/Object/ELF.h
+++ b/llvm/include/llvm/Object/ELF.h
@@ -81,10 +81,6 @@ getElfArchType(StringRef Object) {
                         (uint8_t)Object[ELF::EI_DATA]);
 }
 
-static inline Error createError(const Twine &Err) {
-  return make_error<StringError>(Err, object_error::parse_failed);
-}
-
 enum PPCInstrMasks : uint64_t {
   PADDI_R12_NO_DISP = 0x0610000039800000,
   ADDIS_R12_TO_R2_NO_DISP = 0x3D820000,

diff  --git a/llvm/include/llvm/Object/Error.h b/llvm/include/llvm/Object/Error.h
index 07744188444ac..1fc1f6603a361 100644
--- a/llvm/include/llvm/Object/Error.h
+++ b/llvm/include/llvm/Object/Error.h
@@ -82,6 +82,10 @@ class GenericBinaryError : public ErrorInfo<GenericBinaryError, BinaryError> {
 /// error() function needs to called on the llvm::Error.
 Error isNotObjectErrorInvalidFileType(llvm::Error Err);
 
+inline Error createError(const Twine &Err) {
+  return make_error<StringError>(Err, object_error::parse_failed);
+}
+
 } // end namespace object.
 
 } // end namespace llvm.

diff  --git a/llvm/lib/Object/COFFModuleDefinition.cpp b/llvm/lib/Object/COFFModuleDefinition.cpp
index 8f29f7a658fdd..55ddd3baca2b2 100644
--- a/llvm/lib/Object/COFFModuleDefinition.cpp
+++ b/llvm/lib/Object/COFFModuleDefinition.cpp
@@ -80,11 +80,6 @@ static bool isDecorated(StringRef Sym, bool MingwDef) {
          (!MingwDef && Sym.contains('@'));
 }
 
-static Error createError(const Twine &Err) {
-  return make_error<StringError>(StringRef(Err.str()),
-                                 object_error::parse_failed);
-}
-
 class Lexer {
 public:
   Lexer(StringRef S) : Buf(S) {}

diff  --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp
index a0ce8be8761e9..1a3a394ce9cb7 100644
--- a/llvm/lib/Object/XCOFFObjectFile.cpp
+++ b/llvm/lib/Object/XCOFFObjectFile.cpp
@@ -43,10 +43,6 @@ static uintptr_t getWithOffset(uintptr_t Base, ptr
diff _t Offset) {
                                      Offset);
 }
 
-static Error createError(const Twine &Err) {
-  return make_error<StringError>(Err, object_error::parse_failed);
-}
-
 template <typename T> static const T *viewAs(uintptr_t in) {
   return reinterpret_cast<const T *>(in);
 }


        


More information about the llvm-commits mailing list