From patchwork Wed May 29 13:42:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1941269 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=NMnF1kyV; 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 4Vq9gz72mkz20Pc for ; Wed, 29 May 2024 23:48:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0943B3858C50 for ; Wed, 29 May 2024 13:48:14 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 9C59A3858C50 for ; Wed, 29 May 2024 13:47:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9C59A3858C50 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 9C59A3858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716990471; cv=none; b=iQtdvVtq8CwOMn/YT6poFBdVkkH1phcPboblMtwki8bYwWondxHrbuI4SMNGjQ+hFWJsUyp2vWkgxrOHNrQFM/I+iglwfDeP9EnVees/vZuqMkJJ03dTUrvwHAFSCcUP4/C4R9z7bCv4b2q2KonwYQ6ZOog4/3uwfGrwAba2TCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716990471; c=relaxed/simple; bh=3XR8LiGFZvZlj+5Mlqnx7i/3MBFp+Z/lII7recbaypc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kZ/Usj5cgLmjkY7XDTMV9RrBqtiaZoU5fULh79Jd/rm1EzrwY93QeHI8mOQw+9GPppm/2pVMpOgHjwGpcYAGajlBmCPnc29A3OUm6LFY/7O/YTEicXcpqEvvGVC4kpIWVQt0OjoOk7MzF8kItcZzf4xbAB4SKp47BNQtT6BS4IA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716990468; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=92TNJTzL/HxpHVXRQG+1Lf4mfYqsuUGFMBF3zeORkoM=; b=NMnF1kyVXpUvodJIqWeg/uvMCpBedk2raqWOUCF0xBeP4Yl+YewLcQYQP83LrSTJkOMls8 n8TF270cq4vayhMM/RcUcm28EiH0P7vX582Dzk91DHtBV9nNLgZLNLdaj5xzCKMi5zAspc DUR0udqgxPbT1I0KyFyiMvnnKhTbvWw= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-695-sn2DFMzXNR2AQaBe_NLzFw-1; Wed, 29 May 2024 09:47:46 -0400 X-MC-Unique: sn2DFMzXNR2AQaBe_NLzFw-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6ab9056087cso25362226d6.3 for ; Wed, 29 May 2024 06:47:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716990466; x=1717595266; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=92TNJTzL/HxpHVXRQG+1Lf4mfYqsuUGFMBF3zeORkoM=; b=IISQ9goQGEI18Cdz5AaSB5vHzrE6QYDGEk5c61i0oP3tfn/Fx3ALfPzqQx2gNoOUj/ A6AI9gLsfFk8AwpZya52GnCG2znOby4HgeYd94AAxTmgGalPV0fcmHVoq8Gb1kgCkmBw Vd29GW4pVX0Ee59g8RdBAzE46Npd8hQ3PcP/UOHmt4i/fcbAvo3d+w40efXZRyh4i5LH IWyzLn2uLpLuNQ/b3hhNnLsb+XDoODhT1LvD9M+zwn7Cxtt4EZU1fVxnzfWhG1rHwhhp zb5F531OWelIzh5iRGcfGLjonTk7cykbFMs+J8m69ivZi0CyIFqH3yEw+BzAUx1sBGEv Cajg== X-Gm-Message-State: AOJu0Yzsh97K40d2IYmzgqTXm6VSnwa6IGZzDILKH/OhV0LvtzkuLMhp QDNu4LwFW9vfcrrlqDG1mq7KE7oQSt2+mpqNAOJJ726gLENtJgDcgd9VoK+50HlV/MO4k8sh/p+ WsKhJp4wtywEZAQ9kvghIj9y/c17Pe7IXBJv/JurAuV6hKrEoOf7gBDjby+cToWq8W/G/0DPeLt +zX/Pi1SeN41G49NasW4U4fHR/qPAVMV6Juto= X-Received: by 2002:a05:6214:449e:b0:6ab:6c18:57d0 with SMTP id 6a1803df08f44-6abcd0b203amr185601046d6.36.1716990465806; Wed, 29 May 2024 06:47:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHqniLAl6+t2is6wL8g89UYO7JvYur9tLTmabYcysQGcLL3o67J12jpfxpZng5w2rudxiXzCA== X-Received: by 2002:a05:6214:449e:b0:6ab:6c18:57d0 with SMTP id 6a1803df08f44-6abcd0b203amr185600576d6.36.1716990464765; Wed, 29 May 2024 06:47:44 -0700 (PDT) Received: from jason-thinkpadp1gen4i.rmtusma.csb (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ad9f112d96sm7911066d6.24.2024.05.29.06.47.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 06:47:44 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: add module extensions Date: Wed, 29 May 2024 09:42:25 -0400 Message-ID: <20240529134742.610755-1-jason@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240522140029.3671772-1-jason@redhat.com> References: <20240522140029.3671772-1-jason@redhat.com> 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, SPF_HELO_NONE, SPF_NONE, 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.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 Revised to change mkdeps and the docs. Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- There is a trend in the broader C++ community to use a different extension for module interface units, even though (in GCC) they are compiled in the same way as other source files. Let's recognize these extensions as C++. .ixx is the MSVC standard, while the .c*m are supported by Clang. libc++ standard headers use .cppm, as their other source files use .cpp. Perhaps libstdc++ might use .ccm for parallel consistency? One issue with .c++m is that libcpp/mkdeps.cc has been using it for the phony dependencies to express module dependencies, so I'm changing mkdeps to something less likely to be an actual file, ".c++-module". gcc/cp/ChangeLog: * lang-specs.h: Add module interface extensions. gcc/ChangeLog: * doc/invoke.texi: Update module extension docs. libcpp/ChangeLog: * mkdeps.cc (make_write): Change .c++m to .c++-module. gcc/testsuite/ChangeLog: * g++.dg/modules/dep-1_a.C * g++.dg/modules/dep-1_b.C * g++.dg/modules/dep-2.C: Change .c++m to .c++-module. --- gcc/doc/invoke.texi | 20 ++++++++++---------- gcc/cp/lang-specs.h | 6 ++++++ gcc/testsuite/g++.dg/modules/dep-1_a.C | 4 ++-- gcc/testsuite/g++.dg/modules/dep-1_b.C | 8 ++++---- gcc/testsuite/g++.dg/modules/dep-2.C | 4 ++-- libcpp/mkdeps.cc | 13 ++++++------- 6 files changed, 30 insertions(+), 25 deletions(-) base-commit: 19c491d1848a8410559247183597096778967edf diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 2cba380718b..517a782987d 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -2317,9 +2317,12 @@ other language. C++ source files conventionally use one of the suffixes @samp{.C}, @samp{.cc}, @samp{.cpp}, @samp{.CPP}, @samp{.c++}, @samp{.cp}, or @samp{.cxx}; C++ header files often use @samp{.hh}, @samp{.hpp}, -@samp{.H}, or (for shared template code) @samp{.tcc}; and -preprocessed C++ files use the suffix @samp{.ii}. GCC recognizes -files with these names and compiles them as C++ programs even if you +@samp{.H}, or (for shared template code) @samp{.tcc}; +preprocessed C++ files use the suffix @samp{.ii}; and C++20 module interface +units sometimes use @samp{.ixx}, @samp{.cppm}, @samp{.cxxm}, @samp{.c++m}, +or @samp{.ccm}. + +GCC recognizes files with these names and compiles them as C++ programs even if you call the compiler the same way as for compiling C programs (usually with the name @command{gcc}). @@ -37705,13 +37708,10 @@ Modular compilation is @emph{not} enabled with just the version selected, although in pre-C++20 versions, it is of course an extension. -No new source file suffixes are required or supported. If you wish to -use a non-standard suffix (@pxref{Overall Options}), you also need -to provide a @option{-x c++} option too.@footnote{Some users like to -distinguish module interface files with a new suffix, such as naming -the source @code{module.cppm}, which involves -teaching all tools about the new suffix. A different scheme, such as -naming @code{module-m.cpp} would be less invasive.} +No new source file suffixes are required. A few suffixes preferred +for module interface units by other compilers (e.g. @samp{.ixx}, +@samp{.cppm}) are supported, but files with these suffixes are treated +the same as any other C++ source file. Compiling a module interface unit produces an additional output (to the assembly or object file), called a Compiled Module Interface diff --git a/gcc/cp/lang-specs.h b/gcc/cp/lang-specs.h index 7a7f5ff0ab5..e5651567a2d 100644 --- a/gcc/cp/lang-specs.h +++ b/gcc/cp/lang-specs.h @@ -39,6 +39,12 @@ along with GCC; see the file COPYING3. If not see {".HPP", "@c++-header", 0, 0, 0}, {".tcc", "@c++-header", 0, 0, 0}, {".hh", "@c++-header", 0, 0, 0}, + /* Module interface unit. Should there also be a .C counterpart? */ + {".ixx", "@c++", 0, 0, 0}, /* MSVC */ + {".cppm", "@c++", 0, 0, 0}, /* Clang/libc++ */ + {".cxxm", "@c++", 0, 0, 0}, + {".c++m", "@c++", 0, 0, 0}, + {".ccm", "@c++", 0, 0, 0}, {"@c++-header", "%{E|M|MM:cc1plus -E %{fmodules-ts:-fdirectives-only -fmodule-header}" " %(cpp_options) %2 %(cpp_debug_options)}" diff --git a/gcc/testsuite/g++.dg/modules/dep-1_a.C b/gcc/testsuite/g++.dg/modules/dep-1_a.C index 5ec5dd30f6d..3e92eeaef9f 100644 --- a/gcc/testsuite/g++.dg/modules/dep-1_a.C +++ b/gcc/testsuite/g++.dg/modules/dep-1_a.C @@ -4,6 +4,6 @@ export module m:part; // { dg-module-cmi m:part } // All The Backslashes! -// { dg-final { scan-file dep-1_a.d {\nm:part\.c\+\+m: gcm.cache/m-part\.gcm} } } +// { dg-final { scan-file dep-1_a.d {\nm:part\.c\+\+-module: gcm.cache/m-part\.gcm} } } // { dg-final { scan-file dep-1_a.d {\ngcm.cache/m-part\.gcm:| dep-1_a\.o} } } -// { dg-final { scan-file dep-1_a.d {\n\.PHONY: m:part\.c\+\+m} } } +// { dg-final { scan-file dep-1_a.d {\n\.PHONY: m:part\.c\+\+-module} } } diff --git a/gcc/testsuite/g++.dg/modules/dep-1_b.C b/gcc/testsuite/g++.dg/modules/dep-1_b.C index 7a0794eda51..265ebfcda64 100644 --- a/gcc/testsuite/g++.dg/modules/dep-1_b.C +++ b/gcc/testsuite/g++.dg/modules/dep-1_b.C @@ -3,8 +3,8 @@ export module m; // { dg-module-cmi m } export import :part; -// { dg-final { scan-file dep-1_b.d {\ndep-1_b\.s gcm.cache/m\.gcm: m:part\.c\+\+m} } } -// { dg-final { scan-file dep-1_b.d {\nm\.c\+\+m: gcm.cache/m\.gcm} } } -// { dg-final { scan-file dep-1_b.d {\n\.PHONY: m\.c\+\+m} } } +// { dg-final { scan-file dep-1_b.d {\ndep-1_b\.s gcm.cache/m\.gcm: m:part\.c\+\+-module} } } +// { dg-final { scan-file dep-1_b.d {\nm\.c\+\+-module: gcm.cache/m\.gcm} } } +// { dg-final { scan-file dep-1_b.d {\n\.PHONY: m\.c\+\+-module} } } // { dg-final { scan-file dep-1_b.d {\ngcm.cache/m\.gcm:| dep-1_b.o} } } -// { dg-final { scan-file dep-1_b.d {\nCXX_IMPORTS \+= m:part\.c\+\+m} } } +// { dg-final { scan-file dep-1_b.d {\nCXX_IMPORTS \+= m:part\.c\+\+-module} } } diff --git a/gcc/testsuite/g++.dg/modules/dep-2.C b/gcc/testsuite/g++.dg/modules/dep-2.C index 096243096e3..2dccab3554d 100644 --- a/gcc/testsuite/g++.dg/modules/dep-2.C +++ b/gcc/testsuite/g++.dg/modules/dep-2.C @@ -5,8 +5,8 @@ module m:part; // { dg-module-cmi !m:part } // All The Backslashes! -// { dg-final { scan-file dep-2.d {\nm:part\.c\+\+m: gcm.cache/m-part\.gcm} } } +// { dg-final { scan-file dep-2.d {\nm:part\.c\+\+-module: gcm.cache/m-part\.gcm} } } // { dg-final { scan-file dep-2.d {\ngcm.cache/m:part\.gcm:| dep-2\.o} } } -// { dg-final { scan-file dep-2.d {\n\.PHONY: m:part\.c\+\+m} } } +// { dg-final { scan-file dep-2.d {\n\.PHONY: m:part\.c\+\+-module} } } // { dg-final { scan-file dep-2.i {\nmodule m:part;\n} } } diff --git a/libcpp/mkdeps.cc b/libcpp/mkdeps.cc index 4cf0cf09178..622d0dc2ef8 100644 --- a/libcpp/mkdeps.cc +++ b/libcpp/mkdeps.cc @@ -411,8 +411,7 @@ make_write_vec (const mkdeps::vec &vec, FILE *fp, return col; } -/* Write the dependencies to a Makefile. If PHONY is true, add - .PHONY targets for all the dependencies too. */ +/* Write the dependencies to a Makefile. */ static void make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax) @@ -453,7 +452,7 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax) column = make_write_name (d->cmi_name, fp, column, colmax); fputs (":", fp); column++; - column = make_write_vec (d->modules, fp, column, colmax, 0, ".c++m"); + column = make_write_vec (d->modules, fp, column, colmax, 0, ".c++-module"); fputs ("\n", fp); } @@ -463,7 +462,7 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax) { /* module-name : cmi-name */ column = make_write_name (d->module_name, fp, 0, colmax, - true, ".c++m"); + true, ".c++-module"); fputs (":", fp); column++; column = make_write_name (d->cmi_name, fp, column, colmax); @@ -471,7 +470,7 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax) column = fprintf (fp, ".PHONY:"); column = make_write_name (d->module_name, fp, column, colmax, - true, ".c++m"); + true, ".c++-module"); fputs ("\n", fp); } @@ -488,11 +487,11 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax) fputs ("\n", fp); } } - + if (d->modules.size ()) { column = fprintf (fp, "CXX_IMPORTS +="); - make_write_vec (d->modules, fp, column, colmax, 0, ".c++m"); + make_write_vec (d->modules, fp, column, colmax, 0, ".c++-module"); fputs ("\n", fp); } }