aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPekka Enberg <penberg@kernel.org>2011-08-22 16:57:29 +0300
committerChristopher Li <sparse@chrisli.org>2011-08-25 20:31:35 -0700
commit8376ab091a5ab1850797fd203f31ae97a1287b23 (patch)
tree56c0b18c47bb3058b146c47374e20678b37980fd
parenta7a00d5108c36b8baaf54814aa1f42583dabc754 (diff)
downloadsparse-8376ab091a5ab1850797fd203f31ae97a1287b23.tar.gz
sparse: Fix __builtin_safe_p for pure and const functions
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> Signed-off-by: Christopher Li <sparse@chrisli.org>
-rw-r--r--expand.c3
-rw-r--r--parse.c10
-rw-r--r--show-parse.c1
-rw-r--r--symbol.h1
-rw-r--r--validation/builtin_safe1.c1
5 files changed, 10 insertions, 6 deletions
diff --git a/expand.c b/expand.c
index b965dc35..63a90752 100644
--- a/expand.c
+++ b/expand.c
@@ -791,6 +791,9 @@ static int expand_symbol_call(struct expression *expr, int cost)
if (ctype->op && ctype->op->expand)
return ctype->op->expand(expr, cost);
+ if (ctype->ctype.modifiers & MOD_PURE)
+ return 0;
+
return SIDE_EFFECTS;
}
diff --git a/parse.c b/parse.c
index aea4a1db..bd42180d 100644
--- a/parse.c
+++ b/parse.c
@@ -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",
@@ -547,8 +549,6 @@ const char *ignored_attributes[] = {
"nothrow",
"__nothrow",
"__nothrow__",
- "pure",
- "__pure__",
"regparm",
"__regparm__",
"section",
diff --git a/show-parse.c b/show-parse.c
index a5beafee..1333e301 100644
--- a/show-parse.c
+++ b/show-parse.c
@@ -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++) {
diff --git a/symbol.h b/symbol.h
index 2b8f20e3..1e745799 100644
--- a/symbol.h
+++ b/symbol.h
@@ -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
diff --git a/validation/builtin_safe1.c b/validation/builtin_safe1.c
index 2f6c9d27..eeddcc82 100644
--- a/validation/builtin_safe1.c
+++ b/validation/builtin_safe1.c
@@ -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