]> granicus.if.org Git - clang/commitdiff
Driver: Default to using PTH for C++ precompiled header support, PCH for C++
authorDaniel Dunbar <daniel@zuster.org>
Thu, 15 Oct 2009 20:02:44 +0000 (20:02 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 15 Oct 2009 20:02:44 +0000 (20:02 +0000)
isn't implemented yet.
 - <rdar://problem/7297571> Clang should use pretokenized headers for C++ PCH
   files

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84197 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Tools.cpp
test/Driver/cxx-pth.cpp [new file with mode: 0644]

index 37fe980be2a9953165fc26161f2365de9c0b8bf9..2a9ff8f676e65a51dd15bc5fa7f76b984868dbfa 100644 (file)
@@ -142,10 +142,15 @@ void Clang::AddPreprocessingOptions(const Driver &D,
       continue;
 
     if (A->getOption().matches(options::OPT_include)) {
+      // Use PCH if the user requested it, except for C++ (for now).
+      bool UsePCH = D.CCCUsePCH;
+      if (types::isCXX(Inputs[0].getType()))
+        UsePCH = false;
+
       bool FoundPTH = false;
       bool FoundPCH = false;
       llvm::sys::Path P(A->getValue(Args));
-      if (D.CCCUsePCH) {
+      if (UsePCH) {
         P.appendSuffix("pch");
         if (P.exists())
           FoundPCH = true;
@@ -164,8 +169,8 @@ void Clang::AddPreprocessingOptions(const Driver &D,
       if (!FoundPCH && !FoundPTH) {
         P.appendSuffix("gch");
         if (P.exists()) {
-          FoundPCH = D.CCCUsePCH;
-          FoundPTH = !D.CCCUsePCH;
+          FoundPCH = UsePCH;
+          FoundPTH = !UsePCH;
         }
         else
           P.eraseSuffix();
@@ -173,7 +178,7 @@ void Clang::AddPreprocessingOptions(const Driver &D,
 
       if (FoundPCH || FoundPTH) {
         A->claim();
-        if (D.CCCUsePCH)
+        if (UsePCH)
           CmdArgs.push_back("-include-pch");
         else
           CmdArgs.push_back("-include-pth");
@@ -528,7 +533,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     else
       CmdArgs.push_back("-E");
   } else if (isa<PrecompileJobAction>(JA)) {
-    if (D.CCCUsePCH)
+    // Use PCH if the user requested it, except for C++ (for now).
+    bool UsePCH = D.CCCUsePCH;
+    if (types::isCXX(Inputs[0].getType()))
+      UsePCH = false;
+
+    if (UsePCH)
       CmdArgs.push_back("-emit-pch");
     else
       CmdArgs.push_back("-emit-pth");
diff --git a/test/Driver/cxx-pth.cpp b/test/Driver/cxx-pth.cpp
new file mode 100644 (file)
index 0000000..a06a257
--- /dev/null
@@ -0,0 +1,12 @@
+// Test forced PTH for CXX support.
+
+// RUN: clang -x c++-header %s -### 2> %t.log &&
+// RUN: FileCheck -check-prefix EMIT -input-file %t.log %s &&
+
+// EMIT: "{{.*}}/clang-cc{{.*}}" {{.*}} "-emit-pth" "{{.*}}.cpp.gch" "-x" "c++-header" "{{.*}}.cpp"
+
+// RUN: touch %t.h.gch &&
+// RUN: clang -E -include %t.h %s -### 2> %t.log &&
+// RUN: FileCheck -check-prefix USE -input-file %t.log %s
+
+// USE: "{{.*}}/clang-cc{{.*}}" {{.*}}"-include-pth" "{{.*}}.h.gch" {{.*}}"-x" "c++" "{{.*}}.cpp"