diff mbox

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

Message ID CANeU7Q=qfD=fpP1k1gHpUxek4ZUuau3drCDncYr5eE18Xiq4Zw@mail.gmail.com (mailing list archive)
State Mainlined, archived
Headers show

Commit Message

Christopher Li April 17, 2014, 6:50 a.m. UTC
On Wed, Apr 16, 2014 at 10:09 PM, Josh Triplett <josh@joshtriplett.org> 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

+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@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Christopher Li April 18, 2014, 5:52 a.m. UTC | #1
On Wed, Apr 16, 2014 at 11:50 PM, Christopher Li <sparse@chrisli.org> wrote:

> 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?

I apply the patch and push it out.

Please let me know if it breaks any thing.

Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
cody@linux.vnet.ibm.com April 21, 2014, 4:43 p.m. UTC | #2
On 04/17/2014 10:52 PM, Christopher Li wrote:
> On Wed, Apr 16, 2014 at 11:50 PM, Christopher Li <sparse@chrisli.org> wrote:
>
>> 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?
>
> I apply the patch and push it out.
>
> Please let me know if it breaks any thing.
>

Looks fine to me Chris, thanks for putting this together.

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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