File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ #pragma once
2
+
3
+ #include < cstdlib>
4
+
5
+ #include " swift/extractor/infra/log/SwiftLogging.h"
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
10
+ #define CODEQL_ASSERT (CONDITION, ...) \
11
+ CODEQL_ASSERT_IMPL (CRITICAL, std::abort(), CONDITION, __VA_ARGS__)
12
+
13
+ // If CONDITION is not satisfied, emit an error log optionally using provided format and arguments,
14
+ // but continue execution
15
+ #define CODEQL_EXPECT (CONDITION, ...) CODEQL_EXPECT_OR(void (), CONDITION, __VA_ARGS__)
16
+
17
+ // If CONDITION is not satisfied, emit an error log optionally using provided format and arguments,
18
+ // and execute ACTION (for example return)
19
+ #define CODEQL_EXPECT_OR (ACTION, CONDITION, ...) \
20
+ CODEQL_ASSERT_IMPL (ERROR, ACTION, CONDITION, __VA_ARGS__)
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
+ } \
29
+ } while (false )
You can’t perform that action at this time.
0 commit comments