Add TINT_ASSERT()
Replacement for the places where we currently use assert(), and there is no sensible place to put the error into a diag::List. Change-Id: Id154340b0353f8a3e8962771263f1cc87dce2aa4 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44047 Reviewed-by: Antonio Maiorano <amaiorano@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
5b36d2c612
commit
01df2a7cee
16
src/debug.h
16
src/debug.h
|
@ -88,4 +88,20 @@ class InternalCompilerError {
|
|||
#define TINT_UNREACHABLE(diagnostics) \
|
||||
TINT_ICE(diagnostics) << "TINT_UNREACHABLE "
|
||||
|
||||
/// TINT_ASSERT() is a macro for checking the expression is true, triggering a
|
||||
/// TINT_ICE if it is not.
|
||||
/// The ICE message contains the callsite's file and line.
|
||||
/// @warning: Unlike TINT_ICE() and TINT_UNREACHABLE(), TINT_ASSERT() does not
|
||||
/// append a message to an existing tint::diag::List. As such, TINT_ASSERT()
|
||||
/// may silently fail in builds where SetInternalCompilerErrorReporter() is not
|
||||
/// called. Only use in places where there's no sensible place to put proper
|
||||
/// error handling.
|
||||
#define TINT_ASSERT(condition) \
|
||||
do { \
|
||||
if (!(condition)) { \
|
||||
tint::diag::List diagnostics; \
|
||||
TINT_ICE(diagnostics) << "TINT_ASSERT(" << #condition << ")"; \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#endif // SRC_DEBUG_H_
|
||||
|
|
|
@ -28,5 +28,13 @@ TEST(DebugTest, Unreachable) {
|
|||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST(DebugTest, AssertTrue) {
|
||||
TINT_ASSERT(true);
|
||||
}
|
||||
|
||||
TEST(DebugTest, AssertFalse) {
|
||||
EXPECT_FATAL_FAILURE({ TINT_ASSERT(false); }, "internal compiler error");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint
|
||||
|
|
Loading…
Reference in New Issue