[OpenMP][libomptarget] rework of fatal error reporting

Summary:
Removed the function that used a lock and varargs
Used the same mechanism as for debug messages

Reviewers: ABataev, gtbercea, grokos, Hahnfeld

Reviewed By: gtbercea, Hahnfeld

Subscribers: mikerice, ABataev, RaviNarayanaswamy, guansong, openmp-commits

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

llvm-svn: 340767
This commit is contained in:
Alexandre Eichenberger
2018-08-27 18:20:15 +00:00
parent cea7c6969d
commit e9b7d8dcd6
3 changed files with 21 additions and 23 deletions

View File

@@ -55,16 +55,16 @@ static void HandleTargetOutcome(bool success) {
switch (TargetOffloadPolicy) {
case tgt_disabled:
if (success) {
FatalMessage(1, "expected no offloading while offloading is disabled");
FATAL_MESSAGE0(1, "expected no offloading while offloading is disabled");
}
break;
case tgt_default:
DP("Should never reach this test with target offload set to default\n");
assert(false);
FATAL_MESSAGE0(1, "default offloading policy must switched to "
"mandatory or disabled");
break;
case tgt_mandatory:
if (!success) {
FatalMessage(1, "failure of target construct while offloading is mandatory");
FATAL_MESSAGE0(1, "failure of target construct while offloading is mandatory");
}
break;
}

View File

@@ -26,23 +26,6 @@
int DebugLevel = 0;
#endif // OMPTARGET_DEBUG
////////////////////////////////////////////////////////////////////////////////
/// support for fatal messages
// mutex
std::mutex LibomptargetPrintMtx;
void FatalMessage(const int errorNum, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
LibomptargetPrintMtx.lock();
fprintf(stderr, "Libomptarget error %d:", errorNum);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
LibomptargetPrintMtx.unlock();
va_end(args);
exit(1);
}
/* All begin addresses for partially mapped structs must be 8-aligned in order

View File

@@ -42,6 +42,23 @@ enum kmp_target_offload_kind {
typedef enum kmp_target_offload_kind kmp_target_offload_kind_t;
extern kmp_target_offload_kind_t TargetOffloadPolicy;
////////////////////////////////////////////////////////////////////////////////
// implemtation for fatal messages
////////////////////////////////////////////////////////////////////////////////
#define FATAL_MESSAGE0(_num, _str) \
do { \
fprintf(stderr, "Libomptarget fatal error %d: %s\n", _num, _str); \
exit(1); \
} while (0)
#define FATAL_MESSAGE(_num, _str, ...) \
do { \
fprintf(stderr, "Libomptarget fatal error %d:" _str "\n", _num, \
__VA_ARGS__); \
exit(1); \
} while (0)
// Implemented in libomp, they are called from within __tgt_* functions.
#ifdef __cplusplus
extern "C" {
@@ -54,8 +71,6 @@ int __kmpc_get_target_offload(void) __attribute__((weak));
}
#endif
void FatalMessage(const int errorNum, const char *fmt, ...);
#ifdef OMPTARGET_DEBUG
extern int DebugLevel;