2023-04-18 11:17:44 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
2023-05-04 11:39:50 +03:00
|
|
|
#include "swift/logging/SwiftLogging.h"
|
2023-04-18 11:17:44 +03:00
|
|
|
|
2023-05-16 20:32:41 +03:00
|
|
|
// Assert CONDITION, which is always evaluated (once) regardless of the build type. If
|
|
|
|
// CONDITION is not satisfied, emit a critical log and diagnostic optionally using provided format
|
|
|
|
// and arguments, and then abort the program.
|
2023-04-18 11:17:44 +03:00
|
|
|
#define CODEQL_ASSERT(CONDITION, ...) \
|
2023-05-16 20:32:41 +03:00
|
|
|
CODEQL_ASSERT_IMPL(critical, std::abort(), CONDITION, __VA_ARGS__)
|
2023-04-18 11:17:44 +03:00
|
|
|
|
2023-05-16 20:32:41 +03:00
|
|
|
// If CONDITION is not satisfied, emit an error log and diagnostic optionally using provided format
|
|
|
|
// and arguments, but continue execution
|
2023-04-18 11:17:44 +03:00
|
|
|
#define CODEQL_EXPECT(CONDITION, ...) CODEQL_EXPECT_OR(void(), CONDITION, __VA_ARGS__)
|
|
|
|
|
2023-05-16 20:32:41 +03:00
|
|
|
// If CONDITION is not satisfied, emit an error log and diagnostic optionally using provided format
|
|
|
|
// and arguments, and execute ACTION (for example return)
|
2023-04-18 11:17:44 +03:00
|
|
|
#define CODEQL_EXPECT_OR(ACTION, CONDITION, ...) \
|
2023-05-16 20:32:41 +03:00
|
|
|
CODEQL_ASSERT_IMPL(error, ACTION, CONDITION, __VA_ARGS__)
|
2023-04-18 11:17:44 +03:00
|
|
|
|
2023-05-16 20:32:41 +03:00
|
|
|
#define CODEQL_ASSERT_IMPL(LEVEL, ACTION, CONDITION, ...) \
|
|
|
|
do { \
|
|
|
|
if (!(CONDITION)) { \
|
|
|
|
[[unlikely]] DIAGNOSE_WITH_LEVEL(LEVEL, codeql::internalError, \
|
|
|
|
"CodeQL encountered an unexpected internal error with the " \
|
|
|
|
"following message:\n> Assertion failed: `" #CONDITION \
|
|
|
|
"`. " __VA_ARGS__); \
|
|
|
|
ACTION; \
|
|
|
|
} \
|
2023-04-18 11:17:44 +03:00
|
|
|
} while (false)
|