add workaround to DoNotOptimize(...) for clang inline assembly bug.

This commit is contained in:
Eric Fiselier 2015-03-30 22:14:08 -04:00
parent b5dd1506d8
commit 805145847b

View File

@ -190,10 +190,19 @@ void UseCharPointer(char const volatile*);
// expression from being optimized away by the compiler. This function is
// intented to add little to no overhead.
// See: http://stackoverflow.com/questions/28287064
#if defined(__GNUC__)
#if defined(__clang__) && defined(__GNUC__)
// TODO(ericwf): Clang has a bug where it tries to always use a register
// even if value must be stored in memory. This causes codegen to fail.
// To work around this we remove the "r" modifier so the operand is always
// loaded into memory.
template <class Tp>
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
asm volatile("" : "+r" (const_cast<Tp&>(value)));
asm volatile("" : "+m" (const_cast<Tp&>(value)));
}
#elif defined(__GNUC__)
template <class Tp>
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
asm volatile("" : "+rm" (const_cast<Tp&>(value)));
}
#else
template <class Tp>