sanitizer_common: Implement COMPILER_CHECK using static_assert
authorNico Weber <thakis@chromium.org>
Fri, 4 Sep 2020 15:05:52 +0000 (11:05 -0400)
committerNico Weber <thakis@chromium.org>
Fri, 4 Sep 2020 15:05:54 +0000 (11:05 -0400)
Since this is an internal header, we can just assume static_assert
exists.

If this doesn't upset any bots, I'll replace all uses of
COMPILER_CHECK in a follow-up.

compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h

index d0ffc79..84973ee 100644 (file)
@@ -333,14 +333,10 @@ void NORETURN CheckFailed(const char *file, int line, const char *cond,
 
 #define UNIMPLEMENTED() UNREACHABLE("unimplemented")
 
-#define COMPILER_CHECK(pred) IMPL_COMPILER_ASSERT(pred, __LINE__)
+#define COMPILER_CHECK(pred) static_assert(pred, "")
 
 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
 
-#define IMPL_PASTE(a, b) a##b
-#define IMPL_COMPILER_ASSERT(pred, line) \
-    typedef char IMPL_PASTE(assertion_failed_##_, line)[2*(int)(pred)-1]
-
 // Limits for integral types. We have to redefine it in case we don't
 // have stdint.h (like in Visual Studio 9).
 #undef __INT64_C