From patchwork Thu Nov 24 09:13:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 61052 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DDFBC38432E9 for ; Thu, 24 Nov 2022 09:14:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DDFBC38432E9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669281282; bh=rkB/crH3qhtLVPmLVHqE7NOTNSfBvtkaAlWY1uVGBvk=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=FydymFz7TtkCbWTjcb05BiUZWAKLIrTjR5qlQD8+WYc4kxmeXPgPp6QT4QeK6jIvm IWJXR515UIntd1HfDFlHRGDGylsOH6+YuFp1sZXuvsjKSBerKTnmmRMQPsGWDDxmhw 9vzu3IOnaPhQz7nZ+Mmu1x5uC7LsG+3LFYfI9UKs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id CA3C638518AF for ; Thu, 24 Nov 2022 09:14:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CA3C638518AF Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-161-_i8IHkibP5GZAy4L8OzHJQ-1; Thu, 24 Nov 2022 04:14:01 -0500 X-MC-Unique: _i8IHkibP5GZAy4L8OzHJQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 48E33802314 for ; Thu, 24 Nov 2022 09:14:01 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.202]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 092A517585; Thu, 24 Nov 2022 09:14:00 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 2AO9Du21222241 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Nov 2022 10:13:56 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2AO9DukF222240; Thu, 24 Nov 2022 10:13:56 +0100 Date: Thu, 24 Nov 2022 10:13:55 +0100 To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Don't clear TREE_READONLY for -fmerge-all-constants for non-aggregates [PR107558] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! The following testcase ICEs, because OpenMP lowering for shared clause on l variable with REFERENCE_TYPE creates POINTER_TYPE to REFERENCE_TYPE. The reason is that the automatic variable has non-trivial construction (reference to a lambda) and -fmerge-all-constants is on and so TREE_READONLY isn't set - omp-low will handle automatic TREE_READONLY vars in shared specially and only copy to the construct and not back, while !TREE_READONLY are assumed to be changeable. The PR91529 change rationale was that the gimplification can change some non-addressable automatic variables to TREE_STATIC with -fmerge-all-constants and therefore TREE_READONLY on them is undesirable. But, the gimplifier does that only for aggregate variables: switch (TREE_CODE (type)) { case RECORD_TYPE: case UNION_TYPE: case QUAL_UNION_TYPE: case ARRAY_TYPE: and not for anything else. So, I think clearing TREE_READONLY for automatic integral or reference or pointer etc. vars for -fmerge-all-constants only is unnecessary. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-11-24 Jakub Jelinek PR c++/107558 * decl.cc (cp_finish_decl): Don't clear TREE_READONLY on automatic non-aggregate variables just because of -fmerge-all-constants. * g++.dg/gomp/pr107558.C: New test. Jakub --- gcc/cp/decl.cc.jj 2022-11-19 09:21:14.662439877 +0100 +++ gcc/cp/decl.cc 2022-11-23 13:12:31.866553152 +0100 @@ -8679,8 +8679,10 @@ cp_finish_decl (tree decl, tree init, bo if (var_definition_p /* With -fmerge-all-constants, gimplify_init_constructor - might add TREE_STATIC to the variable. */ - && (TREE_STATIC (decl) || flag_merge_constants >= 2)) + might add TREE_STATIC to aggregate variables. */ + && (TREE_STATIC (decl) + || (flag_merge_constants >= 2 + && AGGREGATE_TYPE_P (type)))) { /* If a TREE_READONLY variable needs initialization at runtime, it is no longer readonly and we need to --- gcc/testsuite/g++.dg/gomp/pr107558.C.jj 2022-11-23 13:13:27.260736525 +0100 +++ gcc/testsuite/g++.dg/gomp/pr107558.C 2022-11-23 13:15:22.271041005 +0100 @@ -0,0 +1,14 @@ +// PR c++/107558 +// { dg-do compile { target c++11 } } +// { dg-additional-options "-fmerge-all-constants" } +// { dg-additional-options "-flto" { target lto } } + +int a = 15; + +void +foo () +{ + auto &&l = [&]() { return a; }; +#pragma omp target parallel + l (); +}