From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 12B9E386FC04 for ; Sun, 9 May 2021 04:51:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 12B9E386FC04 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-79--4cNtaFuNsm_9HtXqhtYKg-1; Sun, 09 May 2021 00:51:40 -0400 X-MC-Unique: -4cNtaFuNsm_9HtXqhtYKg-1 Received: by mail-qt1-f200.google.com with SMTP id b6-20020ac85bc60000b02901c2752ed3d4so8297197qtb.15 for ; Sat, 08 May 2021 21:51:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Ywd3Y6bTcNeRI35+wxd5KW3s8LWVCjFy0mmrIHGHPWc=; b=Fh0EAf0Vr0MW6cPqWRPGjYzKw3CWN9kAJFAQATmjrFB4oUjWfVgb6+Jgq7A1ksiaPC 18+/Etnghfo0VG2tI5I7PlbLLeMOVDQPA4TGwiFmeN5ZD6OVDST9epd5tTCpXFuRNDj3 IACT1fXrk82+pbVKkfm+GryCKXI/ODlp/HLnDImacU1GDR+u4Cm6lERblLNApAHNys2u 0qted8EBX6/xcqPZz/O9YqoAySF0kQpJZzG2vKlAdISpjSDWwRwAElSbtpRtvLrb2dKb U9TCjJWYCzDmo/LoQRfT9soL+JxK7V5wH4fYwgb6L+HCKGE4parzw5f7SSdcipZMik5/ E6PA== X-Gm-Message-State: AOAM5320wdxpJHrIK1H4aqQRW12PHjX7YIrpobLmsN6y6+WAx+kwfWQu JCVw9wOfny35hrJ8ijthGRLLVFCorAeYnDEMhXKiYT0Nnp2UBeKnRW3sXAv8AgY7rsouaX1QMAq sB9En1/G9f3yQo4V5iyaS+HCzJk6L/5HYVfFW7dIXhHZsLt1OdrlKDhVe8ieweBzBVw== X-Received: by 2002:a0c:fec8:: with SMTP id z8mr17656376qvs.58.1620535898649; Sat, 08 May 2021 21:51:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlQGai+1T4LlyZv/4ZxkmRlKNyMWNP7ELitcIcHdQfwhUxmWTHfxU4W82mK/ho3gtZwovsrQ== X-Received: by 2002:a0c:fec8:: with SMTP id z8mr17656351qvs.58.1620535898309; Sat, 08 May 2021 21:51:38 -0700 (PDT) Received: from [192.168.1.148] (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id f7sm9488109qtm.41.2021.05.08.21.51.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 08 May 2021 21:51:37 -0700 (PDT) Subject: Re: [PATCH] middle-end/100464 - avoid spurious TREE_ADDRESSABLE in folding debug stmts To: Richard Biener , Richard Biener Cc: GCC Patches References: From: Jason Merrill Message-ID: Date: Sun, 9 May 2021 00:51:36 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-15.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, 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: , X-List-Received-Date: Sun, 09 May 2021 04:51:46 -0000 On 5/7/21 6:21 AM, Richard Biener wrote: > On Fri, May 7, 2021 at 12:17 PM Richard Biener wrote: >> >> 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. > > I mislooked, the code is old. > > This hunk also breaks (or fixes) g++.dg/tree-ssa/array-temp1.C where > the gimplifier previously passes the > > && (flag_merge_constants >= 2 || !TREE_ADDRESSABLE (object)) > > check guarding it against unifying addresses of different instances > of variables. Clearly in the case of the testcase there are addresses to > this variable as part of the initializer list construction. So the hunk fixes > wrong-code, but it breaks the testcase. > > Any comments? I can of course change the testcase accordingly. Hmm, I suppose if the optimization is wrong for PR38615, it's also wrong for the initializer_list variant: extern "C" void abort (void); #include int f(int t, const int *a) { std::initializer_list b = { 1, 2, 3 }; const int *p = b.begin(); if (!t) return f (1, p); return p == a; } int main(void) { if (f(0, 0)) abort (); return 0; } so adjusting the array-temp testcase seems like the right answer. >> 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() {} >> -- >> 2.26.2 >