From patchwork Tue Aug 23 15:50:24 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 111137 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 B2A53B6F71 for ; Wed, 24 Aug 2011 01:50:49 +1000 (EST) Received: (qmail 2609 invoked by alias); 23 Aug 2011 15:50:45 -0000 Received: (qmail 2583 invoked by uid 22791); 23 Aug 2011 15:50:43 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS 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; Tue, 23 Aug 2011 15:50:26 +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.14.4/8.14.4) with ESMTP id p7NFoQbw028054 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 23 Aug 2011 11:50:26 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p7NFoQLg031286 for ; Tue, 23 Aug 2011 11:50:26 -0400 Received: from [0.0.0.0] (ovpn-113-47.phx2.redhat.com [10.3.113.47]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p7NFoPIT032177 for ; Tue, 23 Aug 2011 11:50:25 -0400 Message-ID: <4E53CC40.1090503@redhat.com> Date: Tue, 23 Aug 2011 11:50:24 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:5.0) Gecko/20110719 Thunderbird/5.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for a fixme in build_functional_cast 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 While looking at another issue I noticed this fixme. A TARGET_EXPR of literal type should have TREE_CONSTANT set iff the initializer is constant, and this patch implements that. Tested x86_64-pc-linux-gnu, applying to trunk. commit 21aebcf68d774827647731368a5708e1c60c31af Author: Jason Merrill Date: Fri Aug 19 10:14:12 2011 -0400 * tree.c (build_target_expr): Set TREE_CONSTANT on literal TARGET_EXPR if the value is constant. * typeck2.c (build_functional_cast): Don't set it here. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 4ef89c4..00598ce 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -288,6 +288,7 @@ static tree build_target_expr (tree decl, tree value, tsubst_flags_t complain) { tree t; + tree type = TREE_TYPE (decl); #ifdef ENABLE_CHECKING gcc_assert (VOID_TYPE_P (TREE_TYPE (value)) @@ -302,12 +303,14 @@ build_target_expr (tree decl, tree value, tsubst_flags_t complain) t = cxx_maybe_build_cleanup (decl, complain); if (t == error_mark_node) return error_mark_node; - t = build4 (TARGET_EXPR, TREE_TYPE (decl), decl, value, t, NULL_TREE); + t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE); /* We always set TREE_SIDE_EFFECTS so that expand_expr does not ignore the TARGET_EXPR. If there really turn out to be no side-effects, then the optimizer should be able to get rid of whatever code is generated anyhow. */ TREE_SIDE_EFFECTS (t) = 1; + if (literal_type_p (type)) + TREE_CONSTANT (t) = TREE_CONSTANT (value); return t; } diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 79aa354..97f98ab 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -1684,9 +1684,6 @@ build_functional_cast (tree exp, tree parms, tsubst_flags_t complain) { exp = build_value_init (type, complain); exp = get_target_expr_sfinae (exp, complain); - /* FIXME this is wrong */ - if (literal_type_p (type)) - TREE_CONSTANT (exp) = true; return exp; }