forked from OSchip/llvm-project
[Sanitizer] Use common CHECK machinery. Currently each tool has to define its own CheckFailed function.
llvm-svn: 158075
This commit is contained in:
parent
79437fe376
commit
e428779dbf
|
@ -110,7 +110,6 @@ class AsanThread;
|
|||
struct AsanStackTrace;
|
||||
|
||||
// asan_rtl.cc
|
||||
void NORETURN CheckFailed(const char *cond, const char *file, int line);
|
||||
void NORETURN ShowStatsAndAbort();
|
||||
|
||||
// asan_globals.cc
|
||||
|
@ -224,19 +223,6 @@ void NORETURN Exit(int exitcode);
|
|||
void NORETURN Abort();
|
||||
int Atexit(void (*function)(void));
|
||||
|
||||
#define CHECK(cond) do { if (!(cond)) { \
|
||||
CheckFailed(#cond, __FILE__, __LINE__); \
|
||||
}}while(0)
|
||||
|
||||
#define RAW_CHECK_MSG(expr, msg) do { \
|
||||
if (!(expr)) { \
|
||||
RawWrite(msg); \
|
||||
Die(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define RAW_CHECK(expr) RAW_CHECK_MSG(expr, #expr)
|
||||
|
||||
#define UNIMPLEMENTED() CHECK("unimplemented" && 0)
|
||||
|
||||
#define ASAN_ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
|
||||
|
|
|
@ -45,6 +45,13 @@ void Die() {
|
|||
Exit(FLAG_exitcode);
|
||||
}
|
||||
|
||||
void CheckFailed(const char *file, int line, const char *cond, u64 v1, u64 v2) {
|
||||
AsanReport("AddressSanitizer CHECK failed: %s:%d \"%s\" (%zx, %zx)\n",
|
||||
file, line, cond, (uptr)v1, (uptr)v2);
|
||||
PRINT_CURRENT_STACK();
|
||||
ShowStatsAndAbort();
|
||||
}
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
||||
namespace __asan {
|
||||
|
@ -336,12 +343,6 @@ static void asan_atexit() {
|
|||
__asan_print_accumulated_stats();
|
||||
}
|
||||
|
||||
void CheckFailed(const char *cond, const char *file, int line) {
|
||||
Report("CHECK failed: %s at %s:%d\n", cond, file, line);
|
||||
PRINT_CURRENT_STACK();
|
||||
ShowStatsAndAbort();
|
||||
}
|
||||
|
||||
} // namespace __asan
|
||||
|
||||
// ---------------------- Interface ---------------- {{{1
|
||||
|
|
|
@ -20,10 +20,6 @@
|
|||
|
||||
namespace __sanitizer {
|
||||
|
||||
// NOTE: Functions below must be defined in each run-time. {{{
|
||||
void NORETURN Die();
|
||||
// }}}
|
||||
|
||||
// Constants.
|
||||
const uptr kWordSize = __WORDSIZE / 8;
|
||||
const uptr kWordSizeInBits = 8 * kWordSize;
|
||||
|
|
|
@ -60,7 +60,14 @@ typedef unsigned long DWORD; // NOLINT
|
|||
# endif
|
||||
#endif // __WORDSIZE
|
||||
|
||||
// Raw check.
|
||||
// NOTE: Functions below must be defined in each run-time.
|
||||
namespace __sanitizer {
|
||||
void NORETURN Die();
|
||||
void NORETURN CheckFailed(const char *file, int line, const char *cond,
|
||||
u64 v1, u64 v2);
|
||||
} // namespace __sanitizer
|
||||
|
||||
// Check macro
|
||||
#define RAW_CHECK_MSG(expr, msg) do { \
|
||||
if (!(expr)) { \
|
||||
RawWrite(msg); \
|
||||
|
@ -70,4 +77,22 @@ typedef unsigned long DWORD; // NOLINT
|
|||
|
||||
#define RAW_CHECK(expr) RAW_CHECK_MSG(expr, #expr)
|
||||
|
||||
#define CHECK_IMPL(c1, op, c2) \
|
||||
do { \
|
||||
__sanitizer::u64 v1 = (u64)(c1); \
|
||||
__sanitizer::u64 v2 = (u64)(c2); \
|
||||
if (!(v1 op v2)) \
|
||||
__sanitizer::CheckFailed(__FILE__, __LINE__, \
|
||||
"(" #c1 ") " #op " (" #c2 ")", v1, v2); \
|
||||
} while (false) \
|
||||
/**/
|
||||
|
||||
#define CHECK(a) CHECK_IMPL((a), !=, 0)
|
||||
#define CHECK_EQ(a, b) CHECK_IMPL((a), ==, (b))
|
||||
#define CHECK_NE(a, b) CHECK_IMPL((a), !=, (b))
|
||||
#define CHECK_LT(a, b) CHECK_IMPL((a), <, (b))
|
||||
#define CHECK_LE(a, b) CHECK_IMPL((a), <=, (b))
|
||||
#define CHECK_GT(a, b) CHECK_IMPL((a), >, (b))
|
||||
#define CHECK_GE(a, b) CHECK_IMPL((a), >=, (b))
|
||||
|
||||
#endif // SANITIZER_DEFS_H
|
||||
|
|
|
@ -52,24 +52,6 @@ const bool kCollectStats = true;
|
|||
const bool kCollectStats = false;
|
||||
#endif
|
||||
|
||||
#define CHECK_IMPL(c1, op, c2) \
|
||||
do { \
|
||||
__sanitizer::u64 v1 = (u64)(c1); \
|
||||
__sanitizer::u64 v2 = (u64)(c2); \
|
||||
if (!(v1 op v2)) \
|
||||
__tsan::CheckFailed(__FILE__, __LINE__, \
|
||||
"(" #c1 ") " #op " (" #c2 ")", v1, v2); \
|
||||
} while (false) \
|
||||
/**/
|
||||
|
||||
#define CHECK(a) CHECK_IMPL((a), !=, 0)
|
||||
#define CHECK_EQ(a, b) CHECK_IMPL((a), ==, (b))
|
||||
#define CHECK_NE(a, b) CHECK_IMPL((a), !=, (b))
|
||||
#define CHECK_LT(a, b) CHECK_IMPL((a), <, (b))
|
||||
#define CHECK_LE(a, b) CHECK_IMPL((a), <=, (b))
|
||||
#define CHECK_GT(a, b) CHECK_IMPL((a), >, (b))
|
||||
#define CHECK_GE(a, b) CHECK_IMPL((a), >=, (b))
|
||||
|
||||
#if TSAN_DEBUG
|
||||
#define DCHECK(a) CHECK(a)
|
||||
#define DCHECK_EQ(a, b) CHECK_EQ(a, b)
|
||||
|
@ -88,8 +70,6 @@ const bool kCollectStats = false;
|
|||
#define DCHECK_GE(a, b)
|
||||
#endif
|
||||
|
||||
void CheckFailed(const char *file, int line, const char *cond, u64 v1, u64 v2);
|
||||
|
||||
// The following "build consistency" machinery ensures that all source files
|
||||
// are built in the same configuration. Inconsistent builds lead to
|
||||
// hard to debug crashes.
|
||||
|
|
|
@ -22,6 +22,18 @@
|
|||
#include "tsan_flags.h"
|
||||
#include "tsan_placement_new.h"
|
||||
|
||||
namespace __sanitizer {
|
||||
using namespace __tsan;
|
||||
|
||||
void CheckFailed(const char *file, int line, const char *cond, u64 v1, u64 v2) {
|
||||
ScopedInRtl in_rtl;
|
||||
TsanPrintf("FATAL: ThreadSanitizer CHECK failed: %s:%d \"%s\" (%zx, %zx)\n",
|
||||
file, line, cond, (uptr)v1, (uptr)v2);
|
||||
Die();
|
||||
}
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
||||
namespace __tsan {
|
||||
|
||||
// Can be overriden by an application/test to intercept reports.
|
||||
|
@ -347,11 +359,4 @@ void ReportRace(ThreadState *thr) {
|
|||
AddRacyStacks(thr, traces, addr_min, addr_max);
|
||||
}
|
||||
|
||||
void CheckFailed(const char *file, int line, const char *cond, u64 v1, u64 v2) {
|
||||
ScopedInRtl in_rtl;
|
||||
TsanPrintf("FATAL: ThreadSanitizer CHECK failed: %s:%d \"%s\" (%zx, %zx)\n",
|
||||
file, line, cond, (uptr)v1, (uptr)v2);
|
||||
Die();
|
||||
}
|
||||
|
||||
} // namespace __tsan
|
||||
|
|
Loading…
Reference in New Issue