llvm-project/clang/lib/Serialization
Martin Storsjö c843c921a1 [clang] Require strict matches for defines for PCH in GCC style directories
When clang includes a PCH, it tolerates some amount of differences
between the defines used when creating and when including the PCH
- this seems to be intentionally allowed in
c379c07240 (and later extended in
b636875196).

When using a PCH (or when picking a PCH out of a directory containing
multiple candidates) Clang used to accept the header if there were
defines on the command line when creating the PCH that are missing
when using the PCH, or vice versa, defines only set when using the
PCH.

The only cases where Clang explicitly rejected the use of a PCH
is if there was an explicit conflict between the options, e.g.
-DFOO=1 vs -DFOO=2, or -DFOO vs -UFOO.

The latter commit added a FIXME that we really should check whether
mismatched defines actually were used somewhere in the PCH, so that
the define would affect the outcome. This FIXME has stood unaddressed
since 2012.

This differs from GCC, which rejects PCH files if the defines differ
at all.

When explicitly including a single PCH file, the relaxed policy
of allowing minor differences is harmless for correct use cases
(but may fail to diagnose mismtaches), and potentially allow using
PCHs in wider cases (where the user intentionally know that the
differences in defines are harmless for the PCH).

However, for GCC style PCH directories, with a directory containing
multiple PCH variants and the compiler should pick the correct match
out of them, Clang's relaxed logic was problematic. The directory
could contain two otherwise identical PCHs, but one built with -DFOO
and one without. When attempting to include a PCH and iterating over
the candidates in the directory, Clang would essentially pick the
first one out of the two, even if there existed a better, exact
match in the directory.

Keep the relaxed checking when specificlly including one named
PCH file, but require strict matches when trying to pick the right
candidate out of a GCC style directory with alternatives.

This fixes https://github.com/lhmouse/mcfgthread/issues/63.

Differential Revision: https://reviews.llvm.org/D126676
2022-08-10 22:47:27 +03:00
..
ASTCommon.cpp [modules] Merge ObjC interface ivars with anonymous types. 2022-04-04 18:48:30 -07:00
ASTCommon.h
ASTReader.cpp [clang] Require strict matches for defines for PCH in GCC style directories 2022-08-10 22:47:27 +03:00
ASTReaderDecl.cpp [C++20] [Modules] Disable preferred_name when writing a C++20 Module interface 2022-07-26 23:58:07 +08:00
ASTReaderInternals.h [clang] Remove unused forward declarations (NFC) 2022-01-08 11:56:40 -08:00
ASTReaderStmt.cpp [FPEnv] Allow CompoundStmt to keep FP options 2022-07-03 17:06:26 +07:00
ASTWriter.cpp [Serialization] Remove `ORIGINAL_PCH_DIR` record 2022-08-05 15:40:33 -07:00
ASTWriterDecl.cpp [NFC] Start saving InstantiatedFromDecl in non-template functions 2022-07-22 12:37:14 -07:00
ASTWriterStmt.cpp [FPEnv] Allow CompoundStmt to keep FP options 2022-07-03 17:06:26 +07:00
CMakeLists.txt
GeneratePCH.cpp [Serialization] Remove `ORIGINAL_PCH_DIR` record 2022-08-05 15:40:33 -07:00
GlobalModuleIndex.cpp [Clang] Use std::move in GlobalModuleIndex::readIndex. NFC 2022-04-26 16:45:01 +08:00
InMemoryModuleCache.cpp
ModuleFile.cpp
ModuleFileExtension.cpp [modules] Use `HashBuilder` and `MD5` for the module hash. 2021-09-03 11:13:36 -07:00
ModuleManager.cpp unique_ptrify the ModuleManager's VisitState linked list 2022-01-19 09:57:46 -08:00
MultiOnDiskHashTable.h
PCHContainerOperations.cpp