From: Nicolai Stange <nicstange@gmail.com>
To: linux-sparse@vger.kernel.org
Subject: [PATCH RFC 13/13] symbol: do not inherit storage modifiers from base types at examination
Date: Thu, 23 Jul 2015 01:24:41 +0200 [thread overview]
Message-ID: <87bnf3ixmu.fsf@gmail.com> (raw)
Consider the following code snippet:
static inline foo(int dummy, ...) {}
static int a = 0;
static void bar(void)
{
foo(0, a);
}
Sparse moans:
test.c:5:9: warning: initializer for static storage duration object
is not a constant expression
The cause can be tracked down as follows:
The anonymous node created by inline_function() for the variadic
argument will get assigned to its base_type whatever the passed
expression's ctype is. For the special case of a primary expression
referencing a symbol, this ctype is the referenced symbol itself.
Furthermore, inline_function() sets that symbol node's initializer
to this expression.
Now, when the anonymous symbol node is evaluated, its base_type is
handled in examine_base_type(). This applies the base_type's modifiers,
i.e. the referenced symbol's MOD_STATIC in this case, to the inheriting
ctype, that of the anonymous node, itself.
This in turn instructs the evaluation of the symbol's initializer to
allow constant expressions only.
Do not inherit a base_type's storage related modifiers in
examine_base_type().
Signed-off-by: Nicolai Stange <nicstange@gmail.com>
---
symbol.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/symbol.c b/symbol.c
index cbc846b..605ec1c 100644
--- a/symbol.c
+++ b/symbol.c
@@ -214,7 +214,8 @@ static struct symbol *examine_base_type(struct symbol *sym)
if (!base_type || base_type->type == SYM_PTR)
return base_type;
sym->ctype.as |= base_type->ctype.as;
- sym->ctype.modifiers |= base_type->ctype.modifiers & MOD_PTRINHERIT;
+ sym->ctype.modifiers |= base_type->ctype.modifiers & MOD_PTRINHERIT &
+ ~MOD_STORAGE;
concat_ptr_list((struct ptr_list *)base_type->ctype.contexts,
(struct ptr_list **)&sym->ctype.contexts);
if (base_type->type == SYM_NODE) {
--
2.4.5
reply other threads:[~2015-07-22 23:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bnf3ixmu.fsf@gmail.com \
--to=nicstange@gmail.com \
--cc=linux-sparse@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.