From patchwork Fri May 7 09:02:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1475405 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fc4G65nzbz9sj5 for ; Fri, 7 May 2021 19:02:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B17EB383582F; Fri, 7 May 2021 09:02:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id A7F3A3857C74 for ; Fri, 7 May 2021 09:02:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A7F3A3857C74 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rguenther@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6DFCAB11A; Fri, 7 May 2021 09:02:14 +0000 (UTC) Date: Fri, 7 May 2021 11:02:13 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/100464 - avoid spurious TREE_ADDRESSABLE in folding debug stmts Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" canonicalize_constructor_val was setting TREE_ADDRESSABLE on bases of ADDR_EXPRs but that's futile when we're dealing with CTOR values in debug stmts. This rips out the code which was added for Java and should have been an assertion when we didn't have debug stmts. Bootstrapped and tested on x86_64-unknown-linux-gnu for all languages which revealed PR100468 for which I added the cp/class.c hunk below. Re-testing with that in progress. OK for trunk and branch? It looks like this C++ code is new in GCC 11. Thanks, Richard. 2021-05-07 Richard Biener PR middle-end/100464 PR c++/100468 gcc/ * gimple-fold.c (canonicalize_constructor_val): Do not set TREE_ADDRESSABLE. gcc/cp/ * call.c (set_up_extended_ref_temp): Mark the temporary addressable if the TARGET_EXPR was. gcc/testsuite/ * gcc.dg/pr100464.c: New testcase. --- gcc/cp/call.c | 2 ++ gcc/gimple-fold.c | 4 +++- gcc/testsuite/gcc.dg/pr100464.c | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr100464.c diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 57bac05fe70..ea97be22f07 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -12478,6 +12478,8 @@ set_up_extended_ref_temp (tree decl, tree expr, vec **cleanups, VAR. */ if (TREE_CODE (expr) != TARGET_EXPR) expr = get_target_expr (expr); + else if (TREE_ADDRESSABLE (expr)) + TREE_ADDRESSABLE (var) = 1; if (TREE_CODE (decl) == FIELD_DECL && extra_warnings && !TREE_NO_WARNING (decl)) diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index aa33779b753..768ef89d876 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -245,7 +245,9 @@ canonicalize_constructor_val (tree cval, tree from_decl) if (TREE_TYPE (base) == error_mark_node) return NULL_TREE; if (VAR_P (base)) - TREE_ADDRESSABLE (base) = 1; + /* ??? We should be able to assert that TREE_ADDRESSABLE is set, + but since the use can be in a debug stmt we can't. */ + ; else if (TREE_CODE (base) == FUNCTION_DECL) { /* Make sure we create a cgraph node for functions we'll reference. diff --git a/gcc/testsuite/gcc.dg/pr100464.c b/gcc/testsuite/gcc.dg/pr100464.c new file mode 100644 index 00000000000..46cc37dff54 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr100464.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fcompare-debug" } */ + +int *a; +static int b, c, d, e, g, h; +int f; +void i() { + int *j[] = {&e, &b, &b, &d, &b, &b, &g, &e, &g, &b, &b, + &b, &b, &g, &e, &e, &b, &b, &d, &b, &b, &e, + &e, &g, &b, &b, &b, &b, &g, &e, &g, &c, &e}; + int **k = &j[5]; + for (; f;) + b |= *a; + *k = &h; +} +int main() {}