[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

Kim Gräsman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 17 12:05:40 PDT 2018


kimgr added a comment.



>> Can you test what happens when you do clang-cl.exe /Yc stdafx.h /Tp stdafx.h, i.e. compile the header
>  > directly as C++ code and generate .pch from it? The normal MSVC modus operandi is to have stdafx.h
>  > included in all source files (with /Yu) and stdafx.cpp to generate it (with /Yc). That stdafx.cpp file serves
>  > no purpose, so I've played this trick to generate PCH from the header directly. If it works, it might also
>  > be useful for your tests.
> 
> It isn't always the case that the .cpp file serves no purpose. It's true that the MS project generators give you this setup but we've seen many projects over the years that use a regular source file with code in it to generate the PCH. The > object file generated during PCH create can have real code and the compiler can take advantage of that fact by compiling less code in the compilation units that use the PCH [...]

Cool, it's never occurred to me that the source file has any other purpose than including the pch header.

> I am not sure about your command: clang-cl.exe /Yc stdafx.h /Tp stdafx.h. The space makes this a compile with just
>  /Yc (no through header). This patch doesn't address /Yc without the through header. Something like clang-cl /Yc 
> /Tpstdafx.h would probably work if/when that is implemented.

I no longer have access to an MSVC environment, so I can't spell out the exact command, but I was trying to phrase a command that generates a PCH from the through-header *without a distinct source file*. It's proved to be a useful trick. I didn't mean to omit the through header, let's try again:

  cl.exe /Ycstdafx.h /TP stdafx.h

or if that doesn't work, a /FI switch may be required, I can't remember for sure what we did:

  cl.exe /Ycstdafx.h /TP /FI stdafx.h stdafx.h

>> I think the current skip-warning is over-specific -- what if I put an inline function before my PCH include?
>  >  A global variable? A #pragma? Or am I misunderstanding what skipping does? It seems to me that any
>  > non-comment tokens before the PCH #include should raise a warning.
> 
> Not any tokens. The through header "feature" compiles all the code in the file up to the through header.
>  So normally you are used to seeing just comments and #include <stdafx.h>. That's one usage but your
>  PCH can be created from a source like this [...]

Thanks for the example, I must have misunderstood how MSVC PCHs work. With that background, the warning seems fine.

>> I find the "through header" terminology is a little hard to interpret, but I did find it on MSDN, so maybe it's well established.
> 
> Sorry about the terminology. I've been responsible for emulating this PCH mechanism for many years so I may be one
>  of the few that understands it. I did try to keep that terminology out of the diagnostics but I don't really have a better
>  name for through header.

:) Sounds like it's well-established!


https://reviews.llvm.org/D46652





More information about the cfe-commits mailing list