From 953b8d1f150f3b1bd81eb87e790d708d0b2eae37 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 8 Sep 2009 23:36:55 +0000 Subject: [PATCH] Fix ShouldUseClangCompiler to use llvm::Triple. - -1 FIXME, and fixes 'clang -arch armv4t ...', for example. llvm-svn: 81276 --- clang/include/clang/Driver/Driver.h | 5 +-- clang/lib/Driver/Driver.cpp | 50 +++++++++++++---------------- clang/lib/Driver/ToolChains.cpp | 12 +++---- clang/test/Driver/bindings.c | 2 +- 4 files changed, 32 insertions(+), 37 deletions(-) diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h index 623485bc6ab3..bdc6f3b18a6e 100644 --- a/clang/include/clang/Driver/Driver.h +++ b/clang/include/clang/Driver/Driver.h @@ -15,6 +15,7 @@ #include "clang/Driver/Phases.h" #include "clang/Driver/Util.h" +#include "llvm/ADT/Triple.h" #include "llvm/System/Path.h" // FIXME: Kill when CompilationInfo // lands. #include @@ -102,7 +103,7 @@ public: private: /// Only use clang for the given architectures (only used when /// non-empty). - std::set CCCClangArchs; + std::set CCCClangArchs; /// Certain options suppress the 'no input files' warning. bool SuppressMissingInputWarning : 1; @@ -260,7 +261,7 @@ public: /// ShouldUseClangCompilar - Should the clang compiler be used to /// handle this action. bool ShouldUseClangCompiler(const Compilation &C, const JobAction &JA, - const std::string &ArchName) const; + const llvm::Triple &ArchName) const; /// @} diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 93fbe54ebe39..26bcb59ffdcf 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -60,12 +60,9 @@ Driver::Driver(const char *_Name, const char *_Dir, { #ifdef USE_PRODUCTION_CLANG // In a "production" build, only use clang on architectures we expect to work. - CCCClangArchs.insert("i386"); - CCCClangArchs.insert("x86_64"); - CCCClangArchs.insert("arm"); - CCCClangArchs.insert("armv5"); - CCCClangArchs.insert("armv6"); - CCCClangArchs.insert("armv7"); + CCCClangArchs.insert(llvm::Triple::x86); + CCCClangArchs.insert(llvm::Triple::x86_64); + CCCClangArchs.insert(llvm::Triple::arm); #endif } @@ -169,23 +166,27 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) { CCCUseClangCPP = false; } else if (!strcmp(Opt, "clang-archs")) { assert(Start+1 < End && "FIXME: -ccc- argument handling."); - const char *Cur = *++Start; + llvm::StringRef Cur = *++Start; CCCClangArchs.clear(); - for (;;) { - const char *Next = strchr(Cur, ','); + while (!Cur.empty()) { + std::pair Split = Cur.split(','); - if (Next) { - if (Cur != Next) - CCCClangArchs.insert(std::string(Cur, Next)); - Cur = Next + 1; - } else { - if (*Cur != '\0') - CCCClangArchs.insert(std::string(Cur)); - break; + if (!Split.first.empty()) { + llvm::Triple::ArchType Arch = + llvm::Triple(Split.first, "", "").getArch(); + + if (Arch == llvm::Triple::UnknownArch) { + // FIXME: Error handling. + llvm::errs() << "invalid arch name: " << Split.first << "\n"; + exit(1); + } + + CCCClangArchs.insert(Arch); } - } + Cur = Split.second; + } } else if (!strcmp(Opt, "host-triple")) { assert(Start+1 < End && "FIXME: -ccc- argument handling."); HostTriple = *++Start; @@ -1262,14 +1263,7 @@ const HostInfo *Driver::GetHostInfo(const char *TripleStr) const { } bool Driver::ShouldUseClangCompiler(const Compilation &C, const JobAction &JA, - const std::string &ArchNameStr) const { - // FIXME: Remove this hack. - const char *ArchName = ArchNameStr.c_str(); - if (ArchNameStr == "powerpc") - ArchName = "ppc"; - else if (ArchNameStr == "powerpc64") - ArchName = "ppc64"; - + const llvm::Triple &Triple) const { // Check if user requested no clang, or clang doesn't understand this type (we // only handle single inputs for now). if (!CCCUseClang || JA.size() != 1 || @@ -1297,8 +1291,8 @@ bool Driver::ShouldUseClangCompiler(const Compilation &C, const JobAction &JA, // Finally, don't use clang if this isn't one of the user specified archs to // build. - if (!CCCClangArchs.empty() && !CCCClangArchs.count(ArchName)) { - Diag(clang::diag::warn_drv_not_using_clang_arch) << ArchName; + if (!CCCClangArchs.empty() && !CCCClangArchs.count(Triple.getArch())) { + Diag(clang::diag::warn_drv_not_using_clang_arch) << Triple.getArchName(); return false; } diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index d6067afc3dba..6512203d0931 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -103,7 +103,7 @@ Darwin::~Darwin() { Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const { Action::ActionClass Key; - if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) + if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple())) Key = Action::AnalyzeJobClass; else Key = JA.getKind(); @@ -338,7 +338,7 @@ Generic_GCC::~Generic_GCC() { Tool &Generic_GCC::SelectTool(const Compilation &C, const JobAction &JA) const { Action::ActionClass Key; - if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) + if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple())) Key = Action::AnalyzeJobClass; else Key = JA.getKind(); @@ -404,7 +404,7 @@ OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple) Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const { Action::ActionClass Key; - if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) + if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple())) Key = Action::AnalyzeJobClass; else Key = JA.getKind(); @@ -439,7 +439,7 @@ FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32) Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const { Action::ActionClass Key; - if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) + if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple())) Key = Action::AnalyzeJobClass; else Key = JA.getKind(); @@ -480,7 +480,7 @@ AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple) Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const { Action::ActionClass Key; - if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) + if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple())) Key = Action::AnalyzeJobClass; else Key = JA.getKind(); @@ -545,7 +545,7 @@ DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple) Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const { Action::ActionClass Key; - if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) + if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple())) Key = Action::AnalyzeJobClass; else Key = JA.getKind(); diff --git a/clang/test/Driver/bindings.c b/clang/test/Driver/bindings.c index 3d0bf35c1e16..393739006bb7 100644 --- a/clang/test/Driver/bindings.c +++ b/clang/test/Driver/bindings.c @@ -39,7 +39,7 @@ // RUN: grep '"clang", inputs: \[".*\.i"\], output: (nothing)' %t && // RUN: clang -ccc-host-triple i386-apple-darwin9 -ccc-print-bindings -ccc-clang-archs i386 %s -S -arch ppc 2> %t && // RUN: grep '"gcc::Compile", inputs: \[".*bindings.c"\], output: "bindings.s"' %t && -// RUN: clang -ccc-host-triple i386-apple-darwin9 -ccc-print-bindings -ccc-clang-archs ppc %s -S -arch ppc 2> %t && +// RUN: clang -ccc-host-triple i386-apple-darwin9 -ccc-print-bindings -ccc-clang-archs powerpc %s -S -arch ppc 2> %t && // RUN: grep '"clang", inputs: \[".*bindings.c"\], output: "bindings.s"' %t && // RUN: clang -ccc-host-triple powerpc-unknown-unknown -ccc-print-bindings -ccc-clang-archs "" %s -S 2> %t &&