summaryrefslogtreecommitdiff
path: root/lib/explicit_bzero.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2021-01-23 11:35:44 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2021-01-23 11:37:49 -0800
commit7c9841b8428edfbc369eccf54788b668d4b27328 (patch)
treed0835a270d1ed4e02b920a8d9468f52f7f8570ea /lib/explicit_bzero.c
parent30d95d33737e4694b579c38328564716d10217b6 (diff)
downloademacs-7c9841b8428edfbc369eccf54788b668d4b27328.tar.gz
emacs-7c9841b8428edfbc369eccf54788b668d4b27328.tar.bz2
emacs-7c9841b8428edfbc369eccf54788b668d4b27328.zip
Update from Gnulib by running admin/merge-gnulib
Diffstat (limited to 'lib/explicit_bzero.c')
-rw-r--r--lib/explicit_bzero.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/explicit_bzero.c b/lib/explicit_bzero.c
index feea4446c06..f50ed0875d7 100644
--- a/lib/explicit_bzero.c
+++ b/lib/explicit_bzero.c
@@ -54,11 +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");
-# endif
+#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");
+#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
}