If __builtin_is_lvalue() is available, use it with __is_lvalue(). There
is patch to Clang to provide this builtin now[1].

Link: https://github.com/kees/llvm-project/commits/builtin_is_lvalue/ [1]
Signed-off-by: Kees Cook <[email protected]>
---
Cc: Miguel Ojeda <[email protected]>
Cc: Nathan Chancellor <[email protected]>
Cc: Marco Elver <[email protected]>
Cc: Nick Desaulniers <[email protected]>
Cc: Przemek Kitszel <[email protected]>
---
 include/linux/compiler_types.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index e09d323be845..eb016808dfa8 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -468,6 +468,16 @@ struct ftrace_likely_data {
 #define __annotated(var, attr) __builtin_has_attribute(var, attr)
 #endif
 
+/*
+ * Determine if a given expression is an lvalue for potential
+ * assignment. Without the builtin, report nothing is an lvalue.
+ */
+#if __has_builtin(__builtin_is_lvalue)
+#define __is_lvalue(expr)      __builtin_is_lvalue(expr)
+#else
+#define __is_lvalue(expr)      false
+#endif
+
 /*
  * Some versions of gcc do not mark 'asm goto' volatile:
  *
-- 
2.34.1


Reply via email to