From fd9fa5454d47c60e41792c65beccf3988f3f2225 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 14 Nov 2023 01:05:28 -0500 Subject: [PATCH] compiler support for blackbox --- include/blt/std/assert.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/include/blt/std/assert.h b/include/blt/std/assert.h index b29db63..f26b485 100644 --- a/include/blt/std/assert.h +++ b/include/blt/std/assert.h @@ -14,6 +14,42 @@ namespace blt void b_assert_failed(const char* expression, const char* path, int line); void b_throw(const char* what, const char* path, int line); + +#if defined(__GNUC__) || defined(__llvm__) + #define BLT_ATTRIB_NO_INLINE __attribute__ ((noinline)) +#else + #if defined(_MSC_VER) && !defined(__INTEL_COMPILER) + #define BLT_ATTRIB_NO_INLINE __declspec(noinline) + #else + #define BLT_ATTRIB_NO_INLINE + #endif +#endif + + template + void BLT_ATTRIB_NO_INLINE black_box_ref(const T& val){ + volatile void* hell; + hell = (void*)&val; + } + + template + void BLT_ATTRIB_NO_INLINE black_box(T val){ + volatile void* hell2; + hell2 = (void*)&val; + } + + template + const T& BLT_ATTRIB_NO_INLINE black_box_ref_ret(const T& val){ + volatile void* hell; + hell = (void*)&val; + return val; + } + + template + T BLT_ATTRIB_NO_INLINE black_box_ret(T val){ + volatile void* hell2; + hell2 = (void*)&val; + return val; + } } // prints error with stack trace if assertion fails. Does not stop execution.