Skip to content

[clang][driver][clang-cl] Support --precompile and -fmodule-* options in Clang-CL #98761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 6, 2024

Conversation

sharadhr
Copy link
Contributor

@sharadhr sharadhr commented Jul 13, 2024

This PR is the first step in improving the situation for clang-cl detailed in this LLVM Discourse thread. There has been some work done in #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, and proper test cases need to be written. I'd like some thoughts on this, thanks!

Partially resolves #64118.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jul 13, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 13, 2024

@llvm/pr-subscribers-clang-modules
@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Sharadh Rajaraman (sharadhr)

Changes

This PR is the first step in improving the situation for clang-cl detailed in this LLVM Discourse thread. There has been some work done in #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, and proper test cases need to be written. Additionally, the /std:c++20 command-line argument is considered unused (although it is very much required, and compilation fails without it) with the following warning:

clang: warning: argument unused during compilation: '/std:c++20' [-Wunused-command-line-argument]

I suspect the issue is somewhere around

// FIXME: Clang doesn't correctly handle -std= when the input language
// doesn't match. For the time being just ignore this for C++ inputs;
// eventually we want to do all the standard defaulting here instead of
// splitting it between the driver and clang -cc1.
if (!types::isCXX(InputType)) {
if (!Args.hasArg(options::OPT__SLASH_std)) {
Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ, "-std=",
/*Joined=*/true);
} else
ImplyVCPPCVer = true;
}
else if (IsWindowsMSVC)
ImplyVCPPCXXVer = true;
Args.AddLastArg(CmdArgs, options::OPT_ftrigraphs,
options::OPT_fno_trigraphs);

I'd like some thoughts on this, thanks!


Full diff: https://github.com/llvm/llvm-project/pull/98761.diff

1 Files Affected:

  • (modified) clang/include/clang/Driver/Options.td (+2-1)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 4ab8638175dd3..ca7cfef8453a0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3085,7 +3085,7 @@ def fmodules_user_build_path : Separate<["-"], "fmodules-user-build-path">, Grou
   HelpText<"Specify the module user build path">,
   MarshallingInfoString<HeaderSearchOpts<"ModuleUserBuildPath">>;
 def fprebuilt_module_path : Joined<["-"], "fprebuilt-module-path=">, Group<i_Group>,
-  Flags<[]>, Visibility<[ClangOption, CC1Option]>,
+  Flags<[]>, Visibility<[ClangOption, CLOption, CC1Option]>,
   MetaVarName<"<directory>">,
   HelpText<"Specify the prebuilt module path">;
 defm prebuilt_implicit_modules : BoolFOption<"prebuilt-implicit-modules",
@@ -5874,6 +5874,7 @@ def _output : Separate<["--"], "output">, Alias<o>;
 def _param : Separate<["--"], "param">, Group<CompileOnly_Group>;
 def _param_EQ : Joined<["--"], "param=">, Alias<_param>;
 def _precompile : Flag<["--"], "precompile">, Flags<[NoXarchOption]>,
+  Visibility<[ClangOption, CLOption]>,
   Group<Action_Group>, HelpText<"Only precompile the input">;
 def _prefix_EQ : Joined<["--"], "prefix=">, Alias<B>;
 def _prefix : Separate<["--"], "prefix">, Alias<B>;

@llvmbot llvmbot added the clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' label Jul 14, 2024
@sharadhr sharadhr changed the title [clang][driver] Improve Clang-CL support for C++20 standard modules [clang][driver] Support --precompile and -fmodule-* options in Clang-CL Jul 14, 2024
Copy link
Member

@ChuanqiXu9 ChuanqiXu9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Can you add a test for this under (clang/test/Driver) and add new subsection for it in StandardCPlusPlusModules.rst ?

@ChuanqiXu9 ChuanqiXu9 added the clang:modules C++20 modules and Clang Header Modules label Jul 16, 2024
Copy link

github-actions bot commented Jul 16, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@sharadhr sharadhr changed the title [clang][driver] Support --precompile and -fmodule-* options in Clang-CL [clang][driver][clang-cl] Support --precompile and -fmodule-* options in Clang-CL Jul 17, 2024
@sharadhr
Copy link
Contributor Author

sharadhr commented Aug 5, 2024

@ChuanqiXu9, do make a re-review when you can, thanks!

Copy link
Member

@ChuanqiXu9 ChuanqiXu9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'll merge this after the CI finished.

@ChuanqiXu9
Copy link
Member

It looks like the CI failure is not related.

@ChuanqiXu9
Copy link
Member

@sharadhr it looks like the commit author is not correct. By default it is 3754080+sharadhr@users.noreply.github.com, but we don't like such fake mail account. Please update it with your real mail.

@sharadhr
Copy link
Contributor Author

sharadhr commented Aug 6, 2024

I've done a git rebase with --reset-author. Hopefully this is correct.

@ChuanqiXu9 ChuanqiXu9 merged commit bd576fe into llvm:main Aug 6, 2024
4 of 6 checks passed
Copy link

github-actions bot commented Aug 6, 2024

@sharadhr Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested
by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself.
This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@ChuanqiXu9
Copy link
Member

I think this worth to be in 19.x and I don't it is a risk.

@ChuanqiXu9 ChuanqiXu9 added this to the LLVM 19.X Release milestone Aug 6, 2024
@ChuanqiXu9
Copy link
Member

/cherry-pick bd576fe

llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Aug 6, 2024
…ions 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)
@llvmbot
Copy link
Member

llvmbot commented Aug 6, 2024

/pull-request #102159

ChuanqiXu9 pushed a commit that referenced this pull request Aug 8, 2024
…` for precompiled module inputs to `clang-cl` (#99300)

Relates to #98761: `-fmodule-file` requires `/std:c++20` or greater, but
passing that option results in an unused argument warning. This resolves
that.
tru pushed a commit to llvmbot/llvm-project that referenced this pull request Aug 10, 2024
…ions 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)
huangqinjin added a commit to huangqinjin/cxxmodules that referenced this pull request Nov 10, 2024
1. __cpp_lib_modules now is defined.
llvm/llvm-project#90091

2. clang-cl supports -x option for all languages.
llvm/llvm-project#89772

3. Header units allow non-inline external static members definitions.
llvm/llvm-project#98309

4. winsysroot alias to the GNU driver: -Xmicrosoft-windows-sys-root.
llvm/llvm-project#94731

5. clang-cl gained options for compiling C++ modules.
llvm/llvm-project#98761

6. fix unused argument warning for /std:c++20 when compiling c++ modules.
llvm/llvm-project#99300
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category
Projects
Development

Successfully merging this pull request may close these issues.

[C++20] [Modules] clang-cl.exe doesn't work with C++20 modules with the HelloWorld example
3 participants