aboutsummaryrefslogtreecommitdiff
path: root/offload/unittests/Conformance/include/mathtest/ErrorHandling.hpp
blob: 7ec276227acc34779c3bcd40480ffdee102b80dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file contains the definition of error handling macros for reporting
/// fatal error conditions and validating Offload API calls.
///
//===----------------------------------------------------------------------===//

#ifndef MATHTEST_ERRORHANDLING_HPP
#define MATHTEST_ERRORHANDLING_HPP

#include "mathtest/OffloadForward.hpp"

#include "llvm/ADT/Twine.h"

#define FATAL_ERROR(Message)                                                   \
  mathtest::detail::reportFatalError(Message, __FILE__, __LINE__, __func__)

#define OL_CHECK(ResultExpr)                                                   \
  do {                                                                         \
    ol_result_t Result = (ResultExpr);                                         \
    if (Result != OL_SUCCESS)                                                  \
      mathtest::detail::reportOffloadError(#ResultExpr, Result, __FILE__,      \
                                           __LINE__, __func__);                \
                                                                               \
  } while (false)

namespace mathtest {
namespace detail {

[[noreturn]] void reportFatalError(const llvm::Twine &Message, const char *File,
                                   int Line, const char *FuncName);

[[noreturn]] void reportOffloadError(const char *ResultExpr, ol_result_t Result,
                                     const char *File, int Line,
                                     const char *FuncName);
} // namespace detail
} // namespace mathtest

#endif // MATHTEST_ERRORHANDLING_HPP