From patchwork Tue Jun 13 12:09:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 107336 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp493384vqr; Tue, 13 Jun 2023 05:10:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4nEPlLGJCmJUiOqmfYGR49l6iZ0Zd+ls2zxNabyBvaVOVLcySY6coAPMNMSjklStpebk3p X-Received: by 2002:a17:907:7208:b0:973:e5d9:d6ff with SMTP id dr8-20020a170907720800b00973e5d9d6ffmr12446917ejc.66.1686658228417; Tue, 13 Jun 2023 05:10:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686658228; cv=none; d=google.com; s=arc-20160816; b=FQqdsaKWKuSngVP5W5xXUG84NX3z6Z4h6epmQbT8L3Ezz39ShEP9aTbPofOLIWVR4l UAaXz/tNq4jxDyuT35AJ68szJtbZYEKOu9v2Sf/FqFhgWxP5gRHquvo8U69CGIaFdb3Y g7wKroNTJQ166BgHLxaPkhv6XOk9te4HpOmW3hh2jBIKznriAZm/acRMUkiavES5ewAI n4QJXxI8CXdJ6yZSiJtlKflJ4AUEK+Cc7fqVYi7Uqgd9EqQn6U72gMeePllEjh4kKrgD 9mB3a+wC07TnfMApbv+SdMJsvPBTSbsK6KHDdbbDmd7VnYzfBKmJ24yRhBUfokz437z7 THBg== 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-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=p9CBIJBiY3006iK03HmW+HLrCIORicy+fjktAJDAQkw=; b=uDkYxd0r//dSVxSl+CKA8NuUQ2ggj/AmKfxAr9THvtOe+A7IwToFK1HSyagYoZ/teM 5QzgY7+9GDsBLB/yaIZXMMuoWSXc7+CxTlUqjGBtSK9lRE3E37oGf0izN+DGgr6VNMjM KGJd05Hm76IqHRNgY0Ve9Am2HC1byrNOm9cYQZZsmUaZfNerOQAPLc9spIVbJJ5l3na0 45B72QfagYU5PvyirwGeTQ3VI9+V+6+hME6xPpNmUcLEARVCj2PTHoB0mDlodNe3e8xa 8PMDMuUgLhECZF2Uf93k8rYCbZB97/e0KZmSlfL4c1mRJ+dDdc0MbGNKRX+TUmpf0Cph gAOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qAQYZ7wc; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bi26-20020a170906a25a00b00977fe4c3bacsi7256725ejb.637.2023.06.13.05.10.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 05:10:28 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qAQYZ7wc; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 55E49385841C for ; Tue, 13 Jun 2023 12:10:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 55E49385841C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686658227; bh=p9CBIJBiY3006iK03HmW+HLrCIORicy+fjktAJDAQkw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=qAQYZ7wcL4iDbU3MSD6ppUz2Zk5GQtm66THNO7gmQ1rx+nFy0WL9HgTkP+Sk4cHJQ riIllqHNXfHXuWTrqgqKZkxt3ttC8YkPYScxcUFc4/uN5VT035F/MwPVWCbg9dcpiO Y7Fo0KG9C7BftidlY+gNeJa8Ktpuni8ZDJCSbG1s= 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 A0C373858D38 for ; Tue, 13 Jun 2023 12:09:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A0C373858D38 Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-159-ko-qBAAMN1K1f2WfTgfFsQ-1; Tue, 13 Jun 2023 08:09:41 -0400 X-MC-Unique: ko-qBAAMN1K1f2WfTgfFsQ-1 Received: by mail-oi1-f199.google.com with SMTP id 5614622812f47-397f97f7966so3817375b6e.3 for ; Tue, 13 Jun 2023 05:09:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686658180; x=1689250180; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=p9CBIJBiY3006iK03HmW+HLrCIORicy+fjktAJDAQkw=; b=Db6Bi6/peYVIJIwXJHqyaZfS85gEH53anK2QWmQwx7sA2lgi07ICOHcYtK1n3fkRxP UMEW8LAnLRIBvEJddGHJ31Bth2VX91x18bDX5uP5D4byrUyw2a2U3tmGmmtCCQd2D9r6 327tkyuLC9ZEyDwzS/Y3urw01wd5wXnsmrmHjWrRFzh4VmADgwwu9UM20SocN3hVUDlY cRFGrYnG1X3/2VJPd/sQDzuhGP4wW7kSeERd7q5rSNPcRzDXOmfIvb2bt0MnZRfw5kkj 4OBbXRi0hTbhXvoIB0YwuTCUfSyPZ5yY23JBGUHc/7N/nd/Ugm/nXAImxFDCCf2aoA1E kIOw== X-Gm-Message-State: AC+VfDwBXfXeUPtmcdSGWLqHHOeBaAWiq+HrSI9J9slfrexfY88Xv0wi Eir+Oy8SbOfdemcwzvAgCw/o6vGOA2XxZzE+lnRnOYmk7vwiHmpYMzv12eb6MhuW7Xnfp0bIWoQ y2l0VQEtIxkVKhj4usN7nLB8gziwx+AAt+dtbZ999NynRAOXmte1fVcXXbpiy0ksbdkfZ62YqXg == X-Received: by 2002:a05:6808:8c:b0:39a:bbd4:bab with SMTP id s12-20020a056808008c00b0039abbd40babmr7514525oic.31.1686658180076; Tue, 13 Jun 2023 05:09:40 -0700 (PDT) X-Received: by 2002:a05:6808:8c:b0:39a:bbd4:bab with SMTP id s12-20020a056808008c00b0039abbd40babmr7514503oic.31.1686658179740; Tue, 13 Jun 2023 05:09:39 -0700 (PDT) Received: from jason.com (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id a18-20020a0ce392000000b005fe4a301350sm3928102qvl.48.2023.06.13.05.09.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 05:09:37 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: mutable temps in rodata Date: Tue, 13 Jun 2023 08:09:34 -0400 Message-Id: <20230613120934.4183450-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill 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?1768589338692771282?= X-GMAIL-MSGID: =?utf-8?q?1768589338692771282?= Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- If the type of a temporary has mutable members, we can't set TREE_READONLY on the VAR_DECL; this is parallel to the check in cp_apply_type_quals_to_decl. gcc/cp/ChangeLog: * tree.cc (build_target_expr): Check TYPE_HAS_MUTABLE_P. gcc/testsuite/ChangeLog: * g++.dg/tree-ssa/initlist-opt6.C: New test. --- gcc/cp/tree.cc | 1 + gcc/testsuite/g++.dg/tree-ssa/initlist-opt6.C | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 gcc/testsuite/g++.dg/tree-ssa/initlist-opt6.C base-commit: d438b67e005bf8fc9e4af26410bf69816c30e969 diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc index 751c9adeb62..799183dc646 100644 --- a/gcc/cp/tree.cc +++ b/gcc/cp/tree.cc @@ -522,6 +522,7 @@ build_target_expr (tree decl, tree value, tsubst_flags_t complain) if (CP_TYPE_CONST_NON_VOLATILE_P (type) && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type) && !VOID_TYPE_P (TREE_TYPE (value)) + && !TYPE_HAS_MUTABLE_P (type) && reduced_constant_expression_p (value)) TREE_READONLY (decl) = true; diff --git a/gcc/testsuite/g++.dg/tree-ssa/initlist-opt6.C b/gcc/testsuite/g++.dg/tree-ssa/initlist-opt6.C new file mode 100644 index 00000000000..ea1bf5d935e --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/initlist-opt6.C @@ -0,0 +1,18 @@ +// { dg-do compile { target c++11 } } +// { dg-additional-options -fdump-tree-gimple } +// { dg-final { scan-tree-dump-not {static const struct S} "gimple" } } + +// Test that mutable prevents putting this init-list array in rodata. + +#include + +struct S { + constexpr S(int i) : i(i) {} + mutable int i; +}; + +void f(std::initializer_list); + +int main() { + f({1,2,3}); +}