Index: cfe/trunk/include/clang/Driver/CLCompatOptions.td =================================================================== --- cfe/trunk/include/clang/Driver/CLCompatOptions.td +++ cfe/trunk/include/clang/Driver/CLCompatOptions.td @@ -182,6 +182,9 @@ Flags<[CLOption, DriverOption]>, HelpText<"Use static run-time">; def _SLASH_MTd : Option<["/", "-"], "MTd", KIND_FLAG>, Group<_SLASH_M_Group>, Flags<[CLOption, DriverOption]>, HelpText<"Use static debug run-time">; +def _SLASH_o : CLJoinedOrSeparate<"o">, + HelpText<"Set output file or directory (ends in / or \\)">, + MetaVarName<"">; def _SLASH_P : CLFlag<"P">, HelpText<"Preprocess to file">; def _SLASH_Tc : CLCompileJoinedOrSeparate<"Tc">, HelpText<"Specify a C source file">, MetaVarName<"">; @@ -256,7 +259,6 @@ def _SLASH_kernel : CLFlag<"kernel">; def _SLASH_LN : CLFlag<"LN">; def _SLASH_MP : CLJoined<"MP">; -def _SLASH_o : CLJoinedOrSeparate<"o">; def _SLASH_openmp : CLFlag<"openmp">; def _SLASH_Qfast_transcendentals : CLFlag<"Qfast_transcendentals">; def _SLASH_QIfist : CLFlag<"QIfist">; Index: cfe/trunk/lib/Driver/Driver.cpp =================================================================== --- cfe/trunk/lib/Driver/Driver.cpp +++ cfe/trunk/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(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) { Index: cfe/trunk/test/Driver/cl-outputs.c =================================================================== --- cfe/trunk/test/Driver/cl-outputs.c +++ cfe/trunk/test/Driver/cl-outputs.c @@ -35,6 +35,59 @@ // CHECK-MULTIPLESOURCEOK: "-o" "mydir{{[/\\]+}}cl-outputs.obj" +// RUN: %clang_cl /c /oa -### -- %s 2>&1 | FileCheck -check-prefix=FooNAME1 %s +// FooNAME1: "-o" "a.obj" + +// RUN: %clang_cl /c /o a -### -- %s 2>&1 | FileCheck -check-prefix=FooNAME2 %s +// FooNAME2: "-o" "a.obj" + +// RUN: %clang_cl /c /oa.ext /ob.ext -### -- %s 2>&1 | FileCheck -check-prefix=FooNAMEEXT1 %s +// FooNAMEEXT1: "-o" "b.ext" + +// RUN: %clang_cl /c /o a.ext /ob.ext -### -- %s 2>&1 | FileCheck -check-prefix=FooNAMEEXT2 %s +// FooNAMEEXT2: "-o" "b.ext" + +// RUN: %clang_cl /c /ofoo.dir/ -### -- %s 2>&1 | FileCheck -check-prefix=FooDIR1 %s +// FooDIR1: "-o" "foo.dir{{[/\\]+}}cl-outputs.obj" + +// RUN: %clang_cl /c /o foo.dir/ -### -- %s 2>&1 | FileCheck -check-prefix=FooDIR2 %s +// FooDIR2: "-o" "foo.dir{{[/\\]+}}cl-outputs.obj" + +// RUN: %clang_cl /c /ofoo.dir/a -### -- %s 2>&1 | FileCheck -check-prefix=FooDIRNAME1 %s +// FooDIRNAME1: "-o" "foo.dir{{[/\\]+}}a.obj" + +// RUN: %clang_cl /c /o foo.dir/a -### -- %s 2>&1 | FileCheck -check-prefix=FooDIRNAME2 %s +// FooDIRNAME2: "-o" "foo.dir{{[/\\]+}}a.obj" + +// RUN: %clang_cl /c /ofoo.dir/a.ext -### -- %s 2>&1 | FileCheck -check-prefix=FooDIRNAMEEXT1 %s +// FooDIRNAMEEXT1: "-o" "foo.dir{{[/\\]+}}a.ext" + +// RUN: %clang_cl /c /o foo.dir/a.ext -### -- %s 2>&1 | FileCheck -check-prefix=FooDIRNAMEEXT2 %s +// FooDIRNAMEEXT2: "-o" "foo.dir{{[/\\]+}}a.ext" + +// RUN: %clang_cl /c /o.. -### -- %s 2>&1 | FileCheck -check-prefix=FooCRAZY1 %s +// FooCRAZY1: "-o" "..obj" + +// RUN: %clang_cl /c /o .. -### -- %s 2>&1 | FileCheck -check-prefix=FooCRAZY2 %s +// FooCRAZY2: "-o" "..obj" + +// RUN: %clang_cl /c %s -### /o 2>&1 | FileCheck -check-prefix=FooMISSINGARG %s +// FooMISSINGARG: error: argument to '/o' is missing (expected 1 value) + +// RUN: %clang_cl /c /omydir/ -### -- %s %s 2>&1 | FileCheck -check-prefix=CHECK-oMULTIPLESOURCEOK1 %s +// CHECK-oMULTIPLESOURCEOK1: "-o" "mydir{{[/\\]+}}cl-outputs.obj" + +// RUN: %clang_cl /c /o mydir/ -### -- %s %s 2>&1 | FileCheck -check-prefix=CHECK-oMULTIPLESOURCEOK2 %s +// CHECK-oMULTIPLESOURCEOK2: "-o" "mydir{{[/\\]+}}cl-outputs.obj" + + +// RUN: %clang_cl /c /obar /Fofoo -### -- %s 2>&1 | FileCheck -check-prefix=FooRACE1 %s +// FooRACE1: "-o" "foo.obj" + +// RUN: %clang_cl /c /Fofoo /obar -### -- %s 2>&1 | FileCheck -check-prefix=FooRACE2 %s +// FooRACE2: "-o" "bar.obj" + + // RUN: %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=DEFAULTEXE %s // DEFAULTEXE: cl-outputs.exe @@ -90,6 +143,75 @@ // FeOVERRIDE: "-out:bar.exe" +// RUN: %clang_cl /obar /Fefoo -### -- %s 2>&1 | FileCheck -check-prefix=FeoRACE1 %s +// FeoRACE1: "-out:foo.exe" + +// RUN: %clang_cl /Fefoo /obar -### -- %s 2>&1 | FileCheck -check-prefix=FeoRACE2 %s +// FeoRACE2: "-out:bar.exe" + + +// RUN: %clang_cl /ofoo -### -- %s 2>&1 | FileCheck -check-prefix=FeoNOEXT1 %s +// FeoNOEXT1: "-out:foo.exe" + +// RUN: %clang_cl /o foo -### -- %s 2>&1 | FileCheck -check-prefix=FeoNOEXT2 %s +// FeoNOEXT2: "-out:foo.exe" + +// RUN: %clang_cl /o foo /LD -### -- %s 2>&1 | FileCheck -check-prefix=FeoNOEXTDLL %s +// RUN: %clang_cl /ofoo /LDd -### -- %s 2>&1 | FileCheck -check-prefix=FeoNOEXTDLL %s +// FeoNOEXTDLL: "-out:foo.dll" +// FeoNOEXTDLL: "-implib:foo.lib" + +// RUN: %clang_cl /ofoo.ext -### -- %s 2>&1 | FileCheck -check-prefix=FeoEXT1 %s +// FeoEXT1: "-out:foo.ext" + +// RUN: %clang_cl /o foo.ext -### -- %s 2>&1 | FileCheck -check-prefix=FeoEXT2 %s +// FeoEXT2: "-out:foo.ext" + +// RUN: %clang_cl /LD /o foo.ext -### -- %s 2>&1 | FileCheck -check-prefix=FeoEXTDLL %s +// RUN: %clang_cl /LDd /ofoo.ext -### -- %s 2>&1 | FileCheck -check-prefix=FeoEXTDLL %s +// FeoEXTDLL: "-out:foo.ext" +// FeoEXTDLL: "-implib:foo.lib" + +// RUN: %clang_cl /ofoo.dir/ -### -- %s 2>&1 | FileCheck -check-prefix=FeoDIR1 %s +// FeoDIR1: "-out:foo.dir{{[/\\]+}}cl-outputs.exe" + +// RUN: %clang_cl /o foo.dir/ -### -- %s 2>&1 | FileCheck -check-prefix=FeoDIR2 %s +// FeoDIR2: "-out:foo.dir{{[/\\]+}}cl-outputs.exe" + +// RUN: %clang_cl /LD /o foo.dir/ -### -- %s 2>&1 | FileCheck -check-prefix=FeoDIRDLL %s +// RUN: %clang_cl /LDd /ofoo.dir/ -### -- %s 2>&1 | FileCheck -check-prefix=FeoDIRDLL %s +// FeoDIRDLL: "-out:foo.dir{{[/\\]+}}cl-outputs.dll" +// FeoDIRDLL: "-implib:foo.dir{{[/\\]+}}cl-outputs.lib" + +// RUN: %clang_cl /ofoo.dir/a -### -- %s 2>&1 | FileCheck -check-prefix=FeoDIRNAME1 %s +// FeoDIRNAME1: "-out:foo.dir{{[/\\]+}}a.exe" + +// RUN: %clang_cl /o foo.dir/a -### -- %s 2>&1 | FileCheck -check-prefix=FeoDIRNAME2 %s +// FeoDIRNAME2: "-out:foo.dir{{[/\\]+}}a.exe" + +// RUN: %clang_cl /LD /o foo.dir/a -### -- %s 2>&1 | FileCheck -check-prefix=FeoDIRNAMEDLL %s +// RUN: %clang_cl /LDd /ofoo.dir/a -### -- %s 2>&1 | FileCheck -check-prefix=FeoDIRNAMEDLL %s +// FeoDIRNAMEDLL: "-out:foo.dir{{[/\\]+}}a.dll" +// FeoDIRNAMEDLL: "-implib:foo.dir{{[/\\]+}}a.lib" + +// RUN: %clang_cl /ofoo.dir/a.ext -### -- %s 2>&1 | FileCheck -check-prefix=FeoDIRNAMEEXT1 %s +// FeoDIRNAMEEXT1: "-out:foo.dir{{[/\\]+}}a.ext" + +// RUN: %clang_cl /o foo.dir/a.ext -### -- %s 2>&1 | FileCheck -check-prefix=FeoDIRNAMEEXT2 %s +// FeoDIRNAMEEXT2: "-out:foo.dir{{[/\\]+}}a.ext" + +// RUN: %clang_cl /LD /o foo.dir/a.ext -### -- %s 2>&1 | FileCheck -check-prefix=FeoDIRNAMEEXTDLL %s +// RUN: %clang_cl /LDd /ofoo.dir/a.ext -### -- %s 2>&1 | FileCheck -check-prefix=FeoDIRNAMEEXTDLL %s +// FeoDIRNAMEEXTDLL: "-out:foo.dir{{[/\\]+}}a.ext" +// FeoDIRNAMEEXTDLL: "-implib:foo.dir{{[/\\]+}}a.lib" + +// RUN: %clang_cl -### /o 2>&1 | FileCheck -check-prefix=FeoMISSINGARG %s +// FeoMISSINGARG: error: argument to '/o' is missing (expected 1 value) + +// RUN: %clang_cl /ofoo /o bar -### -- %s 2>&1 | FileCheck -check-prefix=FeoOVERRIDE %s +// FeoOVERRIDE: "-out:bar.exe" + + // RUN: %clang_cl /FA -### -- %s 2>&1 | FileCheck -check-prefix=FA %s // FA: "-o" "cl-outputs.asm" // RUN: %clang_cl /FA /Fafoo -### -- %s 2>&1 | FileCheck -check-prefix=FaNAME %s @@ -117,3 +239,28 @@ // RUN: %clang_cl /P /Fifoo.x -### -- %s 2>&1 | FileCheck -check-prefix=Fi2 %s // Fi2: "-E" // Fi2: "-o" "foo.x" + +// RUN: %clang_cl /P /ofoo -### -- %s 2>&1 | FileCheck -check-prefix=Fio1 %s +// Fio1: "-E" +// Fio1: "-o" "foo.i" + +// RUN: %clang_cl /P /o foo -### -- %s 2>&1 | FileCheck -check-prefix=Fio2 %s +// Fio2: "-E" +// Fio2: "-o" "foo.i" + +// RUN: %clang_cl /P /ofoo.x -### -- %s 2>&1 | FileCheck -check-prefix=Fio3 %s +// Fio3: "-E" +// Fio3: "-o" "foo.x" + +// RUN: %clang_cl /P /o foo.x -### -- %s 2>&1 | FileCheck -check-prefix=Fio4 %s +// Fio4: "-E" +// Fio4: "-o" "foo.x" + + +// 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"