From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by sourceware.org (Postfix) with ESMTPS id 944A43858D1E for ; Thu, 9 Nov 2023 09:56:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 944A43858D1E 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 944A43858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699523769; cv=none; b=Oel01ujlheSOfhP5TPug0Xn85s88yLqEO+0JhlPFY083fHMBN93etoq2B/5IurG8Q0x3Y8e83rzkTYB4Aue4cWZvNbXHum9WlN8molgpt2/wT57A9hT5jxjdg2B/l9GfUek2JcWdsm56Q5e8xKBg2aSEgtX3EErB/rRUILeuaYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699523769; c=relaxed/simple; bh=g3ECoNjLHY/15X5Xnpf2mVMQkygo+J/gfYtwAJU627w=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=en4QtYQ6reXQ9RMN85jUAQIp0YK24YoCzgMugtJnYvYBpoPTsrAh5fJYjXojkN3lKbbzPxmurGzip4S/tETIRLpvbo+Ibn+NVhzGamzYS38CV38hHnJnm0dO873RhHTn73/FpRdrTOg1+eIX8NXh24QIxZxuiwAeGtl4IftvGYY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-5bcf83a8f6cso517646a12.2 for ; Thu, 09 Nov 2023 01:56:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699523764; x=1700128564; 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=UqCxlv4FDtDcKlIctjpS+3AkuuMEcC8WuStsavG9e88=; b=jOeHah3aFTMiDkY80JdtosWSs3+cyPLwUVy3+AoYP2BtJDJjK6luhNLt60Fi80IRgU +gyY6TYaGJySoWSA+Oudw7fO08T90fsO1xCbSwOc/lYgGD6unHJq4CkDqodBAbUu12ng DwKPMpykK4Jfiz+9fyMsdHpLU/IeuKuntuJQraxGtWy9Fdty1hS+ymGWGiN2ZcbKVnM8 Q4DwH8vagpEZrOZWwSshGiQwYSYIRGJjHSrW6dX1IozYbIpeKYGnz3UUVLdtawbioQ7W YzfKDXG3Uo50dNGuYg5tQVkOPXGH/28+N6+dnhWfwGClFWqS13Hq50q9KM3+dZHoqL+q qenQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699523764; x=1700128564; 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=UqCxlv4FDtDcKlIctjpS+3AkuuMEcC8WuStsavG9e88=; b=u+BvqlAD6fmJFeKr/8K5NxeSe9V36FIsFg+VbMeduqk2zslUbzhIxT8USa1g4eeXWO Ha+PcaZob5eQKDzpndTCvsjWwpPWPvbNQeJXFdNVDi6HbxkfAtTMl+oWNqoqHCDfvL7Q 0N6Nbky83bh5NS4NuzpCuogQzidmhsMHAH0gvcDvsCuJuYbeLD7f+UBDgs2cKOi5Oo0o D+wnYqZ6v2yn9GvGC4g/z2gv+ruiGERmAYp9Zq5nBTzwHOMQrTyZDhaGdR1kzBHzvf+M ouATdnRHKUW0UFDpc5kflU9HkP8y6Oj6lhKfQ+/cRAC0loK65dBXtdhQzcWpG3sC6wDi XZ9g== X-Gm-Message-State: AOJu0Yz3KEi8aahdVvIxtnUfB6ytttZAAxwrr2nGFe4GKLQjMwjbMy4G KkVPxZgI5lXHlMoDwc0gAn5F83j2xDs= X-Google-Smtp-Source: AGHT+IGm69nXDBI6m4Rl5dTTtHZAEf1sqEZRAJ7x/miLHPhd4PNkcbURQ/u29zA02ZyMmnO4OVm4pQ== X-Received: by 2002:a05:6a20:c19b:b0:184:9f3d:f7ba with SMTP id bg27-20020a056a20c19b00b001849f3df7bamr5727911pzb.33.1699523763735; Thu, 09 Nov 2023 01:56:03 -0800 (PST) Received: from Thaum. (124-150-88-161.tpgi.com.au. [124.150.88.161]) by smtp.gmail.com with ESMTPSA id h17-20020a170902f7d100b001c61073b076sm3128485plw.144.2023.11.09.01.56.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 01:56:03 -0800 (PST) Message-ID: <654cacb3.170a0220.9f692.95e6@mx.google.com> X-Google-Original-Message-ID: Date: Thu, 9 Nov 2023 20:55:58 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH] c++/modules: fix virtual destructors [PR103499] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-11.8 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,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: I'm not sure if this is just papering over a general issue of clones not being exported/imported, or if this is just an exception to the general case of clones being able to be freely regenerated with no other issues. Alternatively, would it be better to override the DECL_VINDEX of the original declaration after filling it in for the clones as well? I wasn't able to see anything depending on the current behaviour (though I didn't look very hard). Bootstrapped and regtexted on x86_64-pc-linux-gnu. -- >8 -- Currently, cloned functions are not included in the CMI. However, for virtual destructors the clones must have a different DECL_VINDEX from their base declaration: the former have an INTEGER_CST indicating the index into the vtable, while the latter indicate the FUNCTION_DECL that they're overriding. As such, this patch ensures that DECL_VINDEX is properly passed on for cloned functions as well to prevent this from causing issues. PR c++/103499 gcc/cp/ChangeLog: * module.cc (trees_out::decl_node): Write DECL_VINDEX for virtual clones. (trees_in::tree_node): Read DECL_VINDEX for virtual clones. gcc/testsuite/ChangeLog: * g++.dg/modules/pr103499_a.C: New test. * g++.dg/modules/pr103499_b.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/module.cc | 6 ++++++ gcc/testsuite/g++.dg/modules/pr103499_a.C | 12 ++++++++++++ gcc/testsuite/g++.dg/modules/pr103499_b.C | 8 ++++++++ 3 files changed, 26 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/pr103499_a.C create mode 100644 gcc/testsuite/g++.dg/modules/pr103499_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index c1c8c226bc1..416a7c414cc 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -8648,6 +8648,8 @@ trees_out::decl_node (tree decl, walk_kind ref) tree_node (target); tree_node (DECL_NAME (decl)); + if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl)) + tree_node (DECL_VINDEX (decl)); int tag = insert (decl); if (streaming_p ()) dump (dumper::TREE) @@ -9869,6 +9871,10 @@ trees_in::tree_node (bool is_use) } } + /* A clone might have a different vtable entry. */ + if (res && TREE_CODE (res) == FUNCTION_DECL && DECL_VIRTUAL_P (res)) + DECL_VINDEX (res) = tree_node (); + if (!res) set_overrun (); int tag = insert (res); diff --git a/gcc/testsuite/g++.dg/modules/pr103499_a.C b/gcc/testsuite/g++.dg/modules/pr103499_a.C new file mode 100644 index 00000000000..0497c2c5504 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr103499_a.C @@ -0,0 +1,12 @@ +// PR c++/103499 +// { dg-module-do compile } +// { dg-additional-options "-fmodules-ts" } +// { dg-module-cmi pr103499 } + +export module pr103499; + +export struct base { + virtual ~base() = default; +}; + +export struct derived : base {}; diff --git a/gcc/testsuite/g++.dg/modules/pr103499_b.C b/gcc/testsuite/g++.dg/modules/pr103499_b.C new file mode 100644 index 00000000000..b7468562ba9 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr103499_b.C @@ -0,0 +1,8 @@ +// PR c++/103499 +// { dg-additional-options "-fmodules-ts" } + +import pr103499; + +void test(derived* p) { + delete p; +} -- 2.42.0