From patchwork Thu Apr 17 06:50:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Li X-Patchwork-Id: 4005891 Return-Path: X-Original-To: patchwork-linux-sparse@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D8ABC9F2CC for ; Thu, 17 Apr 2014 06:50:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1437E2034A for ; Thu, 17 Apr 2014 06:50:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0CA7720328 for ; Thu, 17 Apr 2014 06:50:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751335AbaDQGuR (ORCPT ); Thu, 17 Apr 2014 02:50:17 -0400 Received: from mail-qa0-f43.google.com ([209.85.216.43]:49713 "EHLO mail-qa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751088AbaDQGuQ (ORCPT ); Thu, 17 Apr 2014 02:50:16 -0400 Received: by mail-qa0-f43.google.com with SMTP id j15so29615qaq.30 for ; Wed, 16 Apr 2014 23:50:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=FcF1SPWhHjw8xcits19TtURI6siYOXDHqg4MON7im2k=; b=VVJra4B3CmYytGw3yoUIEeEAaFBK0adkpOgi0twqO43Ekzv/lVIm0U1HUFo5swG0NB 9xLGqJwVSubibr9DTSbq+TJ+czWpMeH2H16ODgaUH3+QyeRRa5HteN+8Okx4JmIbYHAl fEoRxkoylMxcny8MDIXa0heuP9QG4z+GDzp4wYh+KLww0wyHLWLU4LPdBKQS9tW8p4KR IJohI3KrTJ4tHGkNnBYa0dGQF0AoIlVYgOZCZ4yQGbIv2zo8ZoOwM1bnXT0xWMThLw7j SEWwv51PnsSgbrt93Yda17Trzfy6tTLb3YeY6l95L185OGVHIux91GsnUf/CNmrNlPiP qp1w== MIME-Version: 1.0 X-Received: by 10.224.112.74 with SMTP id v10mr10476292qap.28.1397717415500; Wed, 16 Apr 2014 23:50:15 -0700 (PDT) Received: by 10.140.21.209 with HTTP; Wed, 16 Apr 2014 23:50:15 -0700 (PDT) In-Reply-To: <20140417050914.GA21150@leaf> References: <1397603337-28016-1-git-send-email-cody@linux.vnet.ibm.com> <20140417001234.GA18426@leaf> <534F4F7F.5020506@linux.vnet.ibm.com> <20140417050914.GA21150@leaf> Date: Wed, 16 Apr 2014 23:50:15 -0700 X-Google-Sender-Auth: D4-cXtYG04Lt_UWnMYG4BSC2WFc Message-ID: Subject: Re: [PATCH] parse: support c99 [static ...] in abstract array declarators From: Christopher Li To: Josh Triplett Cc: Cody P Schafer , Linux-Sparse Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Apr 16, 2014 at 10:09 PM, Josh Triplett 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 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