PTH for C++

Hey folks,

I wanted to ask about the existing PTH support in clang, and how well
it works for C++.

I couldn't find any user facing documentation, but my understanding is
that you use it by picking some representative C++ file that includes
most of the headers you want to pre-tokenize and invoke clang like so:
clang -cc1 -emit-pth most_headers.h -o most_headers.h.pth

Then you do the rest of your compiles with -token-cache most_headers.h.pth:
clang -cc1 -token-cache most_headers.h.pth foo.cc -o foo.o

Is this correct? If so, how would I go about modifying a standard
Makefile setup to use PTH? I don't see how this functionality is
exposed through the driver.

Have other people had success with PTH? I remember ddunbar mentioned
in passing on IRC that PTH doesn't work well for C++, but I'm looking
for more detail. If no one has numbers for how it performs, I was
going to self-host clang using PTH to make some.

Thanks,
Reid

Hi,

I wanted to ask about the existing PTH support in clang, and how well
it works for C++.

I believe PTH is dead and PCH is what's used these days. See
http://clang.llvm.org/docs/UsersManual.html#precompiledheaders .

PCH support for C++ isn't there yet, but Argyrios is working on it.

Nico

PTH should work fine for C++, since it only works on C++.

The usage of PTH/PCH follows the same mechanism for precompiled headers as gcc:

$ clang -x c++-header t.h -o t.h.pth

$ clang -include t.h t.cpp

Clang will automatically use 't.h.pth' if it is present instead of t.h.

Quick clarification: PTH is not dead at all, and is currently being actively used by clang to support precompiled headers for C++/Objective-C++.

As Nico points out, Argyrios is working on PCH support for C++, but even when that is in place PTH isn't necessarily going away. It is extremely useful for doing performance analysis work on the frontend, as it allows one to analyze the timings of parsing/semantic analysis by removing most of the time used for lexing.