From patchwork Fri Jan 21 19:42:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 79914 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 92657B711B for ; Sat, 22 Jan 2011 06:42:24 +1100 (EST) Received: (qmail 21039 invoked by alias); 21 Jan 2011 19:42:22 -0000 Received: (qmail 21031 invoked by uid 22791); 21 Jan 2011 19:42:21 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 21 Jan 2011 19:42:07 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p0LJg5a3030216 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Jan 2011 14:42:05 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p0LJg4da012100 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 21 Jan 2011 14:42:05 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p0LJg4mY011212; Fri, 21 Jan 2011 20:42:04 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p0LJg4Mm011211; Fri, 21 Jan 2011 20:42:04 +0100 Date: Fri, 21 Jan 2011 20:42:04 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix -fno-for-scope (PR c++/47388) Message-ID: <20110121194204.GL2724@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi! With -fno-for-scope begin_for_scope in templates sets init to push_stmt_list () and returns NULL for scope. cp_parser_for first calls this (thus scope is NULL, but init is non-NULL, and then cp_parser_{c,range}_for call begin_*for_stmt which asserts that if scope is NULL then init is NULL too (which is true for invocations from pt.c, and for -ffor-scope, but not for -fno-for-scope if processing_template_decl). The following patch fixes it by not calling begin_for_scope in that case again. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? BTW, I was kind of surprised pt.c calls begin_for_stmt for both FOR_STMT and RANGE_FOR_STMT, I'd kind of expect it should be begin_range_for_stmt in the latter case, but haven't investigated in detail... 2011-01-27 Jakub Jelinek PR c++/47388 * semantics.c (begin_for_stmt): If -fno-for-scope, don't assume init must be NULL if scope is NULL. (begin_range_for_stmt): Likewise. * g++.dg/cpp0x/range-for10.C: New test. * g++.dg/template/for1.C: New test. Jakub --- gcc/cp/semantics.c.jj 2011-01-18 12:20:08.000000000 +0100 +++ gcc/cp/semantics.c 2011-01-21 17:56:47.000000000 +0100 @@ -860,8 +860,9 @@ begin_for_stmt (tree scope, tree init) if (scope == NULL_TREE) { - gcc_assert (!init); - scope = begin_for_scope (&init); + gcc_assert (!init || !(flag_new_for_scope > 0)); + if (!init) + scope = begin_for_scope (&init); } FOR_INIT_STMT (r) = init; TREE_CHAIN (r) = scope; @@ -962,8 +963,9 @@ begin_range_for_stmt (tree scope, tree i if (scope == NULL_TREE) { - gcc_assert (!init); - scope = begin_for_scope (&init); + gcc_assert (!init || !(flag_new_for_scope > 0)); + if (!init) + scope = begin_for_scope (&init); } /* RANGE_FOR_STMTs do not use nor save the init tree, so we --- gcc/testsuite/g++.dg/cpp0x/range-for10.C.jj 2011-01-21 18:10:06.000000000 +0100 +++ gcc/testsuite/g++.dg/cpp0x/range-for10.C 2011-01-21 18:10:56.000000000 +0100 @@ -0,0 +1,18 @@ +// PR c++/47388 +// { dg-do compile } +// { dg-options "-fno-for-scope -std=c++0x" } + +template +void +foo () +{ + int a[] = { 1, 2, 3, 4 }; + for (int i : a) + ; +} + +void +bar () +{ + foo <0> (); +} --- gcc/testsuite/g++.dg/template/for1.C.jj 2011-01-21 18:12:16.000000000 +0100 +++ gcc/testsuite/g++.dg/template/for1.C 2011-01-21 18:12:10.000000000 +0100 @@ -0,0 +1,23 @@ +// PR c++/47388 +// { dg-do compile } +// { dg-options "-fno-for-scope" } + +template +void +foo () +{ + int i; + for (i = 0; i < 16; i++) + ; + for (int j = 0; j < 16; j++) + ; + if (j != 16) + for (;;) + ; +} + +void +bar () +{ + foo <0> (); +}