clang-cl: Add support for the /o option for object files, executables, and preprocessor output
Summary:
cl.exe recognizes /o as a deprecated and undocumented option similar to
/Fe. This patch adds support for this option to clang-cl for /Fe, /Fo
and /Fi. It also ensures that the last option among /o and /F* wins,
if both specified.
This is required at least for building autoconf based software, since
autoconf uses -o to specify the executable output.
This fixes http://llvm.org/PR20894.
Test Plan: The patch includes automated tests.
Reviewers: rnk
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D5308
llvm-svn: 217615
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 8b159f0..04d4d44 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1180,6 +1180,15 @@
}
}
+ // Diagnose misuse of /o.
+ if (Arg *A = Args.getLastArg(options::OPT__SLASH_o)) {
+ if (A->getValue()[0] == '\0') {
+ // It has to have a value.
+ Diag(clang::diag::err_drv_missing_argument) << A->getSpelling() << 1;
+ Args.eraseArg(options::OPT__SLASH_o);
+ }
+ }
+
// Construct the actions to perform.
ActionList LinkerInputs;
@@ -1651,7 +1660,8 @@
assert(AtTopLevel && isa<PreprocessJobAction>(JA));
StringRef BaseName = llvm::sys::path::filename(BaseInput);
StringRef NameArg;
- if (Arg *A = C.getArgs().getLastArg(options::OPT__SLASH_Fi))
+ if (Arg *A = C.getArgs().getLastArg(options::OPT__SLASH_Fi,
+ options::OPT__SLASH_o))
NameArg = A->getValue();
return C.addResultFile(MakeCLOutputFilename(C.getArgs(), NameArg, BaseName,
types::TY_PP_C), &JA);
@@ -1698,15 +1708,17 @@
const char *NamedOutput;
if (JA.getType() == types::TY_Object &&
- C.getArgs().hasArg(options::OPT__SLASH_Fo)) {
- // The /Fo flag decides the object filename.
- StringRef Val = C.getArgs().getLastArg(options::OPT__SLASH_Fo)->getValue();
+ C.getArgs().hasArg(options::OPT__SLASH_Fo, options::OPT__SLASH_o)) {
+ // The /Fo or /o flag decides the object filename.
+ StringRef Val = C.getArgs().getLastArg(options::OPT__SLASH_Fo,
+ options::OPT__SLASH_o)->getValue();
NamedOutput = MakeCLOutputFilename(C.getArgs(), Val, BaseName,
types::TY_Object);
} else if (JA.getType() == types::TY_Image &&
- C.getArgs().hasArg(options::OPT__SLASH_Fe)) {
- // The /Fe flag names the linked file.
- StringRef Val = C.getArgs().getLastArg(options::OPT__SLASH_Fe)->getValue();
+ C.getArgs().hasArg(options::OPT__SLASH_Fe, options::OPT__SLASH_o)) {
+ // The /Fe or /o flag names the linked file.
+ StringRef Val = C.getArgs().getLastArg(options::OPT__SLASH_Fe,
+ options::OPT__SLASH_o)->getValue();
NamedOutput = MakeCLOutputFilename(C.getArgs(), Val, BaseName,
types::TY_Image);
} else if (JA.getType() == types::TY_Image) {