From 29511875348c49c9c5a14bb086cd51e17feb01c9 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Sun, 24 Mar 2013 15:06:53 +0000 Subject: [PATCH] Reject -no-integrated-as on windows. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177840 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticDriverKinds.td | 2 ++ include/clang/Driver/ToolChain.h | 2 +- lib/Driver/Driver.cpp | 26 +++++++++++--------- lib/Driver/ToolChain.cpp | 8 +++--- lib/Driver/WindowsToolChain.cpp | 7 +++--- test/Driver/inhibit-downstream-commands.c | 1 + test/Driver/no-integrated-as-win.c | 2 +- 7 files changed, 27 insertions(+), 21 deletions(-) diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index 964d2bc193..d14fe94d6c 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -35,6 +35,8 @@ def err_drv_use_of_Z_option : Error< "unsupported use of internal gcc -Z option '%0'">; def err_drv_output_argument_with_multiple_files : Error< "cannot specify -o when generating multiple output files">; +def err_no_external_windows_assembler : Error< + "there is no external assembler we can use on windows">; def err_drv_unable_to_remove_file : Error< "unable to remove file: %0">; def err_drv_command_failure : Error< diff --git a/include/clang/Driver/ToolChain.h b/include/clang/Driver/ToolChain.h index 68d0db176d..ae9e397644 100644 --- a/include/clang/Driver/ToolChain.h +++ b/include/clang/Driver/ToolChain.h @@ -127,7 +127,7 @@ public: } /// Choose a tool to use to handle the action \p JA. - Tool &SelectTool(const JobAction &JA) const; + Tool *SelectTool(const JobAction &JA) const; // Helper methods diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 689ecbcd79..706409d05d 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -1288,7 +1288,7 @@ void Driver::BuildJobs(Compilation &C) const { } } -static const Tool &SelectToolForJob(Compilation &C, const ToolChain *TC, +static const Tool *SelectToolForJob(Compilation &C, const ToolChain *TC, const JobAction *JA, const ActionList *&Inputs) { const Tool *ToolForJob = 0; @@ -1301,17 +1301,19 @@ static const Tool &SelectToolForJob(Compilation &C, const ToolChain *TC, !C.getArgs().hasArg(options::OPT_save_temps) && isa(JA) && Inputs->size() == 1 && isa(*Inputs->begin())) { - const Tool &Compiler = + const Tool *Compiler = TC->SelectTool(cast(**Inputs->begin())); - if (Compiler.hasIntegratedAssembler()) { + if (!Compiler) + return NULL; + if (Compiler->hasIntegratedAssembler()) { Inputs = &(*Inputs)[0]->getInputs(); - ToolForJob = &Compiler; + ToolForJob = Compiler; } } // Otherwise use the tool for the current job. if (!ToolForJob) - ToolForJob = &TC->SelectTool(*JA); + ToolForJob = TC->SelectTool(*JA); // See if we should use an integrated preprocessor. We do so when we have // exactly one input, since this is the only use case we care about @@ -1324,7 +1326,7 @@ static const Tool &SelectToolForJob(Compilation &C, const ToolChain *TC, ToolForJob->hasIntegratedCPP()) Inputs = &(*Inputs)[0]->getInputs(); - return *ToolForJob; + return ToolForJob; } void Driver::BuildJobsForAction(Compilation &C, @@ -1366,7 +1368,9 @@ void Driver::BuildJobsForAction(Compilation &C, const ActionList *Inputs = &A->getInputs(); const JobAction *JA = cast(A); - const Tool &T = SelectToolForJob(C, TC, JA, Inputs); + const Tool *T = SelectToolForJob(C, TC, JA, Inputs); + if (!T) + return; // Only use pipes when there is exactly one input. InputInfoList InputInfos; @@ -1401,8 +1405,8 @@ void Driver::BuildJobsForAction(Compilation &C, A->getType(), BaseInput); if (CCCPrintBindings && !CCGenDiagnostics) { - llvm::errs() << "# \"" << T.getToolChain().getTripleString() << '"' - << " - \"" << T.getName() << "\", inputs: ["; + llvm::errs() << "# \"" << T->getToolChain().getTripleString() << '"' + << " - \"" << T->getName() << "\", inputs: ["; for (unsigned i = 0, e = InputInfos.size(); i != e; ++i) { llvm::errs() << InputInfos[i].getAsString(); if (i + 1 != e) @@ -1410,8 +1414,8 @@ void Driver::BuildJobsForAction(Compilation &C, } llvm::errs() << "], output: " << Result.getAsString() << "\n"; } else { - T.ConstructJob(C, *JA, Result, InputInfos, - C.getArgsForToolChain(TC, BoundArch), LinkingOutput); + T->ConstructJob(C, *JA, Result, InputInfos, + C.getArgsForToolChain(TC, BoundArch), LinkingOutput); } } diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp index b24de5d132..19270b2aa3 100644 --- a/lib/Driver/ToolChain.cpp +++ b/lib/Driver/ToolChain.cpp @@ -117,13 +117,13 @@ Tool *ToolChain::getTool(Action::ActionClass AC) const { llvm_unreachable("Invalid tool kind."); } -Tool &ToolChain::SelectTool(const JobAction &JA) const { +Tool *ToolChain::SelectTool(const JobAction &JA) const { if (getDriver().ShouldUseClangCompiler(JA)) - return *getClang(); + return getClang(); Action::ActionClass AC = JA.getKind(); if (AC == Action::AssembleJobClass && useIntegratedAs()) - return *getClangAs(); - return *getTool(AC); + return getClangAs(); + return getTool(AC); } std::string ToolChain::GetFilePath(const char *Name) const { diff --git a/lib/Driver/WindowsToolChain.cpp b/lib/Driver/WindowsToolChain.cpp index cc52c00710..dac7e77d60 100644 --- a/lib/Driver/WindowsToolChain.cpp +++ b/lib/Driver/WindowsToolChain.cpp @@ -14,6 +14,7 @@ #include "clang/Driver/ArgList.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" +#include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Path.h" @@ -43,10 +44,8 @@ Tool *Windows::buildLinker() const { Tool *Windows::buildAssembler() const { if (getTriple().getEnvironment() == llvm::Triple::MachO) return new tools::darwin::Assemble(*this); - else - // There no assembler we can use on windows other than the integrated - // assembler, so we ignore -no-integrated-as. - return ToolChain::buildAssembler(); + getDriver().Diag(clang::diag::err_no_external_windows_assembler); + return NULL; } bool Windows::IsIntegratedAssemblerDefault() const { diff --git a/test/Driver/inhibit-downstream-commands.c b/test/Driver/inhibit-downstream-commands.c index e06fdb1a3d..5e46708cfe 100644 --- a/test/Driver/inhibit-downstream-commands.c +++ b/test/Driver/inhibit-downstream-commands.c @@ -2,4 +2,5 @@ // CHECK: error: unknown type name 'invalid' // CHECK-NOT: clang: error: assembler command failed // CHECK-NOT: clang: error: linker command failed +// XFAIL: win32 invalid C code! diff --git a/test/Driver/no-integrated-as-win.c b/test/Driver/no-integrated-as-win.c index 298e885586..0d6c2958e5 100644 --- a/test/Driver/no-integrated-as-win.c +++ b/test/Driver/no-integrated-as-win.c @@ -1,3 +1,3 @@ // RUN: %clang -target x86_64-pc-win32 -### -no-integrated-as %s -c 2>&1 | FileCheck %s -// CHECK: cc1as" "-triple" "x86_64-pc-win32" +// CHECK: there is no external assembler we can use on windows -- 2.40.0