-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[clang-cl] Accept cl
-style output arguments (/Fo
, -Fo
) for --precompile
#121046
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
base: main
Are you sure you want to change the base?
Conversation
d8108f0
to
350a517
Compare
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: Sharadh Rajaraman (sharadhr) ChangesFull diff: https://github.com/llvm/llvm-project/pull/121046.diff 1 Files Affected:
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ecae475f75da00..b47e0443d6e9db 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -5442,7 +5442,7 @@ InputInfoList Driver::BuildJobsForAction(
InputInfoList Result = BuildJobsForActionNoCache(
C, A, TC, BoundArch, AtTopLevel, MultipleArchs, LinkingOutput,
CachedResults, TargetDeviceOffloadKind);
- CachedResults[ActionTC] = Result;
+ CachedResults[ActionTC] = Result;
return Result;
}
@@ -5890,7 +5890,7 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
llvm::PrettyStackTraceString CrashInfo("Computing output path");
// Output to a user requested destination?
if (AtTopLevel && !isa<DsymutilJobAction>(JA) && !isa<VerifyJobAction>(JA)) {
- if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
+ if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o, options::OPT__SLASH_Fo, options::OPT__SLASH_Fo_COLON))
return C.addResultFile(FinalOutput->getValue(), &JA);
}
|
350a517
to
e1708db
Compare
The tests are failing and it looks relevent. |
Why is this submitted against the release/19.x branch? Is this a backport? If so, please indicate which commit it backports. |
e1708db
to
bc9b68d
Compare
Not a backport but a new commit. I have now re-submitted it against |
It is better to fix the test failures (or announce they are not relevant with your pr) |
7487d82
to
ff22639
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
a839072
to
1f40c12
Compare
I'm not sure how to fix the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zmodem given how important this it, I hope we can make this for clang21. Thanks!
91cf98b
to
8653855
Compare
8653855
to
d2e56db
Compare
I'm just a reviewer here, and I still find the patch very confusing. And taking a step back, the whole point of clang-cl is to provide a cl.exe compatible interface to clang. I presume cl.exe does not use |
That was discussed on Discourse. If/when |
Sorry, I don't remember seeing that discussion, and I'm probably missing lots of modules context. As a counter argument, clang-cl uses More importantly, it feels like we're being very unintentional about the interface design here. Why should clang-cl's If the idea is to punt on the design, maybe the solution is just to use regular clang flags for this? |
Not asking for an approval. It is just a ping : )
|
although I don't use MSVC. I think '/Fo' is basically '-o'. Its semantic is to specify the path to the output file. And with '--precompile' the output file is BMI. And with '-c', the output is obj files. And with '-emit-llvm', the output is llvm ir. So I feel it is fine. But of course, all of these are my thoughts and imagination. I am never a clang-cl user ever. So if now clang-cl can accept '-o', I don't mind to use that if @mathstuf agrees on this. Since most end users won't write this in my mind. The build system are the major users here. |
No,
It works in general in clang-cl. I guess we'd have to double check if it works in the modules use case. And |
Is
See this thread: https://discourse.llvm.org/t/clang-cl-exe-support-for-c-modules/72257 |
But if we want to generate BMI only instead of obj files, we should use |
Good point. I think trying to hack
As mentioned above, the Clang C++ Standard Modules document suggests using
But CMake seems to prefer the latter. Additionally, in the CMake MR, it was determined that |
From @zmodem's comment above, MSVC documentation, and Clang-cl documentation, I believe it is now incorrect to use It might be better to use |
I believe the issue can be distilled further. On the
This command does not:
This command also does not:
And the only lines where the driver behaviour appears to diverge, is the // Output to a user requested destination?
if (AtTopLevel && !isa<DsymutilJobAction>(JA) && !isa<VerifyJobAction>(JA)) {
...
} |
@mathstuf in #140825 (comment) , xmake dev said he can fix the problem by |
We tried this, but it didn't work when generating multiple output files. In particular, a
|
well i'm still experimenting, |
FYI, branching for LLVM v21 is less than two weeks away |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the problem is important (I've heard the problem for clang-cl with modules several times) and the author have been active on this direction for years, I think I can trust him even if I can't test it actually. So LGTM.
I'll land this one week later if no objection or new comments come in, @sharadhr remind me that time if I forget it somehow.
@@ -14,3 +14,11 @@ | ||
|
||
//--- test.pcm | ||
// CPP20WARNING-NOT: clang-cl: warning: argument unused during compilation: '/std:c++20' [-Wunused-command-line-argument] | ||
|
||
// test whether the following outputs %Hello.bmi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// test whether the following outputs %Hello.bmi | |
// test whether the following outputs %t/Hello.bmi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll land this one week later if no objection or new comments come in
I object.
Even the author seems to object:
I believe it is now incorrect to use /Fo for the BMI output
The change to Driver::GetNamedOutputPath
has not been explained yet, beyond "it seems to make the tests pass".
And the whole approach of making clang-cl's /Fo
("set object file name") do something different from MSVC's seems very questionable.
I think this patch needs to go back to the drawing board.
I agree. My understanding is that @Arthapz made |
I don't really care how things are spelled as long as they're possible. Don't take what CMake does for |
If this is consensus, then I will rework this PR from scratch to expose |
This PR resolves this issue, which can be summarised as such. Given the following
foo.cxx
:Running the following outputs
foo.pcm
, but doesn’t outputfoo.bmi
as requested by-Fo
:However, running the following outputs
foo.bmi
as requested:This behaviour is then used by
clang-scan-deps
to output the dependency scanning JSON. In the former case since no.bmi
is output, the corresponding value of theprimary-output
key here is"-"
.This invocation is used by CMake to run
clang-scan-deps
and build the dependency tree.