Skip to content
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

[clang][driver] Support -x for all languages in CL mode #89772

Merged
merged 1 commit into from
May 24, 2024

Conversation

huangqinjin
Copy link
Contributor

@huangqinjin huangqinjin commented Apr 23, 2024

After #68921, clang-cl gained option -x but only for CUDA/HIP. This commit simply removes the restriction on parameters to -x. Especially, it is able to use -x c++-module and -x c++-system-header to build C++20 modules and header units with clang-cl.

This effectively reverts commit fe08212.

Closes #88006.

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 clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Apr 23, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 23, 2024

@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: None (huangqinjin)

Changes

After #68921, clang-cl gained option -x but only for CUDA/HIP. This commit simply removes the restriction on parameters to -x. Especially, it is able to use -x c++-module and -x c++-user-header to build C++20 modules and header units with clang-cl.

This effectively reverts commit fe08212.

Closes #88006.


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

2 Files Affected:

  • (modified) clang/lib/Driver/Driver.cpp (+1-10)
  • (modified) clang/test/Driver/x-args.c (-4)
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e7335a61b10c53..0f425adfd32a6d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2636,22 +2636,13 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
       Diag(clang::diag::note_drv_t_option_is_global);
   }
 
-  // CUDA/HIP and their preprocessor expansions can be accepted by CL mode.
   // Warn -x after last input file has no effect
-  auto LastXArg = Args.getLastArgValue(options::OPT_x);
-  const llvm::StringSet<> ValidXArgs = {"cuda", "hip", "cui", "hipi"};
-  if (!IsCLMode() || ValidXArgs.contains(LastXArg)) {
+  {
     Arg *LastXArg = Args.getLastArgNoClaim(options::OPT_x);
     Arg *LastInputArg = Args.getLastArgNoClaim(options::OPT_INPUT);
     if (LastXArg && LastInputArg &&
         LastInputArg->getIndex() < LastXArg->getIndex())
       Diag(clang::diag::warn_drv_unused_x) << LastXArg->getValue();
-  } else {
-    // In CL mode suggest /TC or /TP since -x doesn't make sense if passed via
-    // /clang:.
-    if (auto *A = Args.getLastArg(options::OPT_x))
-      Diag(diag::err_drv_unsupported_opt_with_suggestion)
-          << A->getAsString(Args) << "/TC' or '/TP";
   }
 
   for (Arg *A : Args) {
diff --git a/clang/test/Driver/x-args.c b/clang/test/Driver/x-args.c
index 17bb5d99404dae..b49f474babf0fa 100644
--- a/clang/test/Driver/x-args.c
+++ b/clang/test/Driver/x-args.c
@@ -5,7 +5,3 @@
 // RUN: %clang -fsyntax-only -xc %s -xc++ -fsyntax-only 2>&1 | FileCheck %s
 // RUN: %clang -fsyntax-only %s -xc %s -xc++ -fsyntax-only 2>&1 | FileCheck %s
 // CHECK: '-x c++' after last input file has no effect
-
-// RUN: not %clang_cl /WX /clang:-xc /clang:-E /clang:-dM -- %s 2>&1 | FileCheck --implicit-check-not="error:" -check-prefix=CL %s
-// RUN: not %clang_cl /TC /WX /clang:-xc /clang:-E /clang:-dM -- %s 2>&1 | FileCheck --implicit-check-not="error:" -check-prefix=CL %s
-// CL: error: unsupported option '-x c'; did you mean '/TC' or '/TP'?

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.

It may be better to add a test with -x c++-module within CL mode.

clang/test/Driver/x-args.c Show resolved Hide resolved
@huangqinjin
Copy link
Contributor Author

gentle ping. The ci failure looks not relevant.

@MaxEW707
Copy link
Contributor

MaxEW707 commented May 22, 2024

@huangqinjin The error is "fatal error C1060: compiler is out of heap space" which is unrelated. Just ran of out memory on the machine.

I haven't figured out how to resend the event to trigger a build retry without pushing an empty commit.
I usually just do git commit -m "rebuild" --allow-empty and then push that up to trigger a build retry.

Give that a shot to get CI green :).

@huangqinjin
Copy link
Contributor Author

CI still fails. No idea how to proceed.

@MaxEW707
Copy link
Contributor

@huangqinjin Try rebasing you changes on top of latest main. Looks like Windows CI is passing there including flang commits which are the source files that are causing msvc to run out of heap space.

After llvm#68921,
clang-cl gained option `-x` but only for CUDA/HIP.
This commit simply removes the restriction on parameters to `-x`.
Especially, it is able to use `-x c++-module` and `-x c++-system-header`
to build C++20 modules and header units with clang-cl.

This effectively reverts commit fe08212.

Closes llvm#88006.
@huangqinjin
Copy link
Contributor Author

@huangqinjin Try rebasing you changes on top of latest main. Looks like Windows CI is passing there including flang commits which are the source files that are causing msvc to run out of heap space.

Thanks for the advice. CI green now.

@ChuanqiXu9
Copy link
Member

I think we can land this given it is approved and the CI is green

@MaskRay MaskRay merged commit 06b5a7c into llvm:main May 24, 2024
8 checks passed
Copy link

@huangqinjin 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!

@huangqinjin huangqinjin deleted the clang-cl-x branch May 24, 2024 05:44
ChuanqiXu9 pushed a commit that referenced this pull request Aug 6, 2024
…ions in Clang-CL (#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 #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 #64118.
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)
banach-space pushed a commit to banach-space/llvm-project that referenced this pull request Aug 7, 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.
190n added a commit to oven-sh/bun that referenced this pull request Aug 9, 2024
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)
kstoimenov pushed a commit to kstoimenov/llvm-project that referenced this pull request Aug 15, 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.
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 Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support -x for clang-cl
5 participants