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 [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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686658182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=p9CBIJBiY3006iK03HmW+HLrCIORicy+fjktAJDAQkw=; b=gWB1m3FQ+y0MHbKxvYw8gEvKITE6Y3bSBfEyqocZ2SMIyl/OmNfr7pIVU1lhU/jEo70yUJ BNVbcKORK9/18M0lA0BLLwKLXrUBR1+drEU5xcWQdhBWuCeaGHQxKgaGRNHNFOvXgGaONn JOExrpJMuV+JWG89jVpIKr12jC3iIUQ= 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) From: Jason Merrill 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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 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}); +} base-commit: d438b67e005bf8fc9e4af26410bf69816c30e969 -- 2.31.1