This is an archive of the discontinued LLVM Phabricator instance.

[clang-cl] Ignore the /o option when /P is specified.
ClosedPublic

Authored by gbedwell on Jun 8 2015, 7:06 AM.

Details

Summary
[clang-cl] Ignore the /o option when /P is specified.

This matches the cl.exe behavior (tested with 18.00.31101).  In order to
specify an output file for /P, use the /Fi option instead.

I ran into this when my change to add Windows version information to LLVM executables caused a failure on the clang selfhost builds. This is because the CMake tool cmcldeps.exe which it's using to figure out dependencies for the resource script file is invoking the host C++ compiler with '/P /out:<location>' but expecting <location> to be ignored. With MSVC's cl.exe (I tested VS2012 and VS2013) this is the case, but with clang-cl.exe we're trying to output the file to <location>. This patch changes clang-cl to match the cl behaviour in ignoring /o which allows cmcldeps.exe tool to function correctly with clang-cl. The test ensures that the '/Fi' option still works as expected to allow the location of the /P output to be specified if required.

Note that I mentioned that cmcldeps.exe is specifying the location with '/out:<location>', rather than '/o' '<location>'. This means that in this case it's actually being parsed as '/o' 'ut:<location>' but as it's being ignored anyway it doesn't cause us any problems. I'm not sure whether we'd also want to add '/out:' as an alias for '/o' too. As both '/o' and '/out:' now give a warning from cl.exe:

"Command line warning D9035 : option 'o' has been deprecated and will be removed in a future release"

I'm inclined to think that we shouldn't add '/out:' support as I'm not aware of any particular use-cases where it's required but I can do that too in a separate patch if the consensus is that we should.

Thanks,
-Greg

Diff Detail

Repository
rL LLVM

Event Timeline

gbedwell updated this revision to Diff 27306.Jun 8 2015, 7:06 AM
gbedwell retitled this revision from to [clang-cl] Ignore the /o option when /P is specified..
gbedwell updated this object.
gbedwell edited the test plan for this revision. (Show Details)
gbedwell added reviewers: hans, ehsan, mcrosier.
gbedwell added a subscriber: Unknown Object (MLST).
gbedwell added a reviewer: rnk.Jun 8 2015, 7:12 AM

Actually, looking at it more I'm not even sure that MSVC supports the '/out:' form except for in the linker. I think cl.exe may also be interpreting the command line from CMake's cmcldeps as '/o' 'ut:<location>'. Either way, it is ignored so the behaviour after this patch is correct.

ehsan edited edge metadata.Jun 8 2015, 7:29 AM

http://llvm.org/PR20894 is a good read here.

I'm fine with this change myself, but I would be interested to know what
Hans thinks.

hans accepted this revision.Jun 8 2015, 8:29 AM
hans edited edge metadata.

LGTM with comment.

test/Driver/cl-outputs.c
266 ↗(On Diff #27306)

We probably don't need all four test cases for /P with /o anymore.

I think we should also have a note explaining the expected behaviour: that /o doesn't affect /P.

This revision is now accepted and ready to land.Jun 8 2015, 8:29 AM
This revision was automatically updated to reflect the committed changes.