From patchwork Wed Jan 24 23:22:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 865565 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-471998-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="wTp3w7kx"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zRh656nMMz9t3l for ; Thu, 25 Jan 2018 10:22:37 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=at40RO53PoXRZYr0xE6x5MdpZJwV2 Y1o1y889Qw30Ok7zuu8YAy7TqPUpIxU5zSFXm8V/hAQy1XxtV1ozx1P6NOpskHP/ 8FVt/lmueEYbQB4HiIZf0KlVx4lh+vsCsFDUFSwRnpYk0WhI5GvYJJhCkQo5Lqn2 ehLard7BEuSqik= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=tHviYcVhLxu05ew76hPYejGMt3g=; b=wTp 3w7kxbWPYnBRwNmqZPCMd2PWiu9i+Wv77B8f/9JBqOJo6tRCdek0/wE8EvV1B+pT wEUpumNsufu0g02KLAyH3d4LsfkujJs3t4hotlwdsXsl3Bge3/SzJICCPWqvdzJZ IVG2PEtzgycnj5R+XBafCP3aqVdnyOBw9fqcn4jU= Received: (qmail 40027 invoked by alias); 24 Jan 2018 23:22:30 -0000 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 Received: (qmail 40017 invoked by uid 89); 24 Jan 2018 23:22:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= 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; Wed, 24 Jan 2018 23:22:29 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0CB94C05689C; Wed, 24 Jan 2018 23:22:28 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-22.ams2.redhat.com [10.36.117.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A8544438A; Wed, 24 Jan 2018 23:22:27 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w0ONMPe9008476; Thu, 25 Jan 2018 00:22:25 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w0ONMPlO008475; Thu, 25 Jan 2018 00:22:25 +0100 Date: Thu, 25 Jan 2018 00:22:24 +0100 From: Jakub Jelinek To: Jason Merrill , Nathan Sidwell Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Don't clear TREE_CONSTANT on ADDR_EXPRs (PR c++/83993) Message-ID: <20180124232224.GK2063@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) X-IsSubscribed: yes Hi! cxx_eval_outermost_constant_expr clears TREE_CONSTANT on ADDR_EXPRs that aren't considered by C++ constant expressions, but that breaks middle-end which relies on TREE_CONSTANT being set on ADDR_EXPR where the address is constant. The following patch just special cases ADDR_EXPR not to clear it. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? As I wrote in the PR, another option would be to restore TREE_CONSTANT during genericization if it was cleared earlier in the FE. 2018-01-24 Jakub Jelinek PR c++/83993 * constexpr.c (cxx_eval_outermost_constant_expr): Don't clear TREE_CONSTANT on ADDR_EXPRs. * g++.dg/init/pr83993-2.C: New test. Jakub --- gcc/cp/constexpr.c.jj 2018-01-24 13:38:40.572913190 +0100 +++ gcc/cp/constexpr.c 2018-01-24 17:03:16.821440047 +0100 @@ -4832,7 +4832,7 @@ cxx_eval_outermost_constant_expr (tree t if (non_constant_p && !allow_non_constant) return error_mark_node; - else if (non_constant_p && TREE_CONSTANT (r)) + else if (non_constant_p && TREE_CONSTANT (r) && TREE_CODE (r) != ADDR_EXPR) { /* This isn't actually constant, so unset TREE_CONSTANT. */ if (EXPR_P (r)) --- gcc/testsuite/g++.dg/init/pr83993-2.C.jj 2018-01-24 17:04:18.823456178 +0100 +++ gcc/testsuite/g++.dg/init/pr83993-2.C 2018-01-24 17:04:39.593454636 +0100 @@ -0,0 +1,14 @@ +// PR c++/83993 +// { dg-do compile } +// { dg-options "-w" } + +int a[5]; +extern int b[]; +int *const c = &a[6]; +int *const d = &b[1]; + +int +foo () +{ + return c[-4] + d[-1]; +}