Re: [PATCH] parse: support c99 [static ...] in abstract array declarators

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 16, 2014 at 10:09 PM, Josh Triplett <josh@xxxxxxxxxxxxxxxx> wrote:
>> I could have sparse be just as strict as the standard, it just was just
>> (much) simpler to make it liberal in what it accepts. If you're fine with
>> some more verbose code, I'll put together something that is stricter.
>
> I'd suggest trying to match the standard in this case, or failing that
> match what GCC does.

I second that. It does not seem too complicate to make sparse accept
"static" in two possible position.

Here is a purpose patch with limited test. I expand the test to cover
more static test case.

Cody, does this patch work for you?

Chris

diff --git a/parse.c b/parse.c
index 70553f2..76aba40 100644
--- a/parse.c
+++ b/parse.c
@@ -1533,12 +1533,28 @@ static struct token
*declaration_specifiers(struct token *tok
        return token;
 }

+static struct token *abstract_array_static_declarator(struct token
*token, int *has_
+{
+       while (token->ident == &static_ident) {
+               if (*has_static)
+                       warning(token->pos, "duplicate array static
declarator");
+
+               *has_static = 1;
+               token = token->next;
+       }
+       return token;
+
+}
+
 static struct token *abstract_array_declarator(struct token *token,
struct symbol *s
 {
        struct expression *expr = NULL;
+       int has_static = 0;

-       while (match_idents(token, &restrict_ident, &__restrict_ident,
&static_ident,
-               token = token->next;
+       token = abstract_array_static_declarator(token, &has_static);
+
+       if (match_idents(token, &restrict_ident, &__restrict_ident, NULL))
+               token = abstract_array_static_declarator(token->next,
&has_static);
        token = parse_expression(token, &expr);
        sym->array_size = expr;
        return token;
diff --git a/validation/abstract-array-declarator-static.c
b/validation/abstract-arra
index 23cbae0..b0af17b 100644
--- a/validation/abstract-array-declarator-static.c
+++ b/validation/abstract-array-declarator-static.c
@@ -1,6 +1,14 @@

-extern void f(int g[static 1]);
+extern void f1(int g[static 1]);
+extern void f2(int g[static restrict 1]);
+extern void f3(int g[restrict static 1]);
+extern void f4(int g[static restrict static 1]);       /* duplicate
static error */
+extern void f5(int g[restrict static static 1]);       /* duplicate
static error */

 /*
  * check-name: abstract array declarator static
+ * check-error-start
+abstract-array-declarator-static.c:5:38: warning: duplicate array
static declarator
+abstract-array-declarator-static.c:6:38: warning: duplicate array
static declarator
+ * check-error-end
  */
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux