Skip to content

Commit 9cab985

Browse files
committed
Lowercase error messages and port over more calls
Error messages should be lower case, so all of them have been changed. In addition, a few more string error creations have been ported to use offload errors, which also meant moving some reporting things to OffloadError.h.
1 parent 149bee8 commit 9cab985

File tree

14 files changed

+292
-278
lines changed

14 files changed

+292
-278
lines changed

offload/include/Shared/OffloadErrcodes.inc

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,38 @@
1414
// To add new error codes, add them to offload/liboffload/API/Common.td and run
1515
// the GenerateOffload target.
1616

17-
OFFLOAD_ERRC(SUCCESS, "Success", 0)
18-
OFFLOAD_ERRC(UNKNOWN, "Unknown or internal error", 1)
17+
OFFLOAD_ERRC(SUCCESS, "success", 0)
18+
OFFLOAD_ERRC(UNKNOWN, "unknown or internal error", 1)
1919
OFFLOAD_ERRC(HOST_IO, "I/O error on host", 2)
20-
OFFLOAD_ERRC(INVALID_BINARY, "A provided binary image is malformed", 3)
20+
OFFLOAD_ERRC(INVALID_BINARY, "a provided binary image is malformed", 3)
2121
OFFLOAD_ERRC(INVALID_NULL_POINTER,
22-
"A pointer argument is null when it should not be", 4)
23-
OFFLOAD_ERRC(INVALID_ARGUMENT, "An argument is invalid", 5)
24-
OFFLOAD_ERRC(NOT_FOUND, "Requested object was not found in the binary image", 6)
25-
OFFLOAD_ERRC(OUT_OF_RESOURCES, "Out of resources", 7)
22+
"a pointer argument is null when it should not be", 4)
23+
OFFLOAD_ERRC(INVALID_ARGUMENT, "an argument is invalid", 5)
24+
OFFLOAD_ERRC(NOT_FOUND, "requested object was not found in the binary image", 6)
25+
OFFLOAD_ERRC(OUT_OF_RESOURCES, "out of resources", 7)
2626
OFFLOAD_ERRC(
2727
INVALID_SIZE,
2828
"invalid size or dimensions (e.g., must not be zero, or is out of bounds)",
2929
8)
3030
OFFLOAD_ERRC(INVALID_ENUMERATION, "enumerator argument is not valid", 9)
3131
OFFLOAD_ERRC(HOST_TOOL_NOT_FOUND,
32-
"A required binary (linker, etc.) was not found on the host", 10)
33-
OFFLOAD_ERRC(INVALID_VALUE, "Invalid Value", 11)
32+
"a required binary (linker, etc.) was not found on the host", 10)
33+
OFFLOAD_ERRC(INVALID_VALUE, "invalid value", 11)
3434
OFFLOAD_ERRC(UNIMPLEMENTED,
35-
"Generic error code for features currently unimplemented by the "
35+
"generic error code for features currently unimplemented by the "
3636
"device/backend",
3737
12)
3838
OFFLOAD_ERRC(
3939
UNSUPPORTED,
40-
"Generic error code for features unsupported by the device/backend", 13)
40+
"generic error code for features unsupported by the device/backend", 13)
4141
OFFLOAD_ERRC(ASSEMBLE_FAILURE,
42-
"Assembler failure while processing binary image", 14)
43-
OFFLOAD_ERRC(LINK_FAILURE, "Linker failure while processing binary image", 15)
42+
"assembler failure while processing binary image", 14)
43+
OFFLOAD_ERRC(LINK_FAILURE, "linker failure while processing binary image", 15)
4444
OFFLOAD_ERRC(BACKEND_FAILURE,
45-
"The plugin backend is in an invalid or unsupported state", 16)
45+
"the plugin backend is in an invalid or unsupported state", 16)
4646
OFFLOAD_ERRC(INVALID_NULL_HANDLE,
47-
"A handle argument is null when it should not be", 17)
48-
OFFLOAD_ERRC(INVALID_PLATFORM, "Invalid platform", 18)
49-
OFFLOAD_ERRC(INVALID_DEVICE, "Invalid device", 19)
50-
OFFLOAD_ERRC(INVALID_QUEUE, "Invalid queue", 20)
51-
OFFLOAD_ERRC(INVALID_EVENT, "Invalid event", 21)
47+
"a handle argument is null when it should not be", 17)
48+
OFFLOAD_ERRC(INVALID_PLATFORM, "invalid platform", 18)
49+
OFFLOAD_ERRC(INVALID_DEVICE, "invalid device", 19)
50+
OFFLOAD_ERRC(INVALID_QUEUE, "invalid queue", 20)
51+
OFFLOAD_ERRC(INVALID_EVENT, "invalid event", 21)

offload/include/Shared/OffloadError.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,40 @@ class OffloadError : public llvm::ErrorInfo<OffloadError, llvm::StringError> {
4646
// The definition for this resides in the plugin static library
4747
static char ID;
4848
};
49+
50+
/// Create an Offload error.
51+
template <typename... ArgsTy>
52+
static llvm::Error createOffloadError(error::ErrorCode Code, const char *ErrFmt, ArgsTy... Args) {
53+
std::string Buffer;
54+
llvm::raw_string_ostream(Buffer) << llvm::format(ErrFmt, Args...);
55+
return llvm::make_error<error::OffloadError>(Code, Buffer);
56+
}
57+
58+
inline llvm::Error createOffloadError(error::ErrorCode Code, const char *S) {
59+
return llvm::make_error<error::OffloadError>(Code, S);
60+
}
61+
62+
// The OffloadError will have a message of either:
63+
// * "{Context}: {Message}" if the other error is a StringError
64+
// * "{Context}" otherwise
65+
inline llvm::Error createOffloadError(error::ErrorCode Code, llvm::Error &&OtherError,
66+
const char *Context) {
67+
std::string Buffer{Context};
68+
llvm::raw_string_ostream buffer(Buffer);
69+
70+
handleAllErrors(
71+
std::move(OtherError),
72+
[&](llvm::StringError &Err) {
73+
buffer << ": ";
74+
buffer << Err.getMessage();
75+
},
76+
[&](llvm::ErrorInfoBase &Err) {
77+
// Non-string error message don't add anything to the offload error's
78+
// error message
79+
});
80+
81+
return llvm::make_error<error::OffloadError>(Code, Buffer);
82+
}
4983
} // namespace error
5084

5185
#endif

offload/liboffload/API/Common.td

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,32 +87,32 @@ def ErrorCode : Enum {
8787
let name = "ol_errc_t";
8888
let desc = "Defines Return/Error codes";
8989
let etors =[
90-
Etor<"SUCCESS", "Success">,
90+
Etor<"SUCCESS", "success">,
9191

9292
// Universal errors
93-
Etor<"UNKNOWN", "Unknown or internal error">,
93+
Etor<"UNKNOWN", "unknown or internal error">,
9494
Etor<"HOST_IO", "I/O error on host">,
95-
Etor<"INVALID_BINARY", "A provided binary image is malformed">,
96-
Etor<"INVALID_NULL_POINTER", "A pointer argument is null when it should not be">,
97-
Etor<"INVALID_ARGUMENT", "An argument is invalid">,
98-
Etor<"NOT_FOUND", "Requested object was not found in the binary image">,
99-
Etor<"OUT_OF_RESOURCES", "Out of resources">,
95+
Etor<"INVALID_BINARY", "a provided binary image is malformed">,
96+
Etor<"INVALID_NULL_POINTER", "a pointer argument is null when it should not be">,
97+
Etor<"INVALID_ARGUMENT", "an argument is invalid">,
98+
Etor<"NOT_FOUND", "requested object was not found in the binary image">,
99+
Etor<"OUT_OF_RESOURCES", "out of resources">,
100100
Etor<"INVALID_SIZE", "invalid size or dimensions (e.g., must not be zero, or is out of bounds)">,
101101
Etor<"INVALID_ENUMERATION", "enumerator argument is not valid">,
102-
Etor<"HOST_TOOL_NOT_FOUND", "A required binary (linker, etc.) was not found on the host">,
103-
Etor<"INVALID_VALUE", "Invalid Value">,
104-
Etor<"UNIMPLEMENTED", "Generic error code for features currently unimplemented by the device/backend">,
105-
Etor<"UNSUPPORTED", "Generic error code for features unsupported by the device/backend">,
106-
Etor<"ASSEMBLE_FAILURE", "Assembler failure while processing binary image">,
107-
Etor<"LINK_FAILURE", "Linker failure while processing binary image">,
108-
Etor<"BACKEND_FAILURE", "The plugin backend is in an invalid or unsupported state">,
102+
Etor<"HOST_TOOL_NOT_FOUND", "a required binary (linker, etc.) was not found on the host">,
103+
Etor<"INVALID_VALUE", "invalid value">,
104+
Etor<"UNIMPLEMENTED", "generic error code for features currently unimplemented by the device/backend">,
105+
Etor<"UNSUPPORTED", "generic error code for features unsupported by the device/backend">,
106+
Etor<"ASSEMBLE_FAILURE", "assembler failure while processing binary image">,
107+
Etor<"LINK_FAILURE", "linker failure while processing binary image">,
108+
Etor<"BACKEND_FAILURE", "the plugin backend is in an invalid or unsupported state">,
109109

110110
// Handle related errors - only makes sense for liboffload
111-
Etor<"INVALID_NULL_HANDLE", "A handle argument is null when it should not be">,
112-
Etor<"INVALID_PLATFORM", "Invalid platform">,
113-
Etor<"INVALID_DEVICE", "Invalid device">,
114-
Etor<"INVALID_QUEUE", "Invalid queue">,
115-
Etor<"INVALID_EVENT", "Invalid event">,
111+
Etor<"INVALID_NULL_HANDLE", "a handle argument is null when it should not be">,
112+
Etor<"INVALID_PLATFORM", "invalid platform">,
113+
Etor<"INVALID_DEVICE", "invalid device">,
114+
Etor<"INVALID_QUEUE", "invalid queue">,
115+
Etor<"INVALID_EVENT", "invalid event">,
116116
];
117117
}
118118

offload/liboffload/include/generated/OffloadAPI.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,50 +20,50 @@ extern "C" {
2020
///////////////////////////////////////////////////////////////////////////////
2121
/// @brief Defines Return/Error codes
2222
typedef enum ol_errc_t {
23-
/// Success
23+
/// success
2424
OL_ERRC_SUCCESS = 0,
25-
/// Unknown or internal error
25+
/// unknown or internal error
2626
OL_ERRC_UNKNOWN = 1,
2727
/// I/O error on host
2828
OL_ERRC_HOST_IO = 2,
29-
/// A provided binary image is malformed
29+
/// a provided binary image is malformed
3030
OL_ERRC_INVALID_BINARY = 3,
31-
/// A pointer argument is null when it should not be
31+
/// a pointer argument is null when it should not be
3232
OL_ERRC_INVALID_NULL_POINTER = 4,
33-
/// An argument is invalid
33+
/// an argument is invalid
3434
OL_ERRC_INVALID_ARGUMENT = 5,
35-
/// Requested object was not found in the binary image
35+
/// requested object was not found in the binary image
3636
OL_ERRC_NOT_FOUND = 6,
37-
/// Out of resources
37+
/// out of resources
3838
OL_ERRC_OUT_OF_RESOURCES = 7,
3939
/// invalid size or dimensions (e.g., must not be zero, or is out of bounds)
4040
OL_ERRC_INVALID_SIZE = 8,
4141
/// enumerator argument is not valid
4242
OL_ERRC_INVALID_ENUMERATION = 9,
43-
/// A required binary (linker, etc.) was not found on the host
43+
/// a required binary (linker, etc.) was not found on the host
4444
OL_ERRC_HOST_TOOL_NOT_FOUND = 10,
45-
/// Invalid Value
45+
/// invalid value
4646
OL_ERRC_INVALID_VALUE = 11,
47-
/// Generic error code for features currently unimplemented by the
47+
/// generic error code for features currently unimplemented by the
4848
/// device/backend
4949
OL_ERRC_UNIMPLEMENTED = 12,
50-
/// Generic error code for features unsupported by the device/backend
50+
/// generic error code for features unsupported by the device/backend
5151
OL_ERRC_UNSUPPORTED = 13,
52-
/// Assembler failure while processing binary image
52+
/// assembler failure while processing binary image
5353
OL_ERRC_ASSEMBLE_FAILURE = 14,
54-
/// Linker failure while processing binary image
54+
/// linker failure while processing binary image
5555
OL_ERRC_LINK_FAILURE = 15,
56-
/// The plugin backend is in an invalid or unsupported state
56+
/// the plugin backend is in an invalid or unsupported state
5757
OL_ERRC_BACKEND_FAILURE = 16,
58-
/// A handle argument is null when it should not be
58+
/// a handle argument is null when it should not be
5959
OL_ERRC_INVALID_NULL_HANDLE = 17,
60-
/// Invalid platform
60+
/// invalid platform
6161
OL_ERRC_INVALID_PLATFORM = 18,
62-
/// Invalid device
62+
/// invalid device
6363
OL_ERRC_INVALID_DEVICE = 19,
64-
/// Invalid queue
64+
/// invalid queue
6565
OL_ERRC_INVALID_QUEUE = 20,
66-
/// Invalid event
66+
/// invalid event
6767
OL_ERRC_INVALID_EVENT = 21,
6868
/// @cond
6969
OL_ERRC_FORCE_UINT32 = 0x7fffffff

offload/libomptarget/PluginManager.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,9 @@ Expected<DeviceTy &> PluginManager::getDevice(uint32_t DeviceNo) {
538538
{
539539
auto ExclusiveDevicesAccessor = getExclusiveDevicesAccessor();
540540
if (DeviceNo >= ExclusiveDevicesAccessor->size())
541-
return createStringError(
542-
inconvertibleErrorCode(),
543-
"Device number '%i' out of range, only %i devices available",
541+
return error::createOffloadError(
542+
error::ErrorCode::INVALID_VALUE,
543+
"device number '%i' out of range, only %i devices available",
544544
DeviceNo, ExclusiveDevicesAccessor->size());
545545

546546
DevicePtr = &*(*ExclusiveDevicesAccessor)[DeviceNo];
@@ -549,8 +549,8 @@ Expected<DeviceTy &> PluginManager::getDevice(uint32_t DeviceNo) {
549549
// Check whether global data has been mapped for this device
550550
if (DevicePtr->hasPendingImages())
551551
if (loadImagesOntoDevice(*DevicePtr) != OFFLOAD_SUCCESS)
552-
return createStringError(inconvertibleErrorCode(),
553-
"Failed to load images on device '%i'",
554-
DeviceNo);
552+
return error::createOffloadError(error::ErrorCode::BACKEND_FAILURE,
553+
"failed to load images on device '%i'",
554+
DeviceNo);
555555
return *DevicePtr;
556556
}

offload/libomptarget/device.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ DeviceTy::~DeviceTy() {
7979
llvm::Error DeviceTy::init() {
8080
int32_t Ret = RTL->init_device(RTLDeviceID);
8181
if (Ret != OFFLOAD_SUCCESS)
82-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
83-
"Failed to initialize device %d\n",
84-
DeviceID);
82+
return error::createOffloadError(error::ErrorCode::BACKEND_FAILURE,
83+
"failed to initialize device %d\n",
84+
DeviceID);
8585

8686
// Enables recording kernels if set.
8787
BoolEnvar OMPX_RecordKernel("LIBOMPTARGET_RECORD", false);
@@ -103,8 +103,8 @@ DeviceTy::loadBinary(__tgt_device_image *Img) {
103103
__tgt_device_binary Binary;
104104

105105
if (RTL->load_binary(RTLDeviceID, Img, &Binary) != OFFLOAD_SUCCESS)
106-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
107-
"Failed to load binary %p", Img);
106+
return error::createOffloadError(error::ErrorCode::INVALID_BINARY,
107+
"failed to load binary %p", Img);
108108
return Binary;
109109
}
110110

0 commit comments

Comments
 (0)