René Rebe noticed that in a slightly modified version of test-floorf-ieee.c, "gcc -O2" inlines the 'floorf' function, despite the conditional expression initializer. The test is pointless with this inlining. This patch provides a defense against it.
2023-11-24 Bruno Haible <br...@clisp.org> floorf, ceilf tests: Strengthen against compiler optimizations. Reported by René Rebe <r...@t2-project.org>. * tests/test-floorf1.c (main): Mark my_floorf as 'volatile'. * tests/test-floorf-ieee.c (main): Likewise. * tests/test-ceilf1.c (main): Mark my_ceilf as 'volatile'. * tests/test-ceilf-ieee.c (main): Likewise. diff --git a/tests/test-ceilf-ieee.c b/tests/test-ceilf-ieee.c index 02edc0d92a..bfdceee1c5 100644 --- a/tests/test-ceilf-ieee.c +++ b/tests/test-ceilf-ieee.c @@ -38,7 +38,7 @@ dummy (float f) int main (int argc, _GL_UNUSED char **argv) { - float (*my_ceilf) (float) = argc ? ceilf : dummy; + float (* volatile my_ceilf) (float) = argc ? ceilf : dummy; /* See IEEE 754, section 6.3: "the sign of the result of the round floating-point number to diff --git a/tests/test-ceilf1.c b/tests/test-ceilf1.c index 61a4ae99b5..2ad2b30fb0 100644 --- a/tests/test-ceilf1.c +++ b/tests/test-ceilf1.c @@ -43,7 +43,7 @@ dummy (float f) int main (int argc, _GL_UNUSED char **argv) { - float (*my_ceilf) (float) = argc ? ceilf : dummy; + float (* volatile my_ceilf) (float) = argc ? ceilf : dummy; /* Zero. */ ASSERT (my_ceilf (0.0f) == 0.0f); diff --git a/tests/test-floorf-ieee.c b/tests/test-floorf-ieee.c index 32ceb5b7b1..8b1a02ac89 100644 --- a/tests/test-floorf-ieee.c +++ b/tests/test-floorf-ieee.c @@ -38,7 +38,7 @@ dummy (float f) int main (int argc, _GL_UNUSED char **argv) { - float (*my_floorf) (float) = argc ? floorf : dummy; + float (* volatile my_floorf) (float) = argc ? floorf : dummy; /* See IEEE 754, section 6.3: "the sign of the result of the round floating-point number to diff --git a/tests/test-floorf1.c b/tests/test-floorf1.c index b2787f6ff3..39b7a48432 100644 --- a/tests/test-floorf1.c +++ b/tests/test-floorf1.c @@ -43,7 +43,7 @@ dummy (float f) int main (int argc, _GL_UNUSED char **argv) { - float (*my_floorf) (float) = argc ? floorf : dummy; + float (* volatile my_floorf) (float) = argc ? floorf : dummy; /* Zero. */ ASSERT (my_floorf (0.0f) == 0.0f);