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: 1794481 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ud+SRifH; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QgS6k3Q7pz20Wq for ; Tue, 13 Jun 2023 22:10:05 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 758BA3858414 for ; Tue, 13 Jun 2023 12:10:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 758BA3858414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686658203; 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=ud+SRifHUiB1P9grzxgxdNm6eacCYjrrtdvX/hM+LT0DYxZRPddNo2zfW3vuOIzvn sCpguTh88qh8aH4Ul+vFP2wj5JKI/l1LveKcBI7w2EKr1Aud+Ion6UOcBrumPveXmV 7VWxcZqYCfQhQo2BsFchhKm6FY3RDv1Vmm8gW/bU= 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-Google-Smtp-Source: ACHHUZ6+1h6gqdI2IbeXu7AlH8sVXKzg/FXmuysmbbf2ZTUptBV28sOBxtGaxbCZDPLGoa0ml5RBiA== 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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}); +}