From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by sourceware.org (Postfix) with ESMTPS id 51E703858C2B for ; Thu, 23 Nov 2023 17:12:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 51E703858C2B Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 51E703858C2B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700759524; cv=none; b=a8O3zES1n4yaRoqF99/VVOZ7zs3z36u9K2/Vd2WgbqVwcoFBtPY+WY1jBz5wujjPPC3FDsF9yBVQtPuVmgsKOwPtsaVhzVwtansy3Bnzx/dyJwgAvJH1Z9zxM4OrNZKlhavniR67jDKHK0XN1ud7mwqUxLGgwABzX38Ex3ZHnAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700759524; c=relaxed/simple; bh=yZnai5R/8m+YRSr0RbSwvnmRu7arw6CD+B/dxgBqilc=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=F8O33T97Nou6xUEJ53JHZYwzjzinYWDf4Xzb0MNmhjRAFMCtsFrZGtC3Ub8nrVpe/HNU8xv5oRTdLta2DaeQc+AlCJjJW3eOlSEjIYwvBDpXvfQt0zgDBdC21hwt8Vz6H3idP8DCfDNV5pX87Dxl/NcUIihYMZw7r+rlHTBx6Cc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf33.google.com with SMTP id 6a1803df08f44-679dc22f2b7so5884236d6.2 for ; Thu, 23 Nov 2023 09:12:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700759521; x=1701364321; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=gyLXOhl/1jXLSSZPs0YC/S/Y/oyczHCi4fS8INJ2EJk=; b=INrctKARoXu4PJzjlMP7wvc0RzPPuMKHygqzqp16DZ904iM+JYbdOnqmMXl2rGSgdS me9XmQe3ex0aesGnoX9orXcBYc6ZkXUB8m6lqDUuEUmztrSUBf2qoghiCfpKsInIc33W K75MJQ/emG43rXLNR9LRhCBV3CDKk6qlWefR+5urEp0kP0nl29C9IhP0CZTvHkforn5v 7or4TIa32EZAU3ocRFveeSGaEmbCLlxQC4z1hR9dZ7Fk/INhLuRo6ohMoJMMGQjMp/6/ Jz0gkmAMbQErrJiqV3JH5MK8XNypFjXmVHKlgfi6xL02Dy1oruDAV4wjlIOmCTcttPuH 869w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700759521; x=1701364321; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gyLXOhl/1jXLSSZPs0YC/S/Y/oyczHCi4fS8INJ2EJk=; b=F9+tElVlRotT+zT+HCIbhiKAcWpR3SGLYZnp63vtcj8uQHG9/nCxmB6xKnqNoIvKxQ 2W3e27wjbJjxhjCqLHV1sO4t2SnrnqfPhzLr0c8dqzUY3TpkZRodskesCG2KHCo5pzjD slIBGUJoRkVFGTmQVoqPaw9y1Tew+rbg6z1dtUoDQw3m7r3GcXpNN0nmgh0KxWsrbHi/ 9xM6SNIuz5OsPSq4/zMJ+fyI0c5m6D1OTGRE7DL7Jix/pz7c6/aplgao9ct6pU/nEXFd 183ecwMz4w1xJeQdS/vWITD4KnOJPoau5UR407AsZDep+kpvFcrKDN7zxaRBFSNnbyFs INJw== X-Gm-Message-State: AOJu0YxrjzYCMduNFaQ8x97dgQyIz504DuKRpKObJych9XjE4ikgu6+A u2co9iIaNK8axGbIbZo+lQo= X-Google-Smtp-Source: AGHT+IFM/2r8TRIHwoIcfxEvkYRS3mM2Fh2AR74OIuaEIMojLKJy6he5ANDpdNaqlVUVzHQqw9bd2A== X-Received: by 2002:a05:6214:1774:b0:67a:ddd:e16a with SMTP id et20-20020a056214177400b0067a0ddde16amr94471qvb.58.1700759521591; Thu, 23 Nov 2023 09:12:01 -0800 (PST) Received: from ?IPV6:2601:19c:5282:9160::4? ([2601:19c:5282:9160::4]) by smtp.googlemail.com with ESMTPSA id n6-20020a056214008600b0067a0dc300d9sm305324qvr.10.2023.11.23.09.12.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Nov 2023 09:12:01 -0800 (PST) Sender: Nathan Sidwell Message-ID: <4b2df9c9-6658-4240-9f4f-4f7197c64490@acm.org> Date: Thu, 23 Nov 2023 12:11:58 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++/modules: Restrict partitions when parsing import declarations [PR110808] Content-Language: en-US To: Nathaniel Shead , gcc-patches@gcc.gnu.org Cc: Jason Merrill References: <655312af.630a0220.8e418.ba89@mx.google.com> From: Nathan Sidwell In-Reply-To: <655312af.630a0220.8e418.ba89@mx.google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3038.2 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 List-Id: On 11/14/23 01:24, Nathaniel Shead wrote: > I'll also note that the comments above the parsing functions here no > longer exactly match with the grammar in the standard, should they be > updated as well? please. > > Bootstrapped and regtested on x86_64-pc-linux-gnu. I don't have write > access. > > -- >8 -- > > Currently we allow declarations like 'import A:B', even from an > unrelated source file (not part of module A), which causes errors in > merging declarations. However, the syntax in [module.import] doesn't > even allow this form of import, so this patch prevents this from > parsing at all and avoids the error that way. ok, I messed that one right up :) > > PR c++/110808 > > gcc/cp/ChangeLog: > > * parser.cc (cp_parser_module_name): Add param import_p. > Disallow partitions after module-name for import decls. > (cp_parser_module_declaration): Pass import_p = false. > (cp_parser_import_declaration): Pass import_p = true. > > gcc/testsuite/ChangeLog: > > * g++.dg/modules/part-hdr-1_c.C: Fix syntax. > * g++.dg/modules/part-mac-1_c.C: Likewise. > * g++.dg/modules/part-8_a.C: New test. > * g++.dg/modules/part-8_b.C: New test. > * g++.dg/modules/part-8_c.C: New test. > > Signed-off-by: Nathaniel Shead > --- > gcc/cp/parser.cc | 11 ++++++----- > gcc/testsuite/g++.dg/modules/part-8_a.C | 6 ++++++ > gcc/testsuite/g++.dg/modules/part-8_b.C | 6 ++++++ > gcc/testsuite/g++.dg/modules/part-8_c.C | 8 ++++++++ > gcc/testsuite/g++.dg/modules/part-hdr-1_c.C | 2 +- > gcc/testsuite/g++.dg/modules/part-mac-1_c.C | 2 +- > 6 files changed, 28 insertions(+), 7 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/modules/part-8_a.C > create mode 100644 gcc/testsuite/g++.dg/modules/part-8_b.C > create mode 100644 gcc/testsuite/g++.dg/modules/part-8_c.C > > diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc > index 5116bcb78f6..72a5c52313d 100644 > --- a/gcc/cp/parser.cc > +++ b/gcc/cp/parser.cc > @@ -14858,10 +14858,11 @@ cp_parser_already_scoped_statement (cp_parser* parser, bool *if_p, > module-name . identifier > header-name > > - Returns a pointer to module object, NULL. */ > + Returns a pointer to module object, or NULL. Also parses an optional > + module-partition after the module-name unless IMPORT_P is true. */ > > static module_state * > -cp_parser_module_name (cp_parser *parser) > +cp_parser_module_name (cp_parser *parser, bool import_p) > { > cp_token *token = cp_lexer_peek_token (parser->lexer); > if (token->type == CPP_HEADER_NAME) > @@ -14890,7 +14891,7 @@ cp_parser_module_name (cp_parser *parser) > tree name = cp_lexer_consume_token (parser->lexer)->u.value; > parent = get_module (name, parent, partitioned); > token = cp_lexer_peek_token (parser->lexer); > - if (!partitioned && token->type == CPP_COLON) > + if (!partitioned && !import_p && token->type == CPP_COLON) > partitioned = true; > else if (token->type != CPP_DOT) > break; > @@ -14961,7 +14962,7 @@ cp_parser_module_declaration (cp_parser *parser, module_parse mp_state, > } > else > { > - module_state *mod = cp_parser_module_name (parser); > + module_state *mod = cp_parser_module_name (parser, /*import_p=*/false); > tree attrs = cp_parser_attributes_opt (parser); > > mp_state = MP_PURVIEW_IMPORTS; > @@ -15004,7 +15005,7 @@ cp_parser_import_declaration (cp_parser *parser, module_parse mp_state, > } > else > { > - module_state *mod = cp_parser_module_name (parser); > + module_state *mod = cp_parser_module_name (parser, /*import_p=*/true); > tree attrs = cp_parser_attributes_opt (parser); > > if (!mod || !cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON)) > diff --git a/gcc/testsuite/g++.dg/modules/part-8_a.C b/gcc/testsuite/g++.dg/modules/part-8_a.C > new file mode 100644 > index 00000000000..09f956ff36f > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/part-8_a.C > @@ -0,0 +1,6 @@ > +// PR c++/110808 > +// { dg-additional-options "-fmodules-ts" } > +// { dg-module-cmi group:tres } > + > +export module group:tres; > +int mul() { return 0; } > diff --git a/gcc/testsuite/g++.dg/modules/part-8_b.C b/gcc/testsuite/g++.dg/modules/part-8_b.C > new file mode 100644 > index 00000000000..1ade029495c > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/part-8_b.C > @@ -0,0 +1,6 @@ > +// PR c++/110808 > +// { dg-additional-options "-fmodules-ts" } > +// { dg-module-cmi group } > + > +export module group; > +export import :tres; > diff --git a/gcc/testsuite/g++.dg/modules/part-8_c.C b/gcc/testsuite/g++.dg/modules/part-8_c.C > new file mode 100644 > index 00000000000..2351f28f909 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/part-8_c.C > @@ -0,0 +1,8 @@ > +// PR c++/110808 > +// { dg-additional-options "-fmodules-ts" } > + > +import group:tres; // { dg-error "expected .;." } > + > +int main() { > + return mul(); // { dg-error "not declared" } > +} > diff --git a/gcc/testsuite/g++.dg/modules/part-hdr-1_c.C b/gcc/testsuite/g++.dg/modules/part-hdr-1_c.C > index 78a53d2fda3..db57adcef44 100644 > --- a/gcc/testsuite/g++.dg/modules/part-hdr-1_c.C > +++ b/gcc/testsuite/g++.dg/modules/part-hdr-1_c.C > @@ -2,4 +2,4 @@ > // { dg-module-cmi {mod} } > > export module mod; > -import mod:impl; > +import :impl; > diff --git a/gcc/testsuite/g++.dg/modules/part-mac-1_c.C b/gcc/testsuite/g++.dg/modules/part-mac-1_c.C > index 78a53d2fda3..db57adcef44 100644 > --- a/gcc/testsuite/g++.dg/modules/part-mac-1_c.C > +++ b/gcc/testsuite/g++.dg/modules/part-mac-1_c.C > @@ -2,4 +2,4 @@ > // { dg-module-cmi {mod} } > > export module mod; > -import mod:impl; > +import :impl; -- Nathan Sidwell