mirror of https://github.com/google/benchmark.git
Fix pass rvalue to DoNotOptimize (#1608)
* Fix pass rvalue to DoNotOptimize #1584 * Add test
This commit is contained in:
parent
604f6fd3f4
commit
df9a99d998
|
@ -465,7 +465,13 @@ inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
|
|||
}
|
||||
|
||||
template <class Tp>
|
||||
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp& value) {
|
||||
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(
|
||||
#ifdef BENCHMARK_HAS_CXX11
|
||||
Tp&& value
|
||||
#else
|
||||
Tp& value
|
||||
#endif
|
||||
) {
|
||||
#if defined(__clang__)
|
||||
asm volatile("" : "+r,m"(value) : : "memory");
|
||||
#else
|
||||
|
@ -501,7 +507,7 @@ template <class Tp>
|
|||
inline BENCHMARK_ALWAYS_INLINE
|
||||
typename std::enable_if<std::is_trivially_copyable<Tp>::value &&
|
||||
(sizeof(Tp) <= sizeof(Tp*))>::type
|
||||
DoNotOptimize(Tp& value) {
|
||||
DoNotOptimize(Tp&& value) {
|
||||
asm volatile("" : "+m,r"(value) : : "memory");
|
||||
}
|
||||
|
||||
|
@ -509,7 +515,7 @@ template <class Tp>
|
|||
inline BENCHMARK_ALWAYS_INLINE
|
||||
typename std::enable_if<!std::is_trivially_copyable<Tp>::value ||
|
||||
(sizeof(Tp) > sizeof(Tp*))>::type
|
||||
DoNotOptimize(Tp& value) {
|
||||
DoNotOptimize(Tp&& value) {
|
||||
asm volatile("" : "+m"(value) : : "memory");
|
||||
}
|
||||
|
||||
|
@ -526,7 +532,13 @@ inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
|
|||
}
|
||||
|
||||
template <class Tp>
|
||||
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp& value) {
|
||||
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(
|
||||
#ifdef BENCHMARK_HAS_CXX11
|
||||
Tp&& value
|
||||
#else
|
||||
Tp& value
|
||||
#endif
|
||||
) {
|
||||
asm volatile("" : "+m"(value) : : "memory");
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -61,4 +61,9 @@ int main(int, char*[]) {
|
|||
// These tests are to e
|
||||
BitRef lval = BitRef::Make();
|
||||
benchmark::DoNotOptimize(lval);
|
||||
|
||||
#ifdef BENCHMARK_HAS_CXX11
|
||||
// Check that accept rvalue.
|
||||
benchmark::DoNotOptimize(BitRef::Make());
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue