[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
This commit is contained in:
Raphael Isemann 2021-10-11 16:34:41 +02:00
parent c3abfe4207
commit bdc35b0efc
4 changed files with 4 additions and 13 deletions

View File

@ -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,

View File

@ -82,6 +82,10 @@ private:
/// 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.

View File

@ -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) {}

View File

@ -43,10 +43,6 @@ static uintptr_t getWithOffset(uintptr_t Base, ptrdiff_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);
}