diff options
author | Elliott Hughes <enh@google.com> | 2020-10-22 13:22:35 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2020-10-22 13:22:35 -0700 |
commit | 7cda75f1d3e147a300d7ff4d690b13e36bff5c5d (patch) | |
tree | 0d4390746ae35c223432964fce5041d3dc280bed /tests/fenv_test.cpp | |
parent | 9aa6b15d799ac246e842552fca555920a93ce46b (diff) | |
download | bionic-7cda75f1d3e147a300d7ff4d690b13e36bff5c5d.tar.gz |
Add DoNotOptimize and use it in tests.
Bug: http://b/148307629
Test: treehugger
Change-Id: I3b1726ae55116f6553ea38fe163abdde179c21f0
Diffstat (limited to 'tests/fenv_test.cpp')
-rw-r--r-- | tests/fenv_test.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/tests/fenv_test.cpp b/tests/fenv_test.cpp index e983a1c08..89c7fd5c9 100644 --- a/tests/fenv_test.cpp +++ b/tests/fenv_test.cpp @@ -22,19 +22,20 @@ #include <stdint.h> static void TestRounding(float expectation1, float expectation2) { - // volatile to prevent compiler optimizations. + // Volatile to prevent compile-time evaluation. volatile float f = 1.968750f; volatile float m = 0x1.0p23f; - volatile float x = f + m; + float x; + DoNotOptimize(x = f + m); ASSERT_FLOAT_EQ(expectation1, x); - x = x - m; + DoNotOptimize(x = x - m); ASSERT_EQ(expectation2, x); } static void DivideByZero() { - // volatile to prevent compiler optimizations. + // Volatile to prevent compile-time evaluation. volatile float zero = 0.0f; - volatile float result __attribute__((unused)) = 123.0f / zero; + DoNotOptimize(123.0f / zero); } TEST(fenv, fesetround_fegetround_FE_TONEAREST) { |