From f9803478355d038aa060d71bdd9eddf2bd43325f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 18 Jul 2021 14:08:56 -0500 Subject: [PATCH] explicit_bzero-tests: pacify GCC better Problem reported by Bruno Haible in: https://lists.gnu.org/r/bug-gnulib/2021-07/msg00039.html * tests/test-explicit_bzero.c: Ignore -Wmaybe-uninitialized. (stackbuf): Remove this static pointer, reverting recent change. (do_secret_stuff, test_stack): Revert these related changes too. --- ChangeLog | 9 +++++++++ tests/test-explicit_bzero.c | 16 +++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index c50808437..d175c39af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2021-07-18 Paul Eggert + + explicit_bzero-tests: pacify GCC better + Problem reported by Bruno Haible in: + https://lists.gnu.org/r/bug-gnulib/2021-07/msg00039.html + * tests/test-explicit_bzero.c: Ignore -Wmaybe-uninitialized. + (stackbuf): Remove this static pointer, reverting recent change. + (do_secret_stuff, test_stack): Revert these related changes too. + 2021-07-17 Paul Eggert memrchr-tests: pacify GCC diff --git a/tests/test-explicit_bzero.c b/tests/test-explicit_bzero.c index c42aba93f..14f0ead2b 100644 --- a/tests/test-explicit_bzero.c +++ b/tests/test-explicit_bzero.c @@ -32,6 +32,12 @@ SIGNATURE_CHECK (explicit_bzero, void, (void *, size_t)); #include "vma-iter.h" #include "macros.h" +/* Suppress GCC warning that do_secret_stuff (2) reads uninitialized + local storage. */ +#if 4 < __GNUC__ + (3 <= __GNUC_MINOR__) +# pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif + #define SECRET "xyzzy1729" #define SECRET_SIZE 9 @@ -126,12 +132,14 @@ test_heap (void) /* There are two passes: 1. Put a secret in memory and invoke explicit_bzero on it. 2. Verify that the memory has been erased. - Access the memory via a volatile pointer, so the compiler - does not assume the pointer's value and optimize away accesses. */ -static char *volatile stackbuf; + Implement them in the same function, so that they access the same memory + range on the stack. That way, the test verifies that the compiler + does not eliminate a call to explicit_bzero, even if data flow analysis + reveals that the stack area is dead at the end of the function. */ static int _GL_ATTRIBUTE_NOINLINE do_secret_stuff (volatile int pass) { + char stackbuf[SECRET_SIZE]; if (pass == 1) { memcpy (stackbuf, SECRET, SECRET_SIZE); @@ -147,8 +155,6 @@ do_secret_stuff (volatile int pass) static void test_stack (void) { - char stack_buffer[SECRET_SIZE]; - stackbuf = stack_buffer; int count = 0; int repeat; -- 2.25.1