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

Greg Bedwell greg_bedwell at sn.scee.net
Mon Jun 8 07:06:21 PDT 2015

Hi hans, ehsan, mcrosier,

[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.




Index: lib/Driver/Driver.cpp
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -1697,8 +1697,7 @@
     assert(AtTopLevel && isa<PreprocessJobAction>(JA));
     StringRef BaseName = llvm::sys::path::filename(BaseInput);
     StringRef NameArg;
-    if (Arg *A = C.getArgs().getLastArg(options::OPT__SLASH_Fi,
-                                        options::OPT__SLASH_o))
+    if (Arg *A = C.getArgs().getLastArg(options::OPT__SLASH_Fi))
       NameArg = A->getValue();
     return C.addResultFile(MakeCLOutputFilename(C.getArgs(), NameArg, BaseName,
                                                 types::TY_PP_C), &JA);
Index: test/Driver/cl-outputs.c
--- test/Driver/cl-outputs.c
+++ test/Driver/cl-outputs.c
@@ -251,28 +251,28 @@
 // RUN: %clang_cl /P /ofoo -### -- %s 2>&1 | FileCheck -check-prefix=Fio1 %s
 // Fio1: "-E"
-// Fio1: "-o" "foo.i"
+// Fio1: "-o" "cl-outputs.i"
 // RUN: %clang_cl /P /o foo -### -- %s 2>&1 | FileCheck -check-prefix=Fio2 %s
 // Fio2: "-E"
-// Fio2: "-o" "foo.i"
+// Fio2: "-o" "cl-outputs.i"
 // RUN: %clang_cl /P /ofoo.x -### -- %s 2>&1 | FileCheck -check-prefix=Fio3 %s
 // Fio3: "-E"
-// Fio3: "-o" "foo.x"
+// Fio3: "-o" "cl-outputs.i"
 // RUN: %clang_cl /P /o foo.x -### -- %s 2>&1 | FileCheck -check-prefix=Fio4 %s
 // Fio4: "-E"
-// Fio4: "-o" "foo.x"
+// Fio4: "-o" "cl-outputs.i"
 // RUN: %clang_cl /P /obar.x /Fifoo.x -### -- %s 2>&1 | FileCheck -check-prefix=FioRACE1 %s
 // FioRACE1: "-E"
 // FioRACE1: "-o" "foo.x"
 // RUN: %clang_cl /P /Fifoo.x /obar.x -### -- %s 2>&1 | FileCheck -check-prefix=FioRACE2 %s
 // FioRACE2: "-E"
-// FioRACE2: "-o" "bar.x"
+// FioRACE2: "-o" "foo.x"
 // RUN: %clang_cl /c /GL -### -- %s 2>&1 | FileCheck -check-prefix=LTO-DEFAULT %s
 // LTO-DEFAULT: "-emit-llvm-bc"{{.*}}"-o" "cl-outputs.obj"

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10313.27306.patch
Type: text/x-patch
Size: 1931 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150608/91a7f861/attachment.bin>

More information about the cfe-commits mailing list