From patchwork Thu May 12 11:18:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1630104 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=NKG17x/6; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KzTmK39Fbz9sFx for ; Thu, 12 May 2022 21:18:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0AB103843870 for ; Thu, 12 May 2022 11:18:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by sourceware.org (Postfix) with ESMTPS id A4268385742D for ; Thu, 12 May 2022 11:18:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A4268385742D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qt1-x82e.google.com with SMTP id t16so3985591qtr.9 for ; Thu, 12 May 2022 04:18:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:message-id:date:mime-version:user-agent:content-language:to :cc:from:subject; bh=+90uP4Yf00h+ZI+DEsVpZuoCSOOdNRH4JwJwqhLMyw8=; b=NKG17x/6RPbw3VfEj7+ErdVPK+w3mlvu8gFLNcOrMqglt9Xg+6MWH9rLu3pfJjeMc7 /kJOuZSbmau0Je/ekYnpqHo849IIooYFntEMyw13PBQSDbzF6d1cJCgzzp7vBB1WV4+w MkmRa2ID9ceENTvvqv+2WoHxW1Xknis6g1NSO9CNsl5gahrl/+kodhJULVXYbF2NK5Xs 2GFZhyo8gufNMEHF0ifjodjMmS0Hg+oFxKBo3a/Db0qP+oHC9105bHTvIcqOMVV44THu r/n0J5ICPrk0Ja4Ul2IPyQLYk25CtWK7i4mJPNYDmFW2XsE+uEcBEfB+dPs8jKwMxP1C zkKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:message-id:date:mime-version:user-agent :content-language:to:cc:from:subject; bh=+90uP4Yf00h+ZI+DEsVpZuoCSOOdNRH4JwJwqhLMyw8=; b=ntBi/H4idqE1sVJoniY12nHnGghoqVp0yHhJFNuB6315Hp5t/XoOYpSELLCLjJAM6F 12d5EL+jIZQAQe8x2cm1DFLnYSysf4lv7JjYYf6dnvqKOAb/OguB3jQzDv3mq5GtExK7 cG3Fmp5oqZuSbOJzIAfVtN4B8cMAM/Z/HY1dkByA7kwwKQKC+yW+i5R77l/jn5Q8I3ED m7wJ56dxGzp76Nkj5JKD1oAD3th8CE0q1kXgNx6fFCoRxe/gKMRXbh8cOaZWtnbG7LyQ xwSTOig0/99pJGlp7BDxU2bBNWdSouwhOVfWe1Y0+p3n8GFmrkOJd92tliQ9k9HCfHsZ tkyQ== X-Gm-Message-State: AOAM531B8LTi5lB39K8uUumsxKJ6et+w5rwQTL4m9BuYhHLM7aEuVH9G c/AsfzU/zLyCpN5HKzoCT43NX8sUkLI= X-Google-Smtp-Source: ABdhPJxjibYkRdpBIR/zDY2BnUk7ZW1J8hOQoyOJJ1LjYwnWBeUjBNhuKFfr4MlFyV+DnYESBwAVdg== X-Received: by 2002:ac8:578c:0:b0:2f3:edf0:698a with SMTP id v12-20020ac8578c000000b002f3edf0698amr8280421qta.418.1652354287724; Thu, 12 May 2022 04:18:07 -0700 (PDT) Received: from ?IPV6:2620:10d:c0a3:1407:e594:a635:7d2b:2991? ([2620:10d:c091:500::1:e655]) by smtp.googlemail.com with ESMTPSA id j1-20020ac85501000000b002f39b99f69asm2769177qtq.52.2022.05.12.04.18.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 May 2022 04:18:07 -0700 (PDT) Message-ID: <5bb16ba7-9ff1-161c-b17d-a71b09f902d6@acm.org> Date: Thu, 12 May 2022 07:18:06 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Content-Language: en-US To: GCC Patches From: Nathan Sidwell Subject: c++: Support module language-decl semantics X-Spam-Status: No, score=-3039.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jonathan Wakely Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" In modules purview, one can attach a declaration to the global module (i.e. not the named module in whence the declaration appears), using a language declaration: export module Foo; extern "C++" void *operator new (std::size_t); This implements those semantics. Jonathan, I guess this might help with modularizing std? nathan From 78c8b0b980341f28de96da518a38bf85bbd24d98 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 9 May 2022 04:51:32 -0700 Subject: [PATCH] c++: Support module language-decl semantics In modules purview, one can attach a declaration to the global module (i.e. not the named module in whence the declaration appears), using a language declaration: export module Foo; extern "C++" void *operator new (std::size_t); This implements those semantics. gcc/cp/ * parser.cc (cp_parser_linkage_specification): Implement global module attachment semantics. gcc/testsuite/ * g++.dg/modules/lang-3_a.C: New. * g++.dg/modules/lang-3_b.C: New. * g++.dg/modules/lang-3_c.C: New. --- gcc/cp/parser.cc | 3 +++ gcc/testsuite/g++.dg/modules/lang-3_a.C | 17 +++++++++++++++++ gcc/testsuite/g++.dg/modules/lang-3_b.C | 18 ++++++++++++++++++ gcc/testsuite/g++.dg/modules/lang-3_c.C | 12 ++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/lang-3_a.C create mode 100644 gcc/testsuite/g++.dg/modules/lang-3_b.C create mode 100644 gcc/testsuite/g++.dg/modules/lang-3_c.C diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 84f379c7bff..8969ed0076a 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -16189,6 +16189,8 @@ cp_parser_linkage_specification (cp_parser* parser, tree prefix_attr) linkage = get_identifier (TREE_STRING_POINTER (linkage)); /* We're now using the new linkage. */ + unsigned saved_module = module_kind; + module_kind &= ~MK_ATTACH; push_lang_context (linkage); /* Preserve the location of the innermost linkage specification, @@ -16235,6 +16237,7 @@ cp_parser_linkage_specification (cp_parser* parser, tree prefix_attr) /* We're done with the linkage-specification. */ pop_lang_context (); + module_kind = saved_module; /* Restore location of parent linkage specification, if any. */ parser->innermost_linkage_specification_location = saved_location; diff --git a/gcc/testsuite/g++.dg/modules/lang-3_a.C b/gcc/testsuite/g++.dg/modules/lang-3_a.C new file mode 100644 index 00000000000..1c6fa1fa2e9 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/lang-3_a.C @@ -0,0 +1,17 @@ +// { dg-additional-options "-fmodules-ts -Wno-pedantic" } +module; +# 4 __FILE__ 1 +void Quux (); +# 6 "" 2 +export module bob; +// { dg-module-cmi bob } + +extern "C++" +{ +export void Bar () {} +export void Quux (); +void Baz () {} +} + +// { dg-final { scan-assembler {_Z3Barv:} } } +// { dg-final { scan-assembler {_Z3Bazv:} } } diff --git a/gcc/testsuite/g++.dg/modules/lang-3_b.C b/gcc/testsuite/g++.dg/modules/lang-3_b.C new file mode 100644 index 00000000000..17300ece699 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/lang-3_b.C @@ -0,0 +1,18 @@ +// { dg-additional-options -fmodules-ts } +import bob; + +void Foo () +{ + Bar (); + Baz (); // { dg-error "was not declared" } + Quux (); +} + +void Bar (); +void Baz (); + +void Quux () +{ + Bar (); + Baz (); +} diff --git a/gcc/testsuite/g++.dg/modules/lang-3_c.C b/gcc/testsuite/g++.dg/modules/lang-3_c.C new file mode 100644 index 00000000000..ca18db72ad8 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/lang-3_c.C @@ -0,0 +1,12 @@ +// { dg-additional-options -fmodules-ts } +module bob; + +void Foo () +{ + Bar (); + Baz (); +} + +extern "C++" void Bar (); +extern "C++" void Baz (); + -- 2.30.2