Hi folks! I'm currently investigating macros loading process during PCH and modules loading.
And I would say that it's a bit tricky. First thing weird thing is how clang deals with predefined macros. It creates them as regular (non built-in) ones. Below are A+B+C which currently stay still, but perhaps may produce some issues in future.
A. InitializePredefinedMacros is called during preprocessor initialization which comes earlier then any ASTReader stuff.
B. Such macros are to be written by ASTWriter, so the *will* go into .pch
C. Such macros will be loaded by ASTReader and in some sort overwrite their twins created during phase A.
And here comes question. Is it really necessary? During init stage we create macro, then we load same from .pch, and then technically we even can write same into new .pch? I probably miss something. Why not to treat with such macros just like with built-ins?
And D. When we read modules, we somehow boil out, thanks to those lines:
// Don't read the directive history for a module; we don't have anywhere
// to put it.
So far all of this works. But it looks like it's a bit misdesigned. Did I guys miss something perhaps?