From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 51877 invoked by alias); 16 Sep 2016 20:44:15 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 51788 invoked by uid 89); 16 Sep 2016 20:44:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=lucky X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Sep 2016 20:44:13 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B22179E61E for ; Fri, 16 Sep 2016 20:44:12 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-204-43.brq.redhat.com [10.40.204.43]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8GKiBoH030752 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 16 Sep 2016 16:44:12 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u8GKi9os002834; Fri, 16 Sep 2016 22:44:09 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u8GKi8Qs002833; Fri, 16 Sep 2016 22:44:08 +0200 Date: Fri, 16 Sep 2016 20:51:00 -0000 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches List Subject: Re: [C++ PATCH] Fix constexpr switch handling (PR c++/77467) Message-ID: <20160916204408.GM7282@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <20160905171119.GU14857@tucnak.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes X-SW-Source: 2016-09/txt/msg01095.txt.bz2 On Fri, Sep 16, 2016 at 03:51:11PM -0400, Jason Merrill wrote: > On Mon, Sep 5, 2016 at 1:11 PM, Jakub Jelinek wrote: > > + /* If body is a statement other than STATEMENT_LIST or BIND_EXPR, > > + it should be skipped. E.g. switch (a) b = a; */ > > + if (TREE_CODE (body) == STATEMENT_LIST > > + || TREE_CODE (body) == BIND_EXPR) > > I'm nervous about this optimization for useless code breaking other > things that might (one day) wrap a case label; I think I'd prefer to > drop the condition. By droping the condition you mean unconditionally call cxx_eval_constant_expression (ctx, body, false, non_constant_p, overflow_p, jump_target); ? That is known not to work, that breaks the +constexpr int +bar (int x) +{ + int a = x; + switch (x) + a = x + 1; + return a; +} handling in the testcase, where body is the MODIFY_EXPR which doesn't have the label and thus needs to be skipped. The problem is that all the logic for skipping statements until the label is found is in cxx_eval_statement_list only. For STATEMENT_LIST that is called by cxx_eval_constant_expression, for BIND_EXPR if we are lucky enough that BIND_EXPR_BODY is a STATEMENT_LIST too (otherwise I assume even my patch doesn't fix it, it would need to verify that). If body is some other statement, then it really should be skipped, but it isn't, because cxx_eval_constant_expression ignores it. I wonder if we e.g. cxx_eval_constant_expression couldn't early in the function for if (*jump_target) return immediately unless code is something like STATEMENT_LIST or BIND_EXPR with BIND_EXPR_BODY being STATEMENT_LIST, or perhaps in the future other construct containing other stmts. I've beeing thinking about TRY block, but at least on the testcases I've tried it has been rejected in constexpr functions, I think one can't branch into statement expressions, so that should be fine, OpenMP/OpenACC constructs are hopefully also rejected in constexpr, what else? Jakub