From 6164753e81c574589822b246b89099dbe9439710 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Mon, 17 Nov 2014 19:16:36 +0000 Subject: [PATCH] clang-cl: Allow /Fo without an argument (PR21589) When it's used without an argument, the default file name is used. The same goes for /Fe. Also, allow using /Fo, /Fa and /Fe with multiple inputs if they don't have an argument. llvm-svn: 222164 --- clang/lib/Driver/Driver.cpp | 19 ++++--------------- clang/test/Driver/cl-outputs.c | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 1794e8e..5d25ed7 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1165,11 +1165,8 @@ void Driver::BuildActions(const ToolChain &TC, DerivedArgList &Args, // Diagnose misuse of /Fo. if (Arg *A = Args.getLastArg(options::OPT__SLASH_Fo)) { StringRef V = A->getValue(); - if (V.empty()) { - // It has to have a value. - Diag(clang::diag::err_drv_missing_argument) << A->getSpelling() << 1; - Args.eraseArg(options::OPT__SLASH_Fo); - } else if (Inputs.size() > 1 && !llvm::sys::path::is_separator(V.back())) { + if (Inputs.size() > 1 && !V.empty() && + !llvm::sys::path::is_separator(V.back())) { // Check whether /Fo tries to name an output file for multiple inputs. Diag(clang::diag::err_drv_out_file_argument_with_multiple_sources) << A->getSpelling() << V; @@ -1180,7 +1177,8 @@ void Driver::BuildActions(const ToolChain &TC, DerivedArgList &Args, // Diagnose misuse of /Fa. if (Arg *A = Args.getLastArg(options::OPT__SLASH_Fa)) { StringRef V = A->getValue(); - if (Inputs.size() > 1 && !llvm::sys::path::is_separator(V.back())) { + if (Inputs.size() > 1 && !V.empty() && + !llvm::sys::path::is_separator(V.back())) { // Check whether /Fa tries to name an asm file for multiple inputs. Diag(clang::diag::err_drv_out_file_argument_with_multiple_sources) << A->getSpelling() << V; @@ -1188,15 +1186,6 @@ void Driver::BuildActions(const ToolChain &TC, DerivedArgList &Args, } } - // Diagnose misuse of /Fe. - if (Arg *A = Args.getLastArg(options::OPT__SLASH_Fe)) { - 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_Fe); - } - } - // Diagnose misuse of /o. if (Arg *A = Args.getLastArg(options::OPT__SLASH_o)) { if (A->getValue()[0] == '\0') { diff --git a/clang/test/Driver/cl-outputs.c b/clang/test/Driver/cl-outputs.c index 29ea6b6..be1172f 100644 --- a/clang/test/Driver/cl-outputs.c +++ b/clang/test/Driver/cl-outputs.c @@ -7,6 +7,9 @@ // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=DEFAULT %s // DEFAULT: "-o" "cl-outputs.obj" +// RUN: %clang_cl /Fo -### -- %s 2>&1 | FileCheck -check-prefix=FoEMPTY %s +// FoEMPTY: "-o" "cl-outputs.obj" + // RUN: %clang_cl /Foa -### -- %s 2>&1 | FileCheck -check-prefix=FoNAME %s // FoNAME: "-o" "a.obj" @@ -25,15 +28,15 @@ // RUN: %clang_cl /Fo.. -### -- %s 2>&1 | FileCheck -check-prefix=FoCRAZY %s // FoCRAZY: "-o" "..obj" -// RUN: %clang_cl /Fo -### 2>&1 | FileCheck -check-prefix=FoMISSINGARG %s -// FoMISSINGARG: error: argument to '/Fo' is missing (expected 1 value) - // RUN: %clang_cl /Foa.obj -### -- %s %s 2>&1 | FileCheck -check-prefix=CHECK-MULTIPLESOURCEERROR %s // CHECK-MULTIPLESOURCEERROR: error: cannot specify '/Foa.obj' when compiling multiple source files // RUN: %clang_cl /Fomydir/ -### -- %s %s 2>&1 | FileCheck -check-prefix=CHECK-MULTIPLESOURCEOK %s // CHECK-MULTIPLESOURCEOK: "-o" "mydir{{[/\\]+}}cl-outputs.obj" +// RUN: %clang_cl /Fo -### -- %s %s 2>&1 | FileCheck -check-prefix=CHECK-MULTIPLESOURCEOK2 %s +// CHECK-MULTIPLESOURCEOK2: "-o" "cl-outputs.obj" +// CHECK-MULTIPLESOURCEOK2: "-o" "cl-outputs.obj" // RUN: %clang_cl /c /oa -### -- %s 2>&1 | FileCheck -check-prefix=oNAME1 %s // oNAME1: "-o" "a.obj" @@ -99,6 +102,10 @@ // RUN: %clang_cl /Fefoo -### -- %s 2>&1 | FileCheck -check-prefix=FeNOEXT %s // FeNOEXT: "-out:foo.exe" +// RUN: %clang_cl /Fe -### -- %s 2>&1 | FileCheck -check-prefix=FeEMPTY %s +// FeEMPTY-NOT: argument to '/Fe' is missing +// FeEMPTY: "-out:cl-outputs.exe" + // RUN: %clang_cl /Fefoo /LD -### -- %s 2>&1 | FileCheck -check-prefix=FeNOEXTDLL %s // RUN: %clang_cl /Fefoo /LDd -### -- %s 2>&1 | FileCheck -check-prefix=FeNOEXTDLL %s // FeNOEXTDLL: "-out:foo.dll" @@ -136,9 +143,6 @@ // FeDIRNAMEEXTDLL: "-out:foo.dir{{[/\\]+}}a.ext" // FeDIRNAMEEXTDLL: "-implib:foo.dir{{[/\\]+}}a.lib" -// RUN: %clang_cl /Fe -### 2>&1 | FileCheck -check-prefix=FeMISSINGARG %s -// FeMISSINGARG: error: argument to '/Fe' is missing (expected 1 value) - // RUN: %clang_cl /Fefoo /Febar -### -- %s 2>&1 | FileCheck -check-prefix=FeOVERRIDE %s // FeOVERRIDE: "-out:bar.exe" @@ -214,6 +218,8 @@ // RUN: %clang_cl /FA -### -- %s 2>&1 | FileCheck -check-prefix=FA %s // FA: "-o" "cl-outputs.asm" +// RUN: %clang_cl /FA /Fa -### -- %s 2>&1 | FileCheck -check-prefix=FaEMPTY %s +// FaEMPTY: "-o" "cl-outputs.asm" // RUN: %clang_cl /FA /Fafoo -### -- %s 2>&1 | FileCheck -check-prefix=FaNAME %s // RUN: %clang_cl /Fafoo -### -- %s 2>&1 | FileCheck -check-prefix=FaNAME %s // FaNAME: "-o" "foo.asm" @@ -227,6 +233,9 @@ // FaDIRNAMEEXT: "-o" "foo.dir{{[/\\]+}}a.ext" // RUN: %clang_cl /Faa.asm -### -- %s %s 2>&1 | FileCheck -check-prefix=FaMULTIPLESOURCE %s // FaMULTIPLESOURCE: error: cannot specify '/Faa.asm' when compiling multiple source files +// RUN: %clang_cl /Fa -### -- %s %s 2>&1 | FileCheck -check-prefix=FaMULTIPLESOURCEOK %s +// FaMULTIPLESOURCEOK: "-o" "cl-outputs.asm" +// FaMULTIPLESOURCEOK: "-o" "cl-outputs.asm" // RUN: %clang_cl /P -### -- %s 2>&1 | FileCheck -check-prefix=P %s // P: "-E" -- 2.7.4