Serialization: Simulate -Werror settings in implicit modules
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 12 Apr 2017 03:58:58 +0000 (03:58 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 12 Apr 2017 03:58:58 +0000 (03:58 +0000)
commit900f817591d0f6871b324aef655cbda926d26052
treeab7f49a6b2f01e9d7a5c2ee8d38f105c3a0450fa
parenta351c10df3b843acaa2ecb48a1bdb61afd10ff01
Serialization: Simulate -Werror settings in implicit modules

r293123 started serializing diagnostic pragma state for modules.  This
makes the serialization work properly for implicit modules.

An implicit module build (using Clang's internal build system) uses the
same PCM file location for different `-Werror` levels.

E.g., if a TU has `-Werror=format` and tries to load a PCM built without
`-Werror=format`, a new PCM will be built in its place (and the new PCM
should have the same signature, since r297655).  In the other direction,
if a TU does not have `-Werror=format` and tries to load a PCM built
with `-Werror=format`, it should "just work".

The idea is to evolve the PCM toward the strictest -Werror flags that
anyone tries.

r293123 started serializing the diagnostic pragma state for each PCM.
Since this encodes the -Werror settings at module-build time, it breaks
the implicit build model.

This commit filters the diagnostic state in order to simulate the
current compilation's diagnostic settings.  Firstly, it ignores the
module's serialized first diagnostic state, replacing it with the state
from this compilation's command-line.  Secondly, if a pragma warning was
upgraded to error/fatal when generating the PCM (e.g., due to `-Werror`
on the command-line), it checks whether it should still be upgraded in
its current context.

llvm-svn: 300025
clang/include/clang/Basic/Diagnostic.h
clang/include/clang/Basic/DiagnosticIDs.h
clang/lib/Basic/Diagnostic.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/Modules/Inputs/implicit-built-Werror-using-W/convert.h [new file with mode: 0644]
clang/test/Modules/Inputs/implicit-built-Werror-using-W/module.modulemap [new file with mode: 0644]
clang/test/Modules/implicit-built-Werror-using-W.cpp [new file with mode: 0644]