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: 25390 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3280562wrr; Thu, 24 Nov 2022 01:15:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf4U7OXj/nap7IE2JMfuBmLySltitnVYP6mMjYbFkNbHbn3J2NH1e3EQ6/aIM0pf9S/QZFvQ X-Received: by 2002:a17:907:104d:b0:79e:3312:9a0f with SMTP id oy13-20020a170907104d00b0079e33129a0fmr25426022ejb.576.1669281299993; Thu, 24 Nov 2022 01:14:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669281299; cv=none; d=google.com; s=arc-20160816; b=QY8Qpau3PInrfXxZDT0yK2QWZdCqLunQRTS8+/rule0CqSTvz7FCYVn4G4dPN8tYhh ueEX+dbMyforDd/yu8EayrPV1t4zkKVyqDyodS7TtSRL7t6ZXdJk6HMfMUqJ9fnawTWK ZHgJbJSEPGQB+8ihvweZNbHYiqxcD8/OJO9UoFANlkGH00G7tvcJ8tC8vcEJhTnCVe3r aExBJnVzWSYl2QVz9F8BDW7Qp+pqUH4KuQrJcrgLYKOVKmtTc41m+IG+Kc41e9IT7pzF iDf8MbfSv+z0rkYyeeyJIh9KKCcejbJM06884UU0cmVTibSLY3S1mfpEzHw/5YYNcwOK Ffkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=rkB/crH3qhtLVPmLVHqE7NOTNSfBvtkaAlWY1uVGBvk=; b=N20RDWxNYPnnHdllyyy/oHN4HlqFrP4kNrcj5mYmx4A2o9cfqQnCcEJud9V64i+VsW Q8MTrKu0GFgKmp3ZMlCItpyONG9f6CPGgi4QcSbpoWu1U8ipwOI39+0gmjGaO7jWZRvj wa/8XmYTqAsFRRlZMQevFNT5t/2i3GTPf5XHQvg5aKo6hxvP55bP+mmQzlVlc+u3DGCJ ZFYk5elVfkbGhm0O1NVWA63uVm/4Dvl9VdLS1L7rslmVR3eRtNOyoki7dlNRhLBeu2sW 2l2Ny7cWMJfwfnYHQ2v1QzZ1JG4w31pZHUubGtk0dpC7ueRx2jN/WNlh+SxKwrSsQjzU NDqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tXxNdOoj; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id js18-20020a17090797d200b007b28c65ba9bsi541370ejc.246.2022.11.24.01.14.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Nov 2022 01:14:59 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tXxNdOoj; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C195438432F6 for ; Thu, 24 Nov 2022 09:14:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C195438432F6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669281298; 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=tXxNdOojEj2OQUACWkF1lcupw+RClb0+Eo4kLcYYh6YfA4nn9a2AgoE/TYZS/Zj8f H3PNiR1TL2EKClqDktiNXoNk55PUSJpL37JwKFaGdI/vmmy++RMQH5XG+42oMQ/hUk i6ofOqxLtO5HK9P/7Obn/JAtd4jRoMg3VQC/dhew= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750368308559536464?= X-GMAIL-MSGID: =?utf-8?q?1750368308559536464?= 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 (); +}