]> Savannah Git Hosting - gnulib.git/commitdiff
explicit_bzero-tests: pacify GCC better
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 18 Jul 2021 19:08:56 +0000 (14:08 -0500)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 18 Jul 2021 19:10:09 +0000 (14:10 -0500)
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
tests/test-explicit_bzero.c

index c508084379e3e6597c5c39b809d84d5fa038be02..d175c39af5e0dd3b16e8990482b2d041d081984a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2021-07-18  Paul Eggert  <eggert@cs.ucla.edu>
+
+       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  <eggert@cs.ucla.edu>
 
        memrchr-tests: pacify GCC
index c42aba93fa8eabad1b8b9321fe75344f47734b62..14f0ead2b73e1b686e31f7cd4eee35ac74520e02 100644 (file)
@@ -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;