From patchwork Thu Aug 8 11:59:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1970519 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=iY58ey4v; 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 4WflwX2N1Lz1ydk for ; Thu, 8 Aug 2024 22:00:08 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A5343385B50D for ; Thu, 8 Aug 2024 11:59:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id CF1DC3858D34 for ; Thu, 8 Aug 2024 11:59:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CF1DC3858D34 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CF1DC3858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::635 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723118379; cv=none; b=UT+xJMydgb2JvrltGk45s3t3daGVk5yNTzrq4fKaYTzFSs0f0ahC2VL6XOWf5LEz1+BarCoLZSNv7v6v6NpBkmufKJGURgma/HD5QsS6+/7EOV978f5oPnqGSZwUVBEA84CywZeqB8dGcC0eyVdD9RrkTPB0WwbKLnmyzCxL2eg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723118379; c=relaxed/simple; bh=56574Sxk6BzLL0z9Wb/UqKqkoBX2TpCfOPob9+OzBOM=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=Pc/9pv81bldjSvafd8IoWLh75voclhACzbmn68rHjTkCtAjo05p4HxoAJRBVE9gEjRJ6PA8a8aAhqCXvwbQDpdtvUqiQERD6PmLA6P90qsZVq9NbxbZcvw/ra3biPjyjc4oMh+4M2S7aJrva+0WSHTSNgeHi6fxWdan+JBPvQXY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1fc4fccdd78so7688575ad.2 for ; Thu, 08 Aug 2024 04:59:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723118376; x=1723723176; darn=gcc.gnu.org; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=UmibqKeRVDLaiS+scE7s/nKkaAAiOb9d8VzwfgNOS9c=; b=iY58ey4v7Kf6+WiFMbLBgvRdmTWOC+/ANRKXlcr6eNEMR8o/hE1lQySOE5DwigL+nW e4QBLVhU4CII4onjhtBARi3lCHs4w4sG0oaeXPTJO5UnHYeKkjFE7y/Q4cXqICdRxXFe DjyfDJ4vXObjFXVs1ursMxbco1PMPyv7Y2WaBUd2jxx/ZllHtJFbt47iqEKLDT7sROFf w2oTpM6h4inInCBNoidaKBamOQSCzX2Du+gsJ1q+RM0udfgDLqJu7Vj6wlOJTOE2XrNl WcByrfM0ZXGea9Kjm3cv7lDseJ0Ihzc179PjJ1D6zf884L9Tx6p4ZcB7r0QHwI4vH765 qhRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723118376; x=1723723176; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UmibqKeRVDLaiS+scE7s/nKkaAAiOb9d8VzwfgNOS9c=; b=ohvrGfr9+5KFt6wHC4Fz8wFOJfMworoZabe42U2isNQ4yaI2vAhaiczL7/xkVck+5Z 36XVuSxZ+pkB3keHHLsU3niYRi+qpLhnkEePFOdZAlBWD68Vytv9S/SfYLU20DB1sUfv mFoosqAElTx4Y2vS9H6eYgnAI51A+vwM5L8gHeGxZAK53r2VdLmMoWm5ydWdglh+wk1i bulkrg/5T+YwKEUexQygd7nV44Lu8QZVMBpFaOy5zdP6oVvzdVpPO2GN0FHMP2d+miTd Ran/L/AevFFNTjiooXnQ4kiOYnXKb/JfcGd4ao/5XbvaHwt79ZqE81wS7PbeBhJXXUZG 4aCQ== X-Gm-Message-State: AOJu0Yw5VsYxhjfoGqhWshdMFGEF1Mb8kOojnYiHZIPjsEL0lmkPabjS BdWKIdS3RVFZr2KIp3GPuBGuSvLcCIdMrrBj/b9deZmw9Y7mvgfIlGkNhA== X-Google-Smtp-Source: AGHT+IHNzTOmzQzriRpzN8Z3UtrbKVYGLPRGRO+AVQRp2izHcdKzTfiCLdXoEe3EsFD63oRYgZjeCg== X-Received: by 2002:a17:902:e80c:b0:1fb:cffb:cfc1 with SMTP id d9443c01a7336-2009521fb01mr22880935ad.4.1723118376406; Thu, 08 Aug 2024 04:59:36 -0700 (PDT) Received: from Thaum. (110-174-164-242.static.tpgi.com.au. [110.174.164.242]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff592979d7sm123243695ad.259.2024.08.08.04.59.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 04:59:35 -0700 (PDT) Message-ID: <66b4b327.170a0220.27dd28.60ca@mx.google.com> X-Google-Original-Message-ID: Date: Thu, 8 Aug 2024 21:59:30 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH] c++: Propagate TREE_ADDRESSABLE in fixup_type_variants [PR115062] MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.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 and regtested on x86_64-pc-linux-gnu, OK for trunk? The change to 'finish_struct_bits' is not required for this PR but I felt it was a nice cleanup; happy to commit without it though if preferred. -- >8 -- This has caused issues with modules when an import fills in the definition of a type already created with a typedef. PR c++/115062 gcc/cp/ChangeLog: * class.cc (fixup_type_variants): Propagate TREE_ADDRESSABLE. (finish_struct_bits): Cleanup now that TREE_ADDRESSABLE is propagated by fixup_type_variants. gcc/testsuite/ChangeLog: * g++.dg/modules/pr115062_a.H: New test. * g++.dg/modules/pr115062_b.H: New test. * g++.dg/modules/pr115062_c.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/class.cc | 31 ++++++++++------------- gcc/testsuite/g++.dg/modules/pr115062_a.H | 6 +++++ gcc/testsuite/g++.dg/modules/pr115062_b.H | 14 ++++++++++ gcc/testsuite/g++.dg/modules/pr115062_c.C | 9 +++++++ 4 files changed, 43 insertions(+), 17 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/pr115062_a.H create mode 100644 gcc/testsuite/g++.dg/modules/pr115062_b.H create mode 100644 gcc/testsuite/g++.dg/modules/pr115062_c.C diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc index 718601756dd..fb6c3370950 100644 --- a/gcc/cp/class.cc +++ b/gcc/cp/class.cc @@ -2312,6 +2312,7 @@ fixup_type_variants (tree type) TYPE_PRECISION (variant) = TYPE_PRECISION (type); TYPE_MODE_RAW (variant) = TYPE_MODE_RAW (type); TYPE_EMPTY_P (variant) = TYPE_EMPTY_P (type); + TREE_ADDRESSABLE (variant) = TREE_ADDRESSABLE (type); } } @@ -2378,8 +2379,17 @@ fixup_attribute_variants (tree t) static void finish_struct_bits (tree t) { - /* Fix up variants (if any). */ - fixup_type_variants (t); + /* If this type has a copy constructor or a destructor, force its + mode to be BLKmode, and force its TREE_ADDRESSABLE bit to be + nonzero. This will cause it to be passed by invisible reference + and prevent it from being returned in a register. */ + if (type_has_nontrivial_copy_init (t) + || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)) + { + SET_DECL_MODE (TYPE_MAIN_DECL (t), BLKmode); + SET_TYPE_MODE (t, BLKmode); + TREE_ADDRESSABLE (t) = 1; + } if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)) && TYPE_POLYMORPHIC_P (t)) /* For a class w/o baseclasses, 'finish_struct' has set @@ -2392,21 +2402,8 @@ finish_struct_bits (tree t) looking in the vtables). */ get_pure_virtuals (t); - /* If this type has a copy constructor or a destructor, force its - mode to be BLKmode, and force its TREE_ADDRESSABLE bit to be - nonzero. This will cause it to be passed by invisible reference - and prevent it from being returned in a register. */ - if (type_has_nontrivial_copy_init (t) - || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)) - { - tree variants; - SET_DECL_MODE (TYPE_MAIN_DECL (t), BLKmode); - for (variants = t; variants; variants = TYPE_NEXT_VARIANT (variants)) - { - SET_TYPE_MODE (variants, BLKmode); - TREE_ADDRESSABLE (variants) = 1; - } - } + /* Fix up variants (if any). */ + fixup_type_variants (t); } /* Issue warnings about T having private constructors, but no friends, diff --git a/gcc/testsuite/g++.dg/modules/pr115062_a.H b/gcc/testsuite/g++.dg/modules/pr115062_a.H new file mode 100644 index 00000000000..3c9daac317e --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr115062_a.H @@ -0,0 +1,6 @@ +// PR c++/115062 +// { dg-additional-options "-fmodule-header" } +// { dg-module-cmi {} } + +template class S; +typedef S X; diff --git a/gcc/testsuite/g++.dg/modules/pr115062_b.H b/gcc/testsuite/g++.dg/modules/pr115062_b.H new file mode 100644 index 00000000000..d8da59591ec --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr115062_b.H @@ -0,0 +1,14 @@ +// PR c++/115062 +// { dg-additional-options "-fmodule-header" } +// { dg-module-cmi {} } + +template +struct S { + int a; + long b; + union {}; + ~S(); + void foo(); +}; +extern template void S::foo(); +S operator+(S, const char *); diff --git a/gcc/testsuite/g++.dg/modules/pr115062_c.C b/gcc/testsuite/g++.dg/modules/pr115062_c.C new file mode 100644 index 00000000000..5255b9ffca7 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr115062_c.C @@ -0,0 +1,9 @@ +// PR c++/115062 +// { dg-additional-options "-fmodules-ts" } + +import "pr115062_a.H"; +import "pr115062_b.H"; + +int main() { + X x = X() + ""; +}