mirror of
https://github.com/google/benchmark.git
synced 2025-01-15 22:30:52 +08:00
add workaround to DoNotOptimize(...) for clang inline assembly bug.
This commit is contained in:
parent
b5dd1506d8
commit
805145847b
@ -190,10 +190,19 @@ void UseCharPointer(char const volatile*);
|
|||||||
// expression from being optimized away by the compiler. This function is
|
// expression from being optimized away by the compiler. This function is
|
||||||
// intented to add little to no overhead.
|
// intented to add little to no overhead.
|
||||||
// See: http://stackoverflow.com/questions/28287064
|
// 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>
|
template <class Tp>
|
||||||
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
|
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
|
#else
|
||||||
template <class Tp>
|
template <class Tp>
|
||||||
|
Loading…
Reference in New Issue
Block a user