[cfe-commits] r67640 - in /cfe/trunk: include/clang/Driver/Driver.h lib/Driver/Driver.cpp test/Driver/bindings.c

Daniel Dunbar daniel at zuster.org
Tue Mar 24 12:02:32 PDT 2009


Author: ddunbar
Date: Tue Mar 24 14:02:31 2009
New Revision: 67640

URL: http://llvm.org/viewvc/llvm-project?rev=67640&view=rev
Log:
Driver: Change default use of "clang" compiler.
 - Don't default to using clang for C++ (use -ccc-clang-cxx to
   override).

 - Default to only using clang on i386 and x86_64 (use
   -ccc-clang-archs "" to override).

 - <rdar://problem/6712350> [driver] clang should not be used on
   powerpc by default
 - <rdar://problem/6705767> driver should default to -ccc-no-clang-cxx

I plan to add a warning that we are not using the clang compiler for
the given compilation so that users do not think clang is being used
in situations it isn't.

This change is motivated by the desire to be able to drop clang into a
build and have things "just work", even if it happens to get used to
compile C++ code or code for an architecture we don't support yet.

Modified:
    cfe/trunk/include/clang/Driver/Driver.h
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/test/Driver/bindings.c

Modified: cfe/trunk/include/clang/Driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=67640&r1=67639&r2=67640&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Tue Mar 24 14:02:31 2009
@@ -78,18 +78,18 @@
   bool CCCPrintBindings : 1;
 
 private:
-  /// Don't use clang for any tasks.
-  bool CCCNoClang : 1;
+  /// Use the clang compiler where possible.
+  bool CCCUseClang : 1;
 
-  /// Don't use clang for handling C++ and Objective-C++ inputs.
-  bool CCCNoClangCXX : 1;
+  /// Use clang for handling C++ and Objective-C++ inputs.
+  bool CCCUseClangCXX : 1;
 
-  /// Don't use clang as a preprocessor (clang's preprocessor will
-  /// still be used where an integrated CPP would).
-  bool CCCNoClangCPP : 1;
+  /// Use clang as a preprocessor (clang's preprocessor will still be
+  /// used where an integrated CPP would).
+  bool CCCUseClangCPP : 1;
 
-  /// Only use clang for the given architectures. Only used when
-  /// non-empty.
+  /// Only use clang for the given architectures (only used when
+  /// non-empty).
   std::set<std::string> CCCClangArchs;
 
   /// Certain options suppress the 'no input files' warning.

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=67640&r1=67639&r2=67640&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Mar 24 14:02:31 2009
@@ -43,9 +43,12 @@
     DefaultImageName(_DefaultImageName),
     Host(0),
     CCCIsCXX(false), CCCEcho(false), CCCPrintBindings(false),
-    CCCNoClang(false), CCCNoClangCXX(false), CCCNoClangCPP(false),
+    CCCUseClang(true), CCCUseClangCXX(false), CCCUseClangCPP(true),
     SuppressMissingInputWarning(false)
 {
+  // Only use clang on i386 and x86_64 by default.
+  CCCClangArchs.insert("i386");
+  CCCClangArchs.insert("x86_64");
 }
 
 Driver::~Driver() {
@@ -132,24 +135,27 @@
     } else if (!strcmp(Opt, "echo")) {
       CCCEcho = true;
       
+    } else if (!strcmp(Opt, "clang-cxx")) {
+      CCCUseClangCXX = true;
     } else if (!strcmp(Opt, "no-clang")) {
-      CCCNoClang = true;
-    } else if (!strcmp(Opt, "no-clang-cxx")) {
-      CCCNoClangCXX = true;
+      CCCUseClang = false;
     } else if (!strcmp(Opt, "no-clang-cpp")) {
-      CCCNoClangCPP = true;
+      CCCUseClangCPP = false;
     } else if (!strcmp(Opt, "clang-archs")) {
       assert(Start+1 < End && "FIXME: -ccc- argument handling.");
       const char *Cur = *++Start;
     
+      CCCClangArchs.clear();
       for (;;) {
         const char *Next = strchr(Cur, ',');
 
         if (Next) {
-          CCCClangArchs.insert(std::string(Cur, Next));
+          if (Cur != Next)
+            CCCClangArchs.insert(std::string(Cur, Next));
           Cur = Next + 1;
         } else {
-          CCCClangArchs.insert(std::string(Cur));
+          if (*Cur != '\0')
+            CCCClangArchs.insert(std::string(Cur));
           break;
         }
       }
@@ -986,19 +992,19 @@
                                     const std::string &ArchName) const {
   // Check if user requested no clang, or clang doesn't understand
   // this type (we only handle single inputs for now).
-  if (CCCNoClang || JA.size() != 1 || 
+  if (!CCCUseClang || JA.size() != 1 || 
       !types::isAcceptedByClang((*JA.begin())->getType()))
     return false;
 
-  // Otherwise make sure this is an action clang undertands.
+  // Otherwise make sure this is an action clang understands.
   if (isa<PreprocessJobAction>(JA)) {
-    if (CCCNoClangCPP)
+    if (!CCCUseClangCPP)
       return false;
   } else if (!isa<PrecompileJobAction>(JA) && !isa<CompileJobAction>(JA))
     return false;
 
-  // Avoid CXX if the user requested.
-  if (CCCNoClangCXX && types::isCXX((*JA.begin())->getType()))
+  // Use clang for C++?
+  if (!CCCUseClangCXX && types::isCXX((*JA.begin())->getType()))
     return false;
 
   // Finally, don't use clang if this isn't one of the user specified

Modified: cfe/trunk/test/Driver/bindings.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/bindings.c?rev=67640&r1=67639&r2=67640&view=diff

==============================================================================
--- cfe/trunk/test/Driver/bindings.c (original)
+++ cfe/trunk/test/Driver/bindings.c Tue Mar 24 14:02:31 2009
@@ -30,15 +30,22 @@
 // RUN: grep 'bind - "clang", inputs: \[".*bindings.c"\], output: (nothing)' %t &&
 // RUN: clang -ccc-host-triple i386-unknown-unknown -ccc-print-bindings -ccc-no-clang -fsyntax-only %s 2> %t &&
 // RUN: grep 'bind - "gcc::Compile", inputs: \[".*bindings.c"\], output: (nothing)' %t &&
-// RUN: clang -ccc-host-triple i386-unknown-unknown -ccc-print-bindings -ccc-no-clang-cxx -fsyntax-only -x c++ %s 2> %t &&
+// RUN: clang -ccc-host-triple i386-unknown-unknown -ccc-print-bindings -fsyntax-only -x c++ %s 2> %t &&
 // RUN: grep 'bind - "gcc::Compile", inputs: \[".*bindings.c"\], output: (nothing)' %t &&
-// RUN: clang -ccc-print-bindings -ccc-no-clang-cpp -fsyntax-only -no-integrated-cpp -x c++ %s 2> %t &&
-// RUN: grep 'bind - "gcc::Preprocess", inputs: \[".*bindings.c"\], output: ".*\.ii"' %t &&
-// RUN: grep 'bind - "clang", inputs: \[".*\.ii"\], output: (nothing)' %t &&
-// RUN: clang -ccc-host-triple i386-unknown-unknown -ccc-host-triple i386-apple-darwin9 -ccc-print-bindings -ccc-clang-archs i386 %s -S -arch ppc 2> %t &&
+// RUN: clang -ccc-host-triple i386-unknown-unknown -ccc-print-bindings -ccc-clang-cxx -fsyntax-only -x c++ %s 2> %t &&
+// RUN: grep 'bind - "clang", inputs: \[".*bindings.c"\], output: (nothing)' %t &&
+// RUN: clang -ccc-host-triple i386-unknown-unknown -ccc-print-bindings -ccc-no-clang-cpp -fsyntax-only -no-integrated-cpp %s 2> %t &&
+// RUN: grep 'bind - "gcc::Preprocess", inputs: \[".*bindings.c"\], output: ".*\.i"' %t &&
+// RUN: grep 'bind - "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 'bind - "gcc::Compile", inputs: \[".*bindings.c"\], output: "bindings.s"' %t &&
-// RUN: clang -ccc-host-triple i386-unknown-unknown -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 ppc %s -S -arch ppc 2> %t &&
+// RUN: grep 'bind - "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 &&
 // RUN: grep 'bind - "clang", inputs: \[".*bindings.c"\], output: "bindings.s"' %t &&
+// RUN: clang -ccc-host-triple powerpc-unknown-unknown -ccc-print-bindings %s -S 2> %t &&
+// RUN: grep 'bind - "gcc::Compile", inputs: \[".*bindings.c"\], output: "bindings.s"' %t &&
 
 // Darwin bindings
 // RUN: clang -ccc-host-triple i386-apple-darwin9 -ccc-print-bindings %s 2> %t &&





More information about the cfe-commits mailing list