[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/2] Support clang for explicit_bzero
From: |
Bruno Haible |
Subject: |
Re: [PATCH 1/2] Support clang for explicit_bzero |
Date: |
Sat, 23 Jan 2021 14:25:57 +0100 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-197-generic; KDE/5.18.0; x86_64; ; ) |
> diff --git a/lib/explicit_bzero.c b/lib/explicit_bzero.c
> index 87fadba81a..71a1cca3b0 100644
> --- a/lib/explicit_bzero.c
> +++ b/lib/explicit_bzero.c
> @@ -56,9 +56,19 @@ explicit_bzero (void *s, size_t len)
> (void) memset_s (s, len, '\0', len);
> #else
> memset (s, '\0', len);
> -# if defined __GNUC__ && !defined __clang__
> - /* Compiler barrier. */
> +# if defined __GNUC__
> +/* Compiler barrier. */
> +# if !defined __clang__
> asm volatile ("" ::: "memory");
> +# else
> + /* See https://bugs.llvm.org/show_bug.cgi?id=15495#c11
> + with asm("" ::: "memory") LLVM analyzes uses of 's'
> + and finds that the whole thing is dead and eliminates it.
> +
> + Using g workarround this problem
> + */
> + __asm__ volatile("" : : "g"(s) : "memory");
> +# endif
> # endif
> #endif
> }
Thanks. I applied this with two changes:
- Make it work also with clang on Windows. Recall that clang on Windows
does not define __GNUC__ [1].
- Use a gnulib-style ChangeLog entry.
Bruno
[1] https://lists.gnu.org/archive/html/bug-gnulib/2020-08/msg00038.html