From patchwork Wed Mar 6 19:10:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1909000 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=YgaQo8LD; 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 4Tqhqb1dLQz1yX0 for ; Thu, 7 Mar 2024 06:11:22 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 571B6385801C for ; Wed, 6 Mar 2024 19:11:20 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id 5DD6E3858401 for ; Wed, 6 Mar 2024 19:10:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5DD6E3858401 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 5DD6E3858401 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709752259; cv=none; b=vEz9ohp0D/eHpnJgwLY8vct1UwANCPoQs5FJmffFencCenv80l+6cOdMYkWgEiv1OsZkFFrjXgxDeEQ12Ur5Pw/6aBhc3lstEYC7fuBSbedKm/gHY4fcrDUqJVKzOJ0TkyIa9EC+L6XPzQfWfZlK1aYvBNwnFKKL3iqfl+5w9ZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709752259; c=relaxed/simple; bh=E/Y8BIJNLnFFnFc2we0MadiNwF52onVPDt7swD8J2Sc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=K7vzFoPp+VAAFHLqtl1JEQr7E5L+mIYXsfa+r0jgXbpLp54M43SBuZoyfxTsol8i9zMmpSfxp+aq1QadA8D1eDGODQ6WUfNhmANR0iDQ4xun9Ai2ZOZ5EmRkBQItuYpStK5YNsMKmcF/lAILnWyn9f8nLccywLJKRpcSu7+l9PY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709752256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+62rrveLny4wHcGhFqqMT/rtANnf0jOWykLBuc0i92Y=; b=YgaQo8LDubied1krc0DU0MDctFCfXSPlbiTbXh05fQZRpJZw+Y4GlesYTdtXJeKeKDAvSe XL55HCvf8fcyYLrAnw/Dt98kEaPgzAGPHtuL1ccmcmil/BCfOyBzwP3N//dF1OVAHWw25C 0i/cYMHkWb4O7WIgOrhPTaB0wqO4o18= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-118-Qg3VHw-hMq-sCOsHBqKeyw-1; Wed, 06 Mar 2024 14:10:54 -0500 X-MC-Unique: Qg3VHw-hMq-sCOsHBqKeyw-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-788440fa805so10420085a.1 for ; Wed, 06 Mar 2024 11:10:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709752253; x=1710357053; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+62rrveLny4wHcGhFqqMT/rtANnf0jOWykLBuc0i92Y=; b=ssaJiar2dLR9v3aeCY/9Mh8whfzHAfb5grDd/ybyX5PwT+1mad+osSLVtsKAArm10x rO8q6156jdWotux+sDOKtmKxDNE3/YdvaJeXAb6ZIolWWyGfHDM3rgkqaxUouutGaqdH B9hZMlccJzBFkqdNyB8YyLK9sCOvqz3yWGwQ72UNqmsfX4LgRKMRm64ZslvNv3txLRcV qPsFKvrV1DuXz0t6HniK+F96uD6yhpzADZ14EEFSiiUe+AmJGsbKS/oRuPSIVV53HLuh obbnNZoOug1EI+DEoeLJ+NgYuL8vtGJEYTXgzz+ad0NV5dRHmHoZm6QgDHq2gEJjXlWK wf8A== X-Gm-Message-State: AOJu0YzvvV5NYLY/Q/OIvKGXNxwI+FmmBBM5Fr3e891qRDDcMsBHRCMq ZePe/ripKAfIFT76bP3H7Px9QRp4+0RBz0ICRsRmIHbWQ0EgAtzXS7Y3a5AfAzmW6iOwq5CtImC hPx41U9GJf86w4PR1hdEEGptMlqPuABz5WGgjB/GSwbsWcamXEAjWpr77g2Mxvg1Gb7hRc5clTH n53h5pRFx1YzvBy/1wBI7iV6kn02QzcGo28qVh X-Received: by 2002:a05:620a:3906:b0:788:2b40:fbce with SMTP id qr6-20020a05620a390600b007882b40fbcemr7157049qkn.47.1709752253081; Wed, 06 Mar 2024 11:10:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IGzazxkUFukDpQO3i26JWUg3+AIw8unDoiwLduQedYrDOpPi9DH7d1AjHd2Cqd5iz5crhbagA== X-Received: by 2002:a05:620a:3906:b0:788:2b40:fbce with SMTP id qr6-20020a05620a390600b007882b40fbcemr7157014qkn.47.1709752252554; Wed, 06 Mar 2024 11:10:52 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id c19-20020ae9e213000000b00788228fbe05sm4169523qkc.17.2024.03.06.11.10.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 11:10:52 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, nathan@acm.org, Patrick Palka Subject: [PATCH] c++/modules: inline namespace abi_tag streaming [PR110730] Date: Wed, 6 Mar 2024 14:10:42 -0500 Message-ID: <20240306191042.1883372-1-ppalka@redhat.com> X-Mailer: git-send-email 2.44.0.117.g43072b4ca1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 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_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_BLACK 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 Tested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- The unreduced testcase from this PR crashes at runtime ultimately because we don't stream the abi_tag attribute on inline namespaces and so the filesystem::current_path() call resolves to the non-C++11 ABI version even though the C++11 ABI is active, leading to a crash when destructing the call result (which contains an std::string member). While we do stream the DECL_ATTRIBUTES of all decls that go through the generic tree streaming routines, it seems namespaces are streamed separately from other decls and we don't use the generic routines for them. So this patch makes us stream the abi_tag manually for (inline) namespaces. PR c++/110730 gcc/cp/ChangeLog: * module.cc (module_state::write_namespaces): Stream the abi_tag attribute of an inline namespace. (module_state::read_namespaces): Likewise. gcc/testsuite/ChangeLog: * g++.dg/modules/namespace-6_a.H: New test. * g++.dg/modules/namespace-6_b.C: New test. --- gcc/cp/module.cc | 32 ++++++++++++++++++++ gcc/testsuite/g++.dg/modules/namespace-6_a.H | 10 ++++++ gcc/testsuite/g++.dg/modules/namespace-6_b.C | 7 +++++ 3 files changed, 49 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/namespace-6_a.H create mode 100644 gcc/testsuite/g++.dg/modules/namespace-6_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index d9e34e9a4b9..ce62c3341a6 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -15411,6 +15411,22 @@ module_state::write_namespaces (elf_out *to, vec spaces, sec.u (flags); write_location (sec, DECL_SOURCE_LOCATION (ns)); + + if (DECL_NAMESPACE_INLINE_P (ns)) + { + if (tree tags = lookup_attribute ("abi_tag", DECL_ATTRIBUTES (ns))) + { + tags = TREE_VALUE (tags); + unsigned count = 0; + for (tree tag = tags; tag; tag = TREE_CHAIN (tag)) + ++count; + sec.u (count); + for (tree tag = tags; tag; tag = TREE_CHAIN (tag)) + sec.str (TREE_STRING_POINTER (TREE_VALUE (tag))); + } + else + sec.u (0); + } } sec.end (to, to->name (MOD_SNAME_PFX ".nms"), crc_p); @@ -15441,6 +15457,7 @@ module_state::read_namespaces (unsigned num) /* See comment in write_namespace about why not bits. */ unsigned flags = sec.u (); location_t src_loc = read_location (sec); + unsigned tags_count = (flags & 2) ? sec.u () : 0; if (entity_index >= entity_num || !parent @@ -15449,6 +15466,17 @@ module_state::read_namespaces (unsigned num) if (sec.get_overrun ()) break; + tree tags = NULL_TREE; + while (tags_count--) + { + size_t len; + const char *str = sec.str (&len); + if (sec.get_overrun ()) + break; + tags = tree_cons (NULL_TREE, build_string (len + 1, str), tags); + tags = nreverse (tags); + } + tree id = name ? get_identifier (from ()->name (name)) : NULL_TREE; dump () && dump ("Read namespace:%u %P%s%s%s%s", @@ -15477,6 +15505,10 @@ module_state::read_namespaces (unsigned num) DECL_MODULE_EXPORT_P (inner) = true; } + if (tags) + DECL_ATTRIBUTES (inner) + = tree_cons (get_identifier ("abi_tag"), tags, DECL_ATTRIBUTES (inner)); + /* Install the namespace. */ (*entity_ary)[entity_lwm + entity_index] = inner; if (DECL_MODULE_IMPORT_P (inner)) diff --git a/gcc/testsuite/g++.dg/modules/namespace-6_a.H b/gcc/testsuite/g++.dg/modules/namespace-6_a.H new file mode 100644 index 00000000000..b412cbe6cbf --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/namespace-6_a.H @@ -0,0 +1,10 @@ +// PR c++/110730 +// { dg-additional-options -fmodule-header } +// { dg-module-cmi {} } + +namespace std::filesystem { + inline namespace __cxx11 __attribute__((__abi_tag__("cxx11", "foo"))) { + struct path { }; + } + inline path current_path() { return {}; }; +} diff --git a/gcc/testsuite/g++.dg/modules/namespace-6_b.C b/gcc/testsuite/g++.dg/modules/namespace-6_b.C new file mode 100644 index 00000000000..2ce41c7c9c7 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/namespace-6_b.C @@ -0,0 +1,7 @@ +// PR c++/110730 +// { dg-additional-options -fmodules-ts } + +import "namespace-6_a.H"; + +int main() { std::filesystem::current_path(); } +// { dg-final { scan-assembler _ZNSt10filesystem12current_pathB5cxx11B3fooEv } }