From ac8adb391d472cfa4154d8ec930e950be65a11d1 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Bastien=20Roucari=C3=A8s?= <rouca@debian.org>
Date: Sat, 23 Jan 2021 11:22:10 +0000
Subject: [PATCH] explicit_bzero: Add support for clang.

* lib/explicit_bzero.c (explicit_bzero): Add a compiler barrier for
clang.
---
 ChangeLog            | 6 ++++++
 lib/explicit_bzero.c | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 8fa2e1535f..e7101e1bf1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2021-01-23  Bastien Roucariès  <rouca@debian.org>
+
+	explicit_bzero: Add support for clang.
+	* lib/explicit_bzero.c (explicit_bzero): Add a compiler barrier for
+	clang.
+
 2021-01-21  Paul Eggert  <eggert@cs.ucla.edu>
 
 	Port FALLTHROUGH to clang 3.4 and earlier
diff --git a/lib/explicit_bzero.c b/lib/explicit_bzero.c
index 87fadba81a..4eb057462b 100644
--- a/lib/explicit_bzero.c
+++ b/lib/explicit_bzero.c
@@ -59,6 +59,12 @@ explicit_bzero (void *s, size_t len)
 # if defined __GNUC__ && !defined __clang__
   /* Compiler barrier.  */
   asm volatile ("" ::: "memory");
+# elif defined __clang__
+  /* 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
 #endif
 }
-- 
2.39.5