[cfe-commits] r163605 - /cfe/trunk/tools/driver/driver.cpp

David Chisnall csdavec at swan.ac.uk
Tue Sep 11 02:58:54 PDT 2012


Author: theraven
Date: Tue Sep 11 04:58:54 2012
New Revision: 163605

URL: http://llvm.org/viewvc/llvm-project?rev=163605&view=rev
Log:
Select the correct, or, failing that, compatible, dialect when invoked as cc,
c89, c99, and so on.  No change to the default dialect when invoked as clang /
clang++.


Modified:
    cfe/trunk/tools/driver/driver.cpp

Modified: cfe/trunk/tools/driver/driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/driver.cpp?rev=163605&r1=163604&r2=163605&view=diff
==============================================================================
--- cfe/trunk/tools/driver/driver.cpp (original)
+++ cfe/trunk/tools/driver/driver.cpp Tue Sep 11 04:58:54 2012
@@ -277,21 +277,32 @@
   // "x86_64-linux-clang" as interpreted as suffix "clang" with
   // target prefix "x86_64-linux". If such a target prefix is found,
   // is gets added via -target as implicit first argument.
+  //
+  // The default language dialect depends on the name by which clang was
+  // invoked.  These names first follow the standard and then the GCC
+  // implementation.  When invoked as c89 or c99, clang should be a c89 or c99
+  // compiler, respectively, per POSIX.  The compiler called cc was deprecated
+  // by POSIX in 1997 and the language dialect is implementation defined.
+  // Unfortunately, a lot of existing code depends on it being a C89 compiler.
   static const struct {
     const char *Suffix;
     bool IsCXX;
     bool IsCPP;
+    const char *DefaultDialect;
   } suffixes [] = {
-    { "clang", false, false },
-    { "clang++", true, false },
-    { "clang-c++", true, false },
-    { "clang-cc", false, false },
-    { "clang-cpp", false, true },
-    { "clang-g++", true, false },
-    { "clang-gcc", false, false },
-    { "cc", false, false },
-    { "cpp", false, true },
-    { "++", true, false },
+    { "clang", false, false, 0 },
+    { "clang++", true, false, 0 },
+    { "clang-c++", true, false, 0 },
+    { "clang-cc", false, false, "-std=c89" },
+    { "clang-cpp", false, true, 0 },
+    { "clang-g++", true, false, "-std=gnu++89" },
+    { "clang-gcc", false, false, "-std=gnu89" },
+    { "cc", false, false, "-std=c89" },
+    { "c89", false, false, "-std=c89" },
+    { "c99", false, false, "-std=c99" },
+    { "c11", false, false, "-std=c11" },
+    { "cpp", false, true, 0 },
+    { "++", true, false, 0 },
   };
   std::string ProgName(llvm::sys::path::stem(ArgVector[0]));
   StringRef ProgNameRef(ProgName);
@@ -304,10 +315,14 @@
     for (i = 0; i < sizeof(suffixes) / sizeof(suffixes[0]); ++i) {
       if (ProgNameRef.endswith(suffixes[i].Suffix)) {
         FoundMatch = true;
-        if (suffixes[i].IsCXX)
+        if (suffixes[i].IsCXX) {
           TheDriver.CCCIsCXX = true;
+          fprintf(stderr, "ccc is c++\n");
+        }
         if (suffixes[i].IsCPP)
           TheDriver.CCCIsCPP = true;
+        if (suffixes[i].DefaultDialect)
+          ArgVector.insert(ArgVector.begin()+1, suffixes[i].DefaultDialect);
         break;
       }
     }





More information about the cfe-commits mailing list