[cfe-dev] PCH: separation from source header
Argyrios Kyrtzidis
kyrtzidis at apple.com
Sun Sep 19 07:39:24 PDT 2010
On Sep 19, 2010, at 3:05 PM, Ilya Murav'jov wrote:
> Argyrios Kyrtzidis пишет:
>> On Sep 18, 2010, at 6:20 PM, Ilya Murav'jov wrote:
>>
>>> So, here is the questions:
>>> 1) How can I make sure that PCH header is being used, not test.h? For
>>> gcc, I use special "fake" build/test.h with contents like so:
>>> #error PCH' using is failed, that shouldn't be done :(
>>>
>>> then, if PCH cannot be used than compilation will break. But this is not
>>> working for clang.
>>
>> It should, can you post a test case where this doesn't work ?
>>
>
> Well, I mean that that technique always fails now (fake header always
> takes priority). Ok, here http://clang.llvm.org/docs/PCHInternals.html I
> found out about -print-stats option for Clang compiler frontend, clang
> -cc1 . But Clang doesn't produce any statistics about PCH use as the doc
> states:
>
> clang -cc1 -triple i386-pc-linux-gnu -S -disable-free
> -disable-llvm-verifier -main-file-name test.cpp -mrelocation-model
> static -mdisable-fp-elim -mconstructor-aliases -target-cpu pentium4
> -target-linker-version 2.20 -v -resource-dir
> /opt/llvm-28dbg/lib/clang/2.8 -include-pch build/test.h.pch -I src
> -ferror-limit 19 -fmessage-length 165 -fexceptions -fgnu-runtime
> -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/cc-acnTys.s -x c++
> -print-stats src/test.cpp 2&>1 | grep PCH
It's actually under "AST File Statistics:" now. We should either revert it back to 'PCH' or update the doc.
>
> P.S. I just want to say that I don't like that "Clang falls back to
> directly processing the content of test.h" *silently* if it cannot use
> .h.pch file. Some way to turn that behaviour into an error/warning would
> be sufficient.
It doesn't "fall back silently", it didn't find the PCH file in the first place so "-include test.h" was treated as a normal [#include "test.h"].
If it finds a PCH file, there will be an error if it cannot use it.
If you'd like to specify the path of a PCH file and get an error if it doesn't exist, you may find useful this "low level" way (although I wouldn't recommend it since it's clang-specific):
$ clang -c -Isrc -Xclang -include-pch -Xclang build/t.h.pch -o build/test.o src/test.c
If the file after the second -Xclang doesn't exist you will get an error.
>
>>> 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
>
> Ok, now build/test.h.pch is used somehow. But there plenty of errors if
> I use PCH for C++, e.g.:
>
> $ cat src/test.h
> #include <sstream>
> $ cat src/test.cpp
> #include <test.h>
>
> int main()
> {
> std::stringstream strm;
> return 0;
> }
>
> $ clang++ -x c++-header -Isrc -o build/test.h.pch src/test.h
> $ clang++ -c -Isrc -o build/test.o src/test.cpp <---- no errors
> $ clang++ -c -Isrc -include build/test.h -o build/test.o src/test.cpp
>
> [snip errors]
>
> ############### end of console output
>
> Has Clang PCH support only for C, not for C++? Should I file in a bug
> about that?
Could you test with the latest clang from trunk and if the problem persists file a bug with a preprocessed file ?
-Argiris
More information about the cfe-dev
mailing list