diff --git a/compiler-rt/lib/asan/asan_internal.h b/compiler-rt/lib/asan/asan_internal.h index 48818a1b1345..f9794315aca0 100644 --- a/compiler-rt/lib/asan/asan_internal.h +++ b/compiler-rt/lib/asan/asan_internal.h @@ -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])) diff --git a/compiler-rt/lib/asan/asan_rtl.cc b/compiler-rt/lib/asan/asan_rtl.cc index 301e34916524..8d156c055a9c 100644 --- a/compiler-rt/lib/asan/asan_rtl.cc +++ b/compiler-rt/lib/asan/asan_rtl.cc @@ -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 diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index b7c77e90fcdd..198ed63c4112 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -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; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h index 654947b6b3fc..cddd9a81aeae 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h @@ -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 diff --git a/compiler-rt/lib/tsan/rtl/tsan_defs.h b/compiler-rt/lib/tsan/rtl/tsan_defs.h index d3c748bd57cc..64e18f117213 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_defs.h +++ b/compiler-rt/lib/tsan/rtl/tsan_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. diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc index daa51b21f62f..ab2dc1e7488b 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc @@ -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