From: Daniel Dunbar Date: Thu, 15 Oct 2009 20:02:44 +0000 (+0000) Subject: Driver: Default to using PTH for C++ precompiled header support, PCH for C++ X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0ebd9321ba380471010341f24c874f46f56e7581;p=clang Driver: Default to using PTH for C++ precompiled header support, PCH for C++ isn't implemented yet. - 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 --- diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 37fe980be2..2a9ff8f676 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -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(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 index 0000000000..a06a257538 --- /dev/null +++ b/test/Driver/cxx-pth.cpp @@ -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"