From patchwork Wed Jun 28 20:49:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9815479 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B1A7C60365 for ; Wed, 28 Jun 2017 20:49:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A47661FF28 for ; Wed, 28 Jun 2017 20:49:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98E70205A4; Wed, 28 Jun 2017 20:49:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E321527FAD for ; Wed, 28 Jun 2017 20:49:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751554AbdF1Ut1 (ORCPT ); Wed, 28 Jun 2017 16:49:27 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36215 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751551AbdF1UtY (ORCPT ); Wed, 28 Jun 2017 16:49:24 -0400 Received: by mail-wm0-f68.google.com with SMTP id y5so13624007wmh.3 for ; Wed, 28 Jun 2017 13:49:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xTBXrifriEwGikxbjb+tqwKmoQtOt9nDgKkeYMJJCLg=; b=AwhKrHkjXip+24bFK0Uq0G6onW2mN06cANRg7itgrM2FQq9YebdVEt8hje1nIG8fbi 7S/Q/QyuN4t5rnFO6JXz2+kur+Qj98ZsqrIb2MA1Ku0dQan6es8iQU/gMP4ygcXEkdW5 UFyxPCcqwR33NvgNoEwp2eJzIlbugMyjtlajSX62gcRf/5B0lp3l9JaZgbcAmDy3tWWV sPuvT2MJ6ecDRchOjAhq3OCwVNSEq4k5XHS8Z+Hy8JmEUJyLP/kYyGbshVTSPdz4At+D Xf3tfzf/JeHcAGMr/TOt03OcssqM5JDt92FFYR34di/8Ky5gZw287P1Vd3K9DrPQX8uh KAvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xTBXrifriEwGikxbjb+tqwKmoQtOt9nDgKkeYMJJCLg=; b=QrGCIkWagJVQ7hDivxH7sovati4Pc8RRExjBxwG9UuX3H+y2jrb7jcGRbrcU5oI7G5 Gx4bAZisxf5ELOOli6MiwoIqw0av5mlGzIudNSiRQW6yc5nfRXVUaQMCMWZQXdziO+Wj UKPGlkArQKVM6+lcHsRexv8LomJxlKCDS0mpZO60OlmT2PszF74859mnQU0Tz/l7Qy7T 9qrLuO7E6by4LfRLnXnnprss0HprHP+pZTjwpoRJpqTh3+SrA8NO4GoSQclZ1hbLfJmv z847baJwFoHXAhAss7f6q1HHgyqkEZq0PGf1idN1rjtXJSpfyuj1k0kzSyLj2W5habH+ h4rg== X-Gm-Message-State: AKS2vOxVeMu1+hnC8JsnPr1NSf4KAOZ1iNbASDp34X21rj8HlXfJ3KeF TLaafYjaFPw2tmlg4m4= X-Received: by 10.80.154.98 with SMTP id o89mr9284409edb.137.1498682962794; Wed, 28 Jun 2017 13:49:22 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:837:f300:dc41:f6b3:4608:d7c8]) by smtp.gmail.com with ESMTPSA id d56sm1822372ede.42.2017.06.28.13.49.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Jun 2017 13:49:22 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Linus Torvalds , Luc Van Oostenryck Subject: [PATCH 1/2] avoid some struct symbol member for for-statements Date: Wed, 28 Jun 2017 22:49:17 +0200 Message-Id: <20170628204918.25853-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170628204918.25853-1-luc.vanoostenryck@gmail.com> References: <20170628204918.25853-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The for-statement needs a lot of fields in struct statement, much more than any other statement. This is due to the complexity of the for-statement. The possibility in C99 to declare variables in the initialization part of the statement add yet another field to hold the declared symbols. However, these symbols doesn't need a lis of their own, they can simply be put in the list of a STMT_DECLARATION used as the 'pre-' statement of a classic for-statement. Merge the symbols list with the pre-statement. Note: The motivation for this change is to make struct statement smaller. The change also make further processing slightly simpler since we don't have to process the declaration separately. Signed-off-by: Luc Van Oostenryck --- compile-i386.c | 1 - dissect.c | 1 - evaluate.c | 1 - inline.c | 2 -- linearize.c | 6 ------ parse.c | 22 +++++++++++++++------- parse.h | 1 - show-parse.c | 1 - 8 files changed, 15 insertions(+), 20 deletions(-) diff --git a/compile-i386.c b/compile-i386.c index 24e408baa..de252c8f9 100644 --- a/compile-i386.c +++ b/compile-i386.c @@ -1926,7 +1926,6 @@ static void emit_loop(struct statement *stmt) loop_continue = new_label(); loopstk_push(loop_continue, loop_bottom); - x86_symbol_decl(stmt->iterator_syms); x86_statement(pre_statement); if (!post_condition || post_condition->type != EXPR_VALUE || post_condition->value) { loop_top = new_label(); diff --git a/dissect.c b/dissect.c index 5f067eb4c..9f823980d 100644 --- a/dissect.c +++ b/dissect.c @@ -494,7 +494,6 @@ static struct symbol *do_statement(usage_t mode, struct statement *stmt) } break; case STMT_ITERATOR: - do_sym_list(stmt->iterator_syms); do_statement(U_VOID, stmt->iterator_pre_statement); do_expression(U_R_VAL, stmt->iterator_pre_condition); do_statement(U_VOID, stmt->iterator_post_statement); diff --git a/evaluate.c b/evaluate.c index cf3cf244d..e5b3b5904 100644 --- a/evaluate.c +++ b/evaluate.c @@ -3279,7 +3279,6 @@ static void evaluate_if_statement(struct statement *stmt) static void evaluate_iterator(struct statement *stmt) { - evaluate_symbol_list(stmt->iterator_syms); evaluate_conditional(stmt->iterator_pre_condition, 1); evaluate_conditional(stmt->iterator_post_condition,1); evaluate_statement(stmt->iterator_pre_statement); diff --git a/inline.c b/inline.c index a3002c6bd..dec07a25c 100644 --- a/inline.c +++ b/inline.c @@ -421,8 +421,6 @@ static struct statement *copy_one_statement(struct statement *stmt) stmt = dup_statement(stmt); stmt->iterator_break = copy_symbol(stmt->pos, stmt->iterator_break); stmt->iterator_continue = copy_symbol(stmt->pos, stmt->iterator_continue); - stmt->iterator_syms = copy_symbol_list(stmt->iterator_syms); - stmt->iterator_pre_statement = copy_one_statement(stmt->iterator_pre_statement); stmt->iterator_pre_condition = copy_expression(stmt->iterator_pre_condition); diff --git a/linearize.c b/linearize.c index 7313e72d8..6d0695a18 100644 --- a/linearize.c +++ b/linearize.c @@ -2000,12 +2000,6 @@ static pseudo_t linearize_iterator(struct entrypoint *ep, struct statement *stmt struct statement *post_statement = stmt->iterator_post_statement; struct expression *post_condition = stmt->iterator_post_condition; struct basic_block *loop_top, *loop_body, *loop_continue, *loop_end; - struct symbol *sym; - - FOR_EACH_PTR(stmt->iterator_syms, sym) { - linearize_one_symbol(ep, sym); - } END_FOR_EACH_PTR(sym); - concat_symbol_list(stmt->iterator_syms, &ep->syms); linearize_statement(ep, pre_statement); loop_body = loop_top = alloc_basic_block(ep, stmt->pos); diff --git a/parse.c b/parse.c index 214547904..e063dae99 100644 --- a/parse.c +++ b/parse.c @@ -2282,36 +2282,44 @@ static void validate_for_loop_decl(struct symbol *sym) static struct token *parse_for_statement(struct token *token, struct statement *stmt) { - struct symbol_list *syms; - struct expression *e1, *e2, *e3; + struct expression *e2, *e3; struct statement *iterator; + struct statement *pre = NULL; - start_iterator(stmt); token = expect(token->next, '(', "after 'for'"); - syms = NULL; - e1 = NULL; /* C99 variable declaration? */ if (lookup_type(token)) { + struct symbol_list *syms = NULL; + struct position pos = token->pos; + start_symbol_scope(); token = external_declaration(token, &syms, validate_for_loop_decl); + pre = alloc_statement(pos, STMT_DECLARATION); + pre->declaration = syms; } else { + struct expression *e1 = NULL; token = parse_expression(token, &e1); token = expect(token, ';', "in 'for'"); + pre = make_statement(e1); } + + start_iterator(stmt); token = parse_expression(token, &e2); token = expect(token, ';', "in 'for'"); token = parse_expression(token, &e3); token = expect(token, ')', "in 'for'"); token = statement(token, &iterator); - stmt->iterator_syms = syms; - stmt->iterator_pre_statement = make_statement(e1); + stmt->iterator_pre_statement = pre; stmt->iterator_pre_condition = e2; stmt->iterator_post_statement = make_statement(e3); stmt->iterator_post_condition = NULL; stmt->iterator_statement = iterator; end_iterator(stmt); + if (pre && pre->type == STMT_DECLARATION) + end_symbol_scope(); + return token; } diff --git a/parse.h b/parse.h index 26227a387..e01497096 100644 --- a/parse.h +++ b/parse.h @@ -88,7 +88,6 @@ struct statement { struct /* iterator_struct */ { struct symbol *iterator_break; struct symbol *iterator_continue; - struct symbol_list *iterator_syms; struct statement *iterator_pre_statement; struct expression *iterator_pre_condition; diff --git a/show-parse.c b/show-parse.c index 5e3e13165..6801a68e2 100644 --- a/show-parse.c +++ b/show-parse.c @@ -633,7 +633,6 @@ int show_statement(struct statement *stmt) struct expression *post_condition = stmt->iterator_post_condition; int val, loop_top = 0, loop_bottom = 0; - show_symbol_decl(stmt->iterator_syms); show_statement(pre_statement); if (pre_condition) { if (pre_condition->type == EXPR_VALUE) {