blob: 581738bfde2938f84b1238cf09ecbd617c89ef16 [file] [log] [blame]
// Part of the Crubit project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CRUBIT_RS_BINDINGS_FROM_CC_UTIL_CHECK_H_
#define CRUBIT_RS_BINDINGS_FROM_CC_UTIL_CHECK_H_
#include "third_party/absl/base/attributes.h"
#include "third_party/absl/base/optimization.h"
#include "third_party/llvm/llvm-project/llvm/include/llvm/Support/ErrorHandling.h"
#include "third_party/llvm/llvm-project/llvm/include/llvm/Support/FormatVariadic.h"
#define CRUBIT_CHECK(condition) \
do { \
if (ABSL_PREDICT_FALSE(!(condition))) { \
::llvm::report_fatal_error( \
::llvm::formatv("CRUBIT_CHECK failure: {0}:{1}: {2}", __FILE__, \
__LINE__, #condition)); \
} \
} while (false)
namespace rs_bindings_from_cc {
template <typename T>
ABSL_MUST_USE_RESULT T DieIfNull(const char* file, int line,
const char* exprtext, T&& t) {
if (ABSL_PREDICT_FALSE(t == nullptr)) {
::llvm::report_fatal_error(llvm::formatv(
"CRUBIT_DIE_IF_NULL failure: {0}:{1}: {2}", file, line, exprtext));
}
return std::forward<T>(t);
}
} // namespace rs_bindings_from_cc
#define CRUBIT_DIE_IF_NULL(value) \
::rs_bindings_from_cc::DieIfNull(__FILE__, __LINE__, #value, (value))
#endif // CRUBIT_RS_BINDINGS_FROM_CC_UTIL_CHECK_H_