From patchwork Fri Dec 7 18:08:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 204591 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 D497E2C0168 for ; Sat, 8 Dec 2012 05:08:37 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1355508518; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=YOEGD08 dBuSeJc4iWwCvudlUONE=; b=MXI6MNkhQw7S/Qj/aF+FFrsN03cqb5wEgEKkUXL uuTqPTWiUv2aDDBCPHwvOxECd9TFuWGsXIBbDgd42YkT5SH2UUziBYflt1XwOE+U 19qAAKRyS31GzHOK5HPgw1UUR0zEYmHmKiGrrXed1YfbbxtX5oPqkC1VKtBkhP9+ V0vw= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Y6IQJSLTCOlPOKtek1MoqgTO0KrkXgqukLN7sluV2dq3QWlqE7MRJXz4x5nGXG kRPT4+oj3oU7nKouGIcRVKxY97ypuVmiK9OkxFvpl6JC8QgJc9AsrUeydpnCqLix wRye7B23KCwEWIOiP/2tBXwGeW575nFyboylumAYFnLpw=; Received: (qmail 13115 invoked by alias); 7 Dec 2012 18:08:32 -0000 Received: (qmail 13096 invoked by uid 22791); 7 Dec 2012 18:08:30 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, 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; Fri, 07 Dec 2012 18:08:22 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qB7I8MrY022566 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 7 Dec 2012 13:08:22 -0500 Received: from reynosa.quesejoda.com (vpn-10-199.rdu.redhat.com [10.11.10.199]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qB7I8K3Y014874; Fri, 7 Dec 2012 13:08:21 -0500 Message-ID: <50C23094.8000607@redhat.com> Date: Fri, 07 Dec 2012 12:08:20 -0600 From: Aldy Hernandez User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121016 Thunderbird/16.0.1 MIME-Version: 1.0 To: Jason Merrill CC: gcc-patches Subject: PR c++/55513: do not fold away builtins in COMPOUND_EXPRs 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 The problem here is that we fold away calls to built-ins in COMPOUND_EXPRs such as: const int t = (__builtin_memcpy (s, "Hello", 6), 777); Since we return true for any built-in in potential_constant_expression_1, this means that check_initializer->store_init_value->maybe_constant_init will chop off the built-in side of a COMPOUND_EXPR when setting a DECL_INITIAL, transforming: (COMPOUND_EXPR (CALL_EXPR built-in) INTEGER_CST) into INTEGER_CST Fixed by setting `non_constant_p' if folding a built-in does not yield a constant. Tested on x86-64 Linux. OK for trunk? commit 9775b837cf9ece71cbf9560c35c638b3f8c0a778 Author: Aldy Hernandez Date: Fri Dec 7 10:40:25 2012 -0600 PR c++/55513 * semantics.c (cxx_eval_builtin_function_call): Set non_constant_p after folding. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 491d97c..f487a61 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -6437,7 +6437,10 @@ cxx_eval_builtin_function_call (const constexpr_call *call, tree t, return t; new_call = build_call_array_loc (EXPR_LOCATION (t), TREE_TYPE (t), CALL_EXPR_FN (t), nargs, args); - return fold (new_call); + new_call = fold (new_call); + if (!TREE_CONSTANT (new_call)) + *non_constant_p = true; + return new_call; } /* TEMP is the constant value of a temporary object of type TYPE. Adjust diff --git a/gcc/testsuite/g++.dg/pr55513.C b/gcc/testsuite/g++.dg/pr55513.C new file mode 100644 index 0000000..06eedee --- /dev/null +++ b/gcc/testsuite/g++.dg/pr55513.C @@ -0,0 +1,12 @@ +// { dg-do compile } +// { dg-options "-O0 -fdump-tree-gimple" } + +main () +{ + char s[10]; + const int t = (__builtin_memcpy (s, "Hello", 6), 777); + __builtin_printf ("%d %s\n", t, s); +} + +// { dg-final { scan-tree-dump-times "memcpy" 1 "gimple" } } +// { dg-final { cleanup-tree-dump "gimple" } }