Skip to content

Commit b2de372

Browse files
sharadhrtru
authored andcommitted
[clang][driver][clang-cl] Support --precompile and -fmodule-* options in Clang-CL (llvm#98761)
This PR is the first step in improving the situation for `clang-cl` detailed in [this LLVM Discourse thread](https://discourse.llvm.org/t/clang-cl-exe-support-for-c-modules/72257/28). There has been some work done in llvm#89772. I believe this is somewhat orthogonal. This is a work-in-progress; the functionality has only been tested with the [basic 'Hello World' example](https://clang.llvm.org/docs/StandardCPlusPlusModules.html#quick-start), and proper test cases need to be written. I'd like some thoughts on this, thanks! Partially resolves llvm#64118. (cherry picked from commit bd576fe)
1 parent 5972d4d commit b2de372

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

clang/docs/StandardCPlusPlusModules.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,16 @@ BMIs cannot be shipped in an archive to create a module library. Instead, the
398398
BMIs(``*.pcm``) are compiled into object files(``*.o``) and those object files
399399
are added to the archive instead.
400400

401+
clang-cl
402+
~~~~~~~~
403+
404+
``clang-cl`` supports the same options as ``clang++`` for modules as detailed above;
405+
there is no need to prefix these options with ``/clang:``. Note that ``cl.exe``
406+
`options to emit/consume IFC files <https://devblogs.microsoft.com/cppblog/using-cpp-modules-in-msvc-from-the-command-line-part-1/>` are *not* supported.
407+
The resultant precompiled modules are also not compatible for use with ``cl.exe``.
408+
409+
We recommend that build system authors use the above-mentioned ``clang++`` options with ``clang-cl`` to build modules.
410+
401411
Consistency Requirements
402412
~~~~~~~~~~~~~~~~~~~~~~~~
403413

@@ -1387,13 +1397,6 @@ have ``.cppm`` (or ``.ccm``, ``.cxxm``, ``.c++m``) as the file extension.
13871397
However, the behavior is inconsistent with other compilers. This is tracked by
13881398
`#57416 <https://github.com/llvm/llvm-project/issues/57416>`_.
13891399

1390-
clang-cl is not compatible with standard C++ modules
1391-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1392-
1393-
``/clang:-fmodule-file`` and ``/clang:-fprebuilt-module-path`` cannot be used
1394-
to specify the BMI with ``clang-cl.exe``. This is tracked by
1395-
`#64118 <https://github.com/llvm/llvm-project/issues/64118>`_.
1396-
13971400
Incorrect ODR violation diagnostics
13981401
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13991402

clang/docs/UsersManual.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4745,6 +4745,12 @@ Execute ``clang-cl /?`` to see a list of supported options:
47454745
-flto=<value> Set LTO mode to either 'full' or 'thin'
47464746
-flto Enable LTO in 'full' mode
47474747
-fmerge-all-constants Allow merging of constants
4748+
-fmodule-file=<module_name>=<module-file>
4749+
Use the specified module file that provides the module <module_name>
4750+
-fmodule-header=<header>
4751+
Build <header> as a C++20 header unit
4752+
-fmodule-output=<path>
4753+
Save intermediate module file results when compiling a standard C++ module unit.
47484754
-fms-compatibility-version=<value>
47494755
Dot-separated value representing the Microsoft compiler version
47504756
number to report in _MSC_VER (0 = don't define it; default is same value as installed cl.exe, or 1933)

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3107,7 +3107,7 @@ def fmodules_user_build_path : Separate<["-"], "fmodules-user-build-path">, Grou
31073107
HelpText<"Specify the module user build path">,
31083108
MarshallingInfoString<HeaderSearchOpts<"ModuleUserBuildPath">>;
31093109
def fprebuilt_module_path : Joined<["-"], "fprebuilt-module-path=">, Group<i_Group>,
3110-
Flags<[]>, Visibility<[ClangOption, CC1Option]>,
3110+
Flags<[]>, Visibility<[ClangOption, CLOption, CC1Option]>,
31113111
MetaVarName<"<directory>">,
31123112
HelpText<"Specify the prebuilt module path">;
31133113
defm prebuilt_implicit_modules : BoolFOption<"prebuilt-implicit-modules",
@@ -3116,11 +3116,11 @@ defm prebuilt_implicit_modules : BoolFOption<"prebuilt-implicit-modules",
31163116
NegFlag<SetFalse>, BothFlags<[], [ClangOption, CC1Option]>>;
31173117

31183118
def fmodule_output_EQ : Joined<["-"], "fmodule-output=">,
3119-
Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option]>,
3119+
Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, CC1Option]>,
31203120
MarshallingInfoString<FrontendOpts<"ModuleOutputPath">>,
31213121
HelpText<"Save intermediate module file results when compiling a standard C++ module unit.">;
31223122
def fmodule_output : Flag<["-"], "fmodule-output">, Flags<[NoXarchOption]>,
3123-
Visibility<[ClangOption, CC1Option]>,
3123+
Visibility<[ClangOption, CLOption, CC1Option]>,
31243124
HelpText<"Save intermediate module file results when compiling a standard C++ module unit.">;
31253125

31263126
defm skip_odr_check_in_gmf : BoolOption<"f", "skip-odr-check-in-gmf",
@@ -3300,8 +3300,10 @@ def fretain_comments_from_system_headers : Flag<["-"], "fretain-comments-from-sy
33003300
Visibility<[ClangOption, CC1Option]>,
33013301
MarshallingInfoFlag<LangOpts<"RetainCommentsFromSystemHeaders">>;
33023302
def fmodule_header : Flag <["-"], "fmodule-header">, Group<f_Group>,
3303+
Visibility<[ClangOption, CLOption]>,
33033304
HelpText<"Build a C++20 Header Unit from a header">;
33043305
def fmodule_header_EQ : Joined<["-"], "fmodule-header=">, Group<f_Group>,
3306+
Visibility<[ClangOption, CLOption]>,
33053307
MetaVarName<"<kind>">,
33063308
HelpText<"Build a C++20 Header Unit from a header that should be found in the user (fmodule-header=user) or system (fmodule-header=system) search path.">;
33073309

@@ -5946,6 +5948,7 @@ def _output : Separate<["--"], "output">, Alias<o>;
59465948
def _param : Separate<["--"], "param">, Group<CompileOnly_Group>;
59475949
def _param_EQ : Joined<["--"], "param=">, Alias<_param>;
59485950
def _precompile : Flag<["--"], "precompile">, Flags<[NoXarchOption]>,
5951+
Visibility<[ClangOption, CLOption]>,
59495952
Group<Action_Group>, HelpText<"Only precompile the input">;
59505953
def _prefix_EQ : Joined<["--"], "prefix=">, Alias<B>;
59515954
def _prefix : Separate<["--"], "prefix">, Alias<B>;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %clang_cl /std:c++20 --precompile -### -- %s 2>&1 | FileCheck --check-prefix=PRECOMPILE %s
2+
// PRECOMPILE: -emit-module-interface
3+
4+
// RUN: %clang_cl /std:c++20 --fmodule-file=Foo=Foo.pcm -### -- %s 2>&1 | FileCheck --check-prefix=FMODULEFILE %s
5+
// FMODULEFILE: -fmodule-file=Foo=Foo.pcm
6+
7+
// RUN: %clang_cl /std:c++20 --fprebuilt-module-path=. -### -- %s 2>&1 | FileCheck --check-prefix=FPREBUILT %s
8+
// FPREBUILT: -fprebuilt-module-path=.

0 commit comments

Comments
 (0)