From 7cda75f1d3e147a300d7ff4d690b13e36bff5c5d Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 22 Oct 2020 13:22:35 -0700 Subject: Add DoNotOptimize and use it in tests. Bug: http://b/148307629 Test: treehugger Change-Id: I3b1726ae55116f6553ea38fe163abdde179c21f0 --- tests/fenv_test.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'tests/fenv_test.cpp') 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 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) { -- cgit v1.2.3