@@ -785,6 +785,9 @@ static int expand_symbol_call(struct expression *expr, int cost)
struct expression *fn = expr->fn;
struct symbol *ctype = fn->ctype;
+ if (ctype->ctype.modifiers & MOD_PURE)
+ return 0;
+
if (fn->type != EXPR_PREOP)
return SIDE_EFFECTS;
@@ -463,6 +463,11 @@ static struct init_keyword {
{ "__transparent_union__", NS_KEYWORD, .op = &transparent_union_op },
{ "noreturn", NS_KEYWORD, MOD_NORETURN, .op = &attr_mod_op },
{ "__noreturn__", NS_KEYWORD, MOD_NORETURN, .op = &attr_mod_op },
+ { "pure", NS_KEYWORD, MOD_PURE, .op = &attr_mod_op },
+ {"__pure__", NS_KEYWORD, MOD_PURE, .op = &attr_mod_op },
+ {"const", NS_KEYWORD, MOD_PURE, .op = &attr_mod_op },
+ {"__const", NS_KEYWORD, MOD_PURE, .op = &attr_mod_op },
+ {"__const__", NS_KEYWORD, MOD_PURE, .op = &attr_mod_op },
{ "__mode__", NS_KEYWORD, .op = &mode_op },
{ "QI", NS_KEYWORD, MOD_CHAR, .op = &mode_QI_op },
@@ -494,9 +499,6 @@ const char *ignored_attributes[] = {
"__cdecl__",
"cold",
"__cold__",
- "const",
- "__const",
- "__const__",
"constructor",
"__constructor__",
"deprecated",
@@ -545,8 +547,6 @@ const char *ignored_attributes[] = {
"nothrow",
"__nothrow",
"__nothrow__",
- "pure",
- "__pure__",
"regparm",
"__regparm__",
"section",
@@ -131,6 +131,7 @@ const char *modifier_string(unsigned long mod)
{MOD_NORETURN, "[noreturn]"},
{MOD_EXPLICITLY_SIGNED, "[explicitly-signed]"},
{MOD_BITWISE, "[bitwise]"},
+ {MOD_PURE, "[pure]"},
};
for (i = 0; i < ARRAY_SIZE(mod_names); i++) {
@@ -198,6 +198,7 @@ struct symbol {
#define MOD_LONG 0x0400
#define MOD_LONGLONG 0x0800
#define MOD_LONGLONGLONG 0x1000
+#define MOD_PURE 0x2000
#define MOD_TYPEDEF 0x10000
@@ -26,7 +26,6 @@ static int foo(int x, int y)
/*
* check-name: __builtin_safe
- * check-known-to-fail
* check-error-start
builtin_safe1.c:13:3: warning: Macro argument with side effects: x++
builtin_safe1.c:14:3: warning: Macro argument with side effects: x+=1
This patch fixes __builtin_safe_p() to work properly for calls to pure functions. Cc: Christopher Li <sparse@chrisli.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Pekka Enberg <penberg@kernel.org> --- expand.c | 3 +++ parse.c | 10 +++++----- show-parse.c | 1 + symbol.h | 1 + validation/builtin_safe1.c | 1 - 5 files changed, 10 insertions(+), 6 deletions(-)