From patchwork Thu Aug 29 20:15:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1978619 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=g48SVnpE; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wvsx82YRcz1yfn for ; Fri, 30 Aug 2024 06:16:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2C85F386181E for ; Thu, 29 Aug 2024 20:16:10 +0000 (GMT) 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 ESMTP id C6EEE385C6C8 for ; Thu, 29 Aug 2024 20:15:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C6EEE385C6C8 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C6EEE385C6C8 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724962552; cv=none; b=T46OZQ4l6PwA4K4feZO93kMMU45+IcLDfKTEa9QbnIq82ZPy1PeU7F2c47lSn23A3y4B0a3OZDESEi42OzSdwmz6dANmKK/CB+66XiI6JHG0NBq+BBWM6AJG/8QTawxvCZSej5GQoADuIX7LPpJBiKCkLg3XGQ1902R8nL33pW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724962552; c=relaxed/simple; bh=o68g9flObiWnUm6jbbxdgaYvdgJg4G6Bijpyfv3XptI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vDsDujdnG5ZXcE67YYsBkAM4wGmOIZvD0741nHSkXicQwOck96176E8vmxIqBYJiz7VXXGRH0tMaXb9sNfkwEVCpYZhK+Ce5BFCKDBXT7dRcuNSYrAA4iLhFoYYUGqYw81poHSNQq16zBelttxlrWkniYV0x/WkJzs3N0SrckJA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724962550; 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=NEwAEELEaTE+aayPhlutA3T7JwnoYxRDNW2rNTj3fuo=; b=g48SVnpExLE7AgyDDPd1FjMLJJJLHuQcQgt47b3mlAh+1jJq2U8M49xU7pdVTObDhKzTNm CeigT3aUFWYqYUkUNPgcF7/9Wwl6x4CygtSnYU2A6XQEOTPobv0jnV3E7Gqe9GDU91+hOV 3G/0WH2BeeaIgRV8JZY4quMrJfA+rg8= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-669-rb4L2EeEObK9gNTZn1n-Iw-1; Thu, 29 Aug 2024 16:15:49 -0400 X-MC-Unique: rb4L2EeEObK9gNTZn1n-Iw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7459B1955EA6 for ; Thu, 29 Aug 2024 20:15:47 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.65.79]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 83F1D3001FC3; Thu, 29 Aug 2024 20:15:46 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: mutable temps in rodata [PR116369] Date: Thu, 29 Aug 2024 16:15:41 -0400 Message-ID: <20240829201541.592487-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.2 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, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/14/13? -- >8 -- Here we wrongly mark the reference temporary for g TREE_READONLY, so it's put in .rodata and so we can't modify its subobject even when the subobject is marked mutable. This is so since r9-869. r14-1785 fixed a similar problem, but not in set_up_extended_ref_temp. PR c++/116369 gcc/cp/ChangeLog: * call.cc (set_up_extended_ref_temp): Don't mark a temporary TREE_READONLY if its type is TYPE_HAS_MUTABLE_P. gcc/testsuite/ChangeLog: * g++.dg/tree-ssa/initlist-opt7.C: New test. --- gcc/cp/call.cc | 4 +++- gcc/testsuite/g++.dg/tree-ssa/initlist-opt7.C | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/tree-ssa/initlist-opt7.C base-commit: 6bfeba12c86b4d0dae27d99b484f64774dd49398 diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index fa7f05d76f6..d30f36d49ff 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -13964,7 +13964,9 @@ set_up_extended_ref_temp (tree decl, tree expr, vec **cleanups, init = cp_fully_fold (init); if (TREE_CONSTANT (init)) { - if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type)) + if (literal_type_p (type) + && CP_TYPE_CONST_NON_VOLATILE_P (type) + && !TYPE_HAS_MUTABLE_P (type)) { /* 5.19 says that a constant expression can include an lvalue-rvalue conversion applied to "a glvalue of literal type diff --git a/gcc/testsuite/g++.dg/tree-ssa/initlist-opt7.C b/gcc/testsuite/g++.dg/tree-ssa/initlist-opt7.C new file mode 100644 index 00000000000..2420db502a6 --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/initlist-opt7.C @@ -0,0 +1,13 @@ +// PR c++/116369 +// { dg-do run { target c++11 } } + +struct f{ + mutable int t; +}; + +const f &g = {1}; + +int main() +{ + g.t++; +}