]> Savannah Git Hosting - gnulib.git/commitdiff
explicit_bzero: Add fallback for other compilers.
authorBastien Roucariès <rouca@debian.org>
Sat, 23 Jan 2021 13:31:44 +0000 (14:31 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 23 Jan 2021 13:31:44 +0000 (14:31 +0100)
* lib/explicit_bzero.c (explicit_bzero): For other compilers, invoke
memset through a volatile function pointer.

ChangeLog
lib/explicit_bzero.c

index e7101e1bf19fe191258de37591b1cd07b289f754..b1b81353e6bad26290677c15608b69b38bba42a6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2021-01-23  Bastien Roucariès  <rouca@debian.org>
 
+       explicit_bzero: Add fallback for other compilers.
+       * lib/explicit_bzero.c (explicit_bzero): For other compilers, invoke
+       memset through a volatile function pointer.
+
        explicit_bzero: Add support for clang.
        * lib/explicit_bzero.c (explicit_bzero): Add a compiler barrier for
        clang.
index 4eb057462bf7995c447dfb205b099a1b64cb3fde..2906c04d0fca0028478a6b50651e8495d82e48ac 100644 (file)
@@ -54,17 +54,21 @@ explicit_bzero (void *s, size_t len)
   explicit_memset (s, '\0', len);
 #elif HAVE_MEMSET_S
   (void) memset_s (s, len, '\0', len);
-#else
+#elif defined __GNUC__ && !defined __clang__
   memset (s, '\0', len);
-# if defined __GNUC__ && !defined __clang__
   /* Compiler barrier.  */
   asm volatile ("" ::: "memory");
-# elif defined __clang__
+#elif defined __clang__
+  memset (s, '\0', len);
   /* Compiler barrier.  */
   /* With asm ("" ::: "memory") LLVM analyzes uses of 's' and finds that the
      whole thing is dead and eliminates it.  Use 'g' to work around this
      problem.  See <https://bugs.llvm.org/show_bug.cgi?id=15495#c11>.  */
   __asm__ volatile ("" : : "g"(s) : "memory");
-# endif
+#else
+  /* Invoke memset through a volatile function pointer.  This defeats compiler
+     optimizations.  */
+  void * (* const volatile volatile_memset) (void *, int, size_t) = memset;
+  (void) volatile_memset (s, '\0', len);
 #endif
 }