From patchwork Sat Aug 2 05:29:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Li X-Patchwork-Id: 4665061 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 3F1AE9F36A for ; Sat, 2 Aug 2014 05:29:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8E319201F7 for ; Sat, 2 Aug 2014 05:29:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D22CF201E4 for ; Sat, 2 Aug 2014 05:29:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750850AbaHBF3H (ORCPT ); Sat, 2 Aug 2014 01:29:07 -0400 Received: from mail-qg0-f53.google.com ([209.85.192.53]:53183 "EHLO mail-qg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750734AbaHBF3G (ORCPT ); Sat, 2 Aug 2014 01:29:06 -0400 Received: by mail-qg0-f53.google.com with SMTP id q107so6736400qgd.40 for ; Fri, 01 Aug 2014 22:29:05 -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=o14/fLd4eTSPRrjd85q9VZGBQiKcRB5J+xO9/sI5zjI=; b=ev/vsncPztzk+BMlF+LUIkjY+cURxtPAY5SCR+SFCvOyNNahylDQzlwnMlPyIrKyWu 7nzA6G/6gkAwMhYxCysemiUmtw8kC2ogjigdJmBKUgweToHix6JLnHpJkhR96CAD88gH qeRelFPfGFq+figDHDbykVpYIpmGuz+ovvYJaAQ7plBC8x1Vld54PUjDEUI7bIs4Ru3Q ouLrLc8Rrn4OpXZ9R39t2+d0Jw8B6yomNU7VgHKv0SVA/F+3PBDcSXrdVCWgd6JRJZJm VL03YhJiFbESxcHvgPs2eGzvHcEP/hUWqH4J14e/8ym5+Y1hz3WlzCXm1JAqggwoMEOn w5vQ== MIME-Version: 1.0 X-Received: by 10.224.36.130 with SMTP id t2mr13414733qad.45.1406957344971; Fri, 01 Aug 2014 22:29:04 -0700 (PDT) Received: by 10.140.21.164 with HTTP; Fri, 1 Aug 2014 22:29:04 -0700 (PDT) In-Reply-To: References: Date: Fri, 1 Aug 2014 22:29:04 -0700 X-Google-Sender-Auth: U9roA8Q_dEfn-zeEybKR8cwXQVU Message-ID: Subject: Re: Possible bug with _Static_assert & sparse From: Christopher Li To: Mike Holmes Cc: 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,T_TVD_MIME_EPI, 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, Jul 30, 2014 at 10:32 AM, Mike Holmes wrote: > Hi > > I wondered if the following sparse error indication was expected > behaviour or if it is a bug, > I would not expect sparse to error with "got 9" > > > $ cat static.c > #include > > #define fake 9 > _Static_assert( fake > 8, "test message"); > I create a patch to parse the _Static_assert and static_assert. Because _Static_assert can happen on the top level declare. It is not really a statement. My patch is not complete because parse_static_assert() does not save the parsing result for later evaluation. I need to figure out where to store it because it is not a statement and it has no effect on back ends. Suggestions are welcome. Chris diff --git a/parse.c b/parse.c index 55a57a7..59fc934 100644 --- a/parse.c +++ b/parse.c @@ -73,6 +73,8 @@ static struct token *parse_context_statement(struct token *token, struct stateme static struct token *parse_range_statement(struct token *token, struct statement *stmt); static struct token *parse_asm_statement(struct token *token, struct statement *stmt); static struct token *toplevel_asm_declaration(struct token *token, struct symbol_list **list); +static struct token *parse_static_assert_statement(struct token *token, struct statement *stmt); +static struct token *toplevel_static_assert_declaration(struct token *token, struct symbol_list **list); typedef struct token *attr_t(struct token *, struct symbol *, struct decl_state *); @@ -308,6 +310,11 @@ static struct symbol_op asm_op = { .toplevel = toplevel_asm_declaration, }; +static struct symbol_op static_assert_op = { + .statement = parse_static_assert_statement, + .toplevel = toplevel_static_assert_declaration, +}; + static struct symbol_op packed_op = { .attribute = attribute_packed, }; @@ -460,6 +467,8 @@ static struct init_keyword { { "asm", NS_KEYWORD, .op = &asm_op }, { "__asm", NS_KEYWORD, .op = &asm_op }, { "__asm__", NS_KEYWORD, .op = &asm_op }, + { "static_assert", NS_KEYWORD, .op = &static_assert_op }, + { "_Static_assert", NS_KEYWORD, .op = &static_assert_op }, /* Attribute */ { "packed", NS_KEYWORD, .op = &packed_op }, @@ -2003,6 +2012,29 @@ static struct token *parse_asm_declarator(struct token *token, struct decl_state return token; } +static struct token *parse_static_assert(struct token * token) +{ + struct expression *expr = NULL; + + token = expect(token->next, '(', "after static assert"); + token = conditional_expression(token, &expr); + token = expect(token, ',', "after constant expression of static assert"); + token = parse_expression(token, &expr); + token = expect(token, ')', "after static assert"); + return expect(token, ';', "at end of static assert"); +} + +static struct token *parse_static_assert_statement(struct token *token, struct statement *stmt) +{ + return parse_static_assert(token); +} + +static struct token *toplevel_static_assert_declaration(struct token *token, struct symbol_list **list) +{ + return parse_static_assert(token); +} + + /* Make a statement out of an expression */ static struct statement *make_statement(struct expression *expr) {