[cfe-dev] PCH: separation from source header

Argyrios Kyrtzidis kyrtzidis at apple.com
Thu Sep 23 03:17:09 PDT 2010


On Sep 22, 2010, at 1:56 AM, Ilya Murav'jov wrote:

> Argyrios Kyrtzidis пишет:
>> On Sep 18, 2010, at 6:20 PM, Ilya Murav'jov wrote:
>> 
>>> 2) Is it possible to use Clang' PCH in the test case above? If not then
>>> what is a solution?
>> 
>> $ clang -c -Isrc -include build/test.h -o build/test.o src/test.c
>> 
>> -Argiris
>> 
>>> 3) What is the reason against using .h.pch automatically like gcc
> does it?
>>> 
> 
> Ok, with Clang 2.9 I succeeded in building my project with PCH, thanks.
> I have 2 things to say.
> 
> 1. I have to say that "-include" scheme is not so flexible as using PCH
> automatically, really. Here is my use case: let's say I have a project
> (a bunch of sources), and I want to use one PCH-file for it (and so on,
> one PCH-file per project). So I set that "-include" option for the
> project and now it is used for every source file in the project, without
> an exception,- that is no so good! In several cases I do want to avoid it:
> - my projects have C++ and C sources together; I can't use C++ PCH
>  header for C sources (so the hack is done - "-include" goes to CXX
>  options, not CPP ones).

Automatically using PCH seems like an architectural change with little benefit.
Most of your woes can be attributed to the fact that clang does not fallback to the source header when it can't use the PCH.
I think we should change the cannot-use-PCH errors to warnings and fallback to the source header, and maybe add a command-line option to enable the current behavior (hard errors when PCH can't be used).
Anyone have an objection about this ?

> - in some C++ sources I still need to set #defines at first lines (e.g.
> BOOST_AUTO_TEST_MAIN for Boost.Test library); now it is impossible.

If clang fallbacks to the source header, you can define them at command-line (-D).

> 
> That said, I need to create additional projects (without PCH) just for
> such exceptional sources to make things to work.
> 
> 2. I have got some benchmarks (compiler' speed in debug mode) gcc vs
> clang for my sources (http://gitorious.org/bombono-dvd). I use Boost *a
> little*, and it makes a compiler be somewhat slow. Here are compilation
> times (-g -O0) for src/mgui/editor/select.cpp (39kb, not so big!):
> 
> a) without PCH:
> clang++ 2.9: 5.35 seconds
> g++     4.2: 5.05 seconds
> 
> b) with PCH:
> clang++ 2.9: 3.47 seconds
> g++     4.2: 2.88 seconds

Interesting, is this gcc 4.4 ? Can you file a bug and include the preprocessed header (move headers of select.cpp to the preprocessed header before including it as well).

-Argiris

> 
> So I am sure clang has some room for optimizing like
> http://clang.llvm.org/features.html#performance states it. :)
> 
> Regards,
> Ilya
> 
> P.S. Anyway, I was surprised when clang managed to build all my projects
> and all tests are working! (except just a trivial one -
> http://llvm.org/bugs/show_bug.cgi?id=8182).
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev





More information about the cfe-dev mailing list