linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@ftp.linux.org.uk>
To: linux-sparse@vger.kernel.org
Subject: [PATCH 1/7] Fix handling of ident-less declarations
Date: Sat, 14 Feb 2009 12:25:05 +0000	[thread overview]
Message-ID: <E1LYJZx-0001ls-Nn@ZenIV.linux.org.uk> (raw)


The rule for ident-less declaration is
	declaration -> declaration-specifiers ;
not
	declaration -> declaration-specifiers abstract-declarator;

IOW, struct foo; is OK and so's struct foo {int x; int y;} (and even
simply int; is allowed by syntax - it's rejected by constraints, but
that's a separate story), but not struct foo (void); and its ilk.

See C99 6.7p1 for syntax; C90 is the same in that area and gcc also
behaves the same way.  Unlike gcc I've made it a warning (gcc produces
a hard error for those).

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 parse.c                    |   10 +++++++++-
 validation/missing-ident.c |   18 ++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletions(-)
 create mode 100644 validation/missing-ident.c

diff --git a/parse.c b/parse.c
index 73e7b65..6100fc2 100644
--- a/parse.c
+++ b/parse.c
@@ -2265,14 +2265,22 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis
 	token = declaration_specifiers(token, &ctype, 0);
 	decl = alloc_symbol(token->pos, SYM_NODE);
 	decl->ctype = ctype;
+	/* Just a type declaration? */
+	if (match_op(token, ';')) {
+		apply_modifiers(token->pos, &decl->ctype);
+		return token->next;
+	}
+
 	token = declarator(token, decl, &ident, 0);
 	apply_modifiers(token->pos, &decl->ctype);
 
 	decl->endpos = token->pos;
 
 	/* Just a type declaration? */
-	if (!ident)
+	if (!ident) {
+		warning(token->pos, "missing identifier in declaration");
 		return expect(token, ';', "end of type declaration");
+	}
 
 	/* type define declaration? */
 	is_typedef = (ctype.modifiers & MOD_TYPEDEF) != 0;
diff --git a/validation/missing-ident.c b/validation/missing-ident.c
new file mode 100644
index 0000000..ce73983
--- /dev/null
+++ b/validation/missing-ident.c
@@ -0,0 +1,18 @@
+int [2];
+int *;
+int (*);
+int ();
+int;
+struct foo;
+union bar {int x; int y;};
+struct baz {int x, :3, y:2;};
+/*
+ * check-name: handling of identifier-less declarations
+ *
+ * check-error-start
+missing-ident.c:1:8: warning: missing identifier in declaration
+missing-ident.c:2:6: warning: missing identifier in declaration
+missing-ident.c:3:8: warning: missing identifier in declaration
+missing-ident.c:4:7: warning: missing identifier in declaration
+ * check-error-end
+ */
-- 
1.5.6.6



             reply	other threads:[~2009-02-14 12:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-14 12:25 Al Viro [this message]
2009-02-14 18:45 ` [PATCH 1/7] Fix handling of ident-less declarations Christopher Li
2009-02-14 19:08   ` Al Viro
2009-02-14 20:31     ` Al Viro
2009-02-14 21:30       ` Al Viro
     [not found]     ` <70318cbf0902151633w77dc151ek7a6205430d2a19b8@mail.gmail.com>
     [not found]       ` <20090216014234.GS28946@ZenIV.linux.org.uk>
2009-02-16 11:14         ` 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=E1LYJZx-0001ls-Nn@ZenIV.linux.org.uk \
    --to=viro@ftp.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).