Commit d3082183 authored by Michael S. Tsirkin's avatar Michael S. Tsirkin Committed by Greg Kroah-Hartman

include/linux/compiler*.h: fix OPTIMIZER_HIDE_VAR

[ Upstream commit 3e2ffd65 ]

Since commit 815f0ddb ("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: 815f0ddb ("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: 's avatarNick Desaulniers <ndesaulniers@google.com>
Signed-off-by: 's avatarMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: Miguel Ojeda's avatarMiguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Signed-off-by: 's avatarSasha Levin <sashal@kernel.org>
parent 31369d8c
......@@ -3,9 +3,8 @@
#error "Please don't include <linux/compiler-clang.h> directly, include <linux/compiler.h> instead."
#endif
/* Some compiler specific definitions are overwritten here
* for Clang compiler
*/
/* Compiler specific definitions for Clang compiler */
#define uninitialized_var(x) x = *(&(x))
/* same as gcc, this was present in clang-2.6 so we can assume it works
......
......@@ -58,10 +58,6 @@
(typeof(ptr)) (__ptr + (off)); \
})
/* Make the optimizer believe the variable can be manipulated arbitrarily. */
#define OPTIMIZER_HIDE_VAR(var) \
__asm__ ("" : "=r" (var) : "0" (var))
/*
* A trick to suppress uninitialized variable warning without generating any
* code
......
......@@ -5,9 +5,7 @@
#ifdef __ECC
/* Some compiler specific definitions are overwritten here
* for Intel ECC compiler
*/
/* Compiler specific definitions for Intel ECC compiler */
#include <asm/intrinsics.h>
......
......@@ -161,7 +161,9 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
#endif
#ifndef OPTIMIZER_HIDE_VAR
#define OPTIMIZER_HIDE_VAR(var) barrier()
/* Make the optimizer believe the variable can be manipulated arbitrarily. */
#define OPTIMIZER_HIDE_VAR(var) \
__asm__ ("" : "=r" (var) : "0" (var))
#endif
/* Not-quite-unique ID. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment