Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
fork

Configure Feed

Select the types of activity you want to include in your feed.

include/linux/compiler*.h: fix OPTIMIZER_HIDE_VAR

Since commit 815f0ddb346c ("include/linux/compiler*.h: make compiler-*.h
mutually exclusive") clang no longer reuses the OPTIMIZER_HIDE_VAR macro
from compiler-gcc - instead it gets the version in
include/linux/compiler.h. Unfortunately that version doesn't actually
prevent compiler from optimizing out the variable.

Fix up by moving the macro out from compiler-gcc.h to compiler.h.
Compilers without incline asm support will keep working
since it's protected by an ifdef.

Also fix up comments to match reality since we are no longer overriding
any macros.

Build-tested with gcc and clang.

Fixes: 815f0ddb346c ("include/linux/compiler*.h: make compiler-*.h mutually exclusive")
Cc: Eli Friedman <efriedma@codeaurora.org>
Cc: Joe Perches <joe@perches.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>

authored by

Michael S. Tsirkin and committed by
Miguel Ojeda
3e2ffd65 bfeffd15

+6 -11
+2 -3
include/linux/compiler-clang.h
··· 3 3 #error "Please don't include <linux/compiler-clang.h> directly, include <linux/compiler.h> instead." 4 4 #endif 5 5 6 - /* Some compiler specific definitions are overwritten here 7 - * for Clang compiler 8 - */ 6 + /* Compiler specific definitions for Clang compiler */ 7 + 9 8 #define uninitialized_var(x) x = *(&(x)) 10 9 11 10 /* same as gcc, this was present in clang-2.6 so we can assume it works
-4
include/linux/compiler-gcc.h
··· 58 58 (typeof(ptr)) (__ptr + (off)); \ 59 59 }) 60 60 61 - /* Make the optimizer believe the variable can be manipulated arbitrarily. */ 62 - #define OPTIMIZER_HIDE_VAR(var) \ 63 - __asm__ ("" : "=r" (var) : "0" (var)) 64 - 65 61 /* 66 62 * A trick to suppress uninitialized variable warning without generating any 67 63 * code
+1 -3
include/linux/compiler-intel.h
··· 5 5 6 6 #ifdef __ECC 7 7 8 - /* Some compiler specific definitions are overwritten here 9 - * for Intel ECC compiler 10 - */ 8 + /* Compiler specific definitions for Intel ECC compiler */ 11 9 12 10 #include <asm/intrinsics.h> 13 11
+3 -1
include/linux/compiler.h
··· 161 161 #endif 162 162 163 163 #ifndef OPTIMIZER_HIDE_VAR 164 - #define OPTIMIZER_HIDE_VAR(var) barrier() 164 + /* Make the optimizer believe the variable can be manipulated arbitrarily. */ 165 + #define OPTIMIZER_HIDE_VAR(var) \ 166 + __asm__ ("" : "=r" (var) : "0" (var)) 165 167 #endif 166 168 167 169 /* Not-quite-unique ID. */