|
4 | 4 |
|
5 | 5 | #include "swift/logging/SwiftLogging.h" |
6 | 6 |
|
7 | | -// assert CONDITION, which is always evaluated (once) regardless of the build type. If |
8 | | -// CONDITION is not satisfied, emit a critical log optionally using provided format and arguments, |
9 | | -// abort the program |
| 7 | +// Assert CONDITION, which is always evaluated (once) regardless of the build type. If |
| 8 | +// CONDITION is not satisfied, emit a critical log and diagnostic optionally using provided format |
| 9 | +// and arguments, and then abort the program. |
10 | 10 | #define CODEQL_ASSERT(CONDITION, ...) \ |
11 | | - CODEQL_ASSERT_IMPL(CRITICAL, std::abort(), CONDITION, __VA_ARGS__) |
| 11 | + CODEQL_ASSERT_IMPL(critical, std::abort(), CONDITION, __VA_ARGS__) |
12 | 12 |
|
13 | | -// If CONDITION is not satisfied, emit an error log optionally using provided format and arguments, |
14 | | -// but continue execution |
| 13 | +// If CONDITION is not satisfied, emit an error log and diagnostic optionally using provided format |
| 14 | +// and arguments, but continue execution |
15 | 15 | #define CODEQL_EXPECT(CONDITION, ...) CODEQL_EXPECT_OR(void(), CONDITION, __VA_ARGS__) |
16 | 16 |
|
17 | | -// If CONDITION is not satisfied, emit an error log optionally using provided format and arguments, |
18 | | -// and execute ACTION (for example return) |
| 17 | +// If CONDITION is not satisfied, emit an error log and diagnostic optionally using provided format |
| 18 | +// and arguments, and execute ACTION (for example return) |
19 | 19 | #define CODEQL_EXPECT_OR(ACTION, CONDITION, ...) \ |
20 | | - CODEQL_ASSERT_IMPL(ERROR, ACTION, CONDITION, __VA_ARGS__) |
| 20 | + CODEQL_ASSERT_IMPL(error, ACTION, CONDITION, __VA_ARGS__) |
21 | 21 |
|
22 | | -#define CODEQL_ASSERT_IMPL(LEVEL, ACTION, CONDITION, ...) \ |
23 | | - do { \ |
24 | | - if (!(CONDITION)) { \ |
25 | | - [[unlikely]] LOG_##LEVEL("assertion failed on " #CONDITION ". " __VA_ARGS__); \ |
26 | | - codeql::Log::flush(); \ |
27 | | - ACTION; \ |
28 | | - } \ |
| 22 | +#define CODEQL_ASSERT_IMPL(LEVEL, ACTION, CONDITION, ...) \ |
| 23 | + do { \ |
| 24 | + if (!(CONDITION)) { \ |
| 25 | + [[unlikely]] DIAGNOSE_WITH_LEVEL(LEVEL, codeql::internalError, \ |
| 26 | + "CodeQL encountered an unexpected internal error with the " \ |
| 27 | + "following message:\n> Assertion failed: `" #CONDITION \ |
| 28 | + "`. " __VA_ARGS__); \ |
| 29 | + ACTION; \ |
| 30 | + } \ |
29 | 31 | } while (false) |
0 commit comments