diff options
| author | Daniel Dunbar <daniel@zuster.org> | 2009-10-15 20:02:44 +0000 |
|---|---|---|
| committer | Daniel Dunbar <daniel@zuster.org> | 2009-10-15 20:02:44 +0000 |
| commit | cbc34b769e97693eb46ee630127c639cd64b9f50 (patch) | |
| tree | b10803d88ed8d6f8a30041c04ddc687a57b0bd7b | |
| parent | 74c35c126a989e4997ad9d1f5f5984bbc7783214 (diff) | |
| download | bcm5719-llvm-cbc34b769e97693eb46ee630127c639cd64b9f50.tar.gz bcm5719-llvm-cbc34b769e97693eb46ee630127c639cd64b9f50.zip | |
Driver: Default to using PTH for C++ precompiled header support, PCH for C++
isn't implemented yet.
- <rdar://problem/7297571> Clang should use pretokenized headers for C++ PCH
files
llvm-svn: 84197
| -rw-r--r-- | clang/lib/Driver/Tools.cpp | 20 | ||||
| -rw-r--r-- | clang/test/Driver/cxx-pth.cpp | 12 |
2 files changed, 27 insertions, 5 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 37fe980be2a..2a9ff8f676e 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/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<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/clang/test/Driver/cxx-pth.cpp b/clang/test/Driver/cxx-pth.cpp new file mode 100644 index 00000000000..a06a2575386 --- /dev/null +++ b/clang/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" |

