changeset 2733:1c84350fdaf6 draft

Fix noinline definition so that it works for more compilers.
author Ricardo M. Correia <rcorreia@wizy.org>
date Thu, 31 May 2012 19:12:01 +0200
parents 07956769d72b
children 7f3b977e543c
files src/test/bignum_tests.cpp src/util.h
diffstat 2 files changed, 19 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/test/bignum_tests.cpp
+++ b/src/test/bignum_tests.cpp
@@ -2,6 +2,7 @@
 #include <climits>
 
 #include "bignum.h"
+#include "util.h"
 
 BOOST_AUTO_TEST_SUITE(bignum_tests)
 
@@ -29,9 +30,7 @@
 // Let's force this code not to be inlined, in order to actually
 // test a generic version of the function. This increases the chance
 // that -ftrapv will detect overflows.
-void mysetint64(CBigNum& num, int64 n) __attribute__((noinline));
-
-void mysetint64(CBigNum& num, int64 n)
+NOINLINE void mysetint64(CBigNum& num, int64 n)
 {
 	num.setint64(n);
 }
--- a/src/util.h
+++ b/src/util.h
@@ -43,6 +43,23 @@
 #define ARRAYLEN(array)     (sizeof(array)/sizeof((array)[0]))
 #define printf              OutputDebugStringF
 
+// Unfortunately there's no standard way of preventing a function from being
+// inlined, so we define a macro for it.
+//
+// You should use it like this:
+//   NOINLINE void function() {...}
+#if defined(__GNUC__)
+// This also works and will be defined for any compiler implementing gcc
+// extensions, such as clang and icc.
+#define NOINLINE __attribute__((noinline))
+#elif defined(_MSC_VER)
+#define NOINLINE __declspec(noinline)
+#else
+// We give out a warning because it impacts the correctness of one bignum test.
+#warning You should define NOINLINE for your compiler.
+#define NOINLINE
+#endif
+
 #ifdef snprintf
 #undef snprintf
 #endif