Fix noinline definition so that it works for more compilers.

This commit is contained in:
Ricardo M. Correia 2012-05-31 19:12:01 +02:00
parent 5849bd472a
commit 78e851f94f
2 changed files with 19 additions and 3 deletions

View file

@ -2,6 +2,7 @@
#include <climits> #include <climits>
#include "bignum.h" #include "bignum.h"
#include "util.h"
BOOST_AUTO_TEST_SUITE(bignum_tests) BOOST_AUTO_TEST_SUITE(bignum_tests)
@ -29,9 +30,7 @@ BOOST_AUTO_TEST_SUITE(bignum_tests)
// Let's force this code not to be inlined, in order to actually // Let's force this code not to be inlined, in order to actually
// test a generic version of the function. This increases the chance // test a generic version of the function. This increases the chance
// that -ftrapv will detect overflows. // that -ftrapv will detect overflows.
void mysetint64(CBigNum& num, int64 n) __attribute__((noinline)); NOINLINE void mysetint64(CBigNum& num, int64 n)
void mysetint64(CBigNum& num, int64 n)
{ {
num.setint64(n); num.setint64(n);
} }

View file

@ -43,6 +43,23 @@ static const int64 CENT = 1000000;
#define ARRAYLEN(array) (sizeof(array)/sizeof((array)[0])) #define ARRAYLEN(array) (sizeof(array)/sizeof((array)[0]))
#define printf OutputDebugStringF #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 #ifdef snprintf
#undef snprintf #undef snprintf
#endif #endif