From: Al Viro <viro@ZenIV.linux.org.uk>
To: linux-sparse@vger.kernel.org
Subject: [PATCH] Fix type_info_expression()
Date: Mon, 2 Feb 2009 07:31:51 +0000 [thread overview]
Message-ID: <20090202073151.GC28946@ZenIV.linux.org.uk> (raw)
sizeof (typename){initializers}.foo is nice and valid C99 - it's parsed
as sizeof primary.foo <- sizeof postfix.foo <- sizeof postfix <- sizeof unary
<- unary. Current type_info_expression() stops too early.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
expression.c | 12 ++++++++++--
validation/sizeof-compound-postfix.c | 8 ++++++++
2 files changed, 18 insertions(+), 2 deletions(-)
create mode 100644 validation/sizeof-compound-postfix.c
diff --git a/expression.c b/expression.c
index f634b07..124a8ec 100644
--- a/expression.c
+++ b/expression.c
@@ -594,12 +594,14 @@ static struct token *type_info_expression(struct token *token,
struct expression **tree, int type)
{
struct expression *expr = alloc_expression(token->pos, type);
+ struct token *p;
*tree = expr;
expr->flags = Int_const_expr; /* XXX: VLA support will need that changed */
token = token->next;
if (!match_op(token, '(') || !lookup_type(token->next))
return unary_expression(token, &expr->cast_expression);
+ p = token;
token = typename(token->next, &expr->cast_type, 0);
if (!match_op(token, ')')) {
@@ -616,8 +618,14 @@ static struct token *type_info_expression(struct token *token,
* C99 ambiguity: the typename might have been the beginning
* of a typed initializer expression..
*/
- if (match_op(token, '{'))
- token = initializer(&expr->cast_expression, token);
+ if (match_op(token, '{')) {
+ struct expression *cast = alloc_expression(p->pos, EXPR_CAST);
+ cast->cast_type = expr->cast_type;
+ expr->cast_type = NULL;
+ expr->cast_expression = cast;
+ token = initializer(&cast->cast_expression, token);
+ token = postfix_expression(token, &expr->cast_expression, cast);
+ }
return token;
}
diff --git a/validation/sizeof-compound-postfix.c b/validation/sizeof-compound-postfix.c
new file mode 100644
index 0000000..3b716fe
--- /dev/null
+++ b/validation/sizeof-compound-postfix.c
@@ -0,0 +1,8 @@
+struct foo {int x, y;};
+static int a(void)
+{
+ return sizeof (struct foo){0,1}.y;
+}
+/*
+ * check-name: Handling of sizeof compound-literal . member
+ */
--
1.5.6.6
next reply other threads:[~2009-02-02 7:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-02 7:31 Al Viro [this message]
2009-02-05 18:29 ` [PATCH] Fix type_info_expression() Christopher Li
2009-02-05 19:23 ` Al Viro
2009-02-05 20:21 ` Christopher Li
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=20090202073151.GC28946@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).