summaryrefslogtreecommitdiffstats
path: root/clang/lib/Serialization
diff options
context:
space:
mode:
authorManman Ren <manman.ren@gmail.com>2016-05-31 18:19:32 +0000
committerManman Ren <manman.ren@gmail.com>2016-05-31 18:19:32 +0000
commit33d80295891fca25ceca3397a70d423cd03b1337 (patch)
tree38dbc85a63caf13da54df3458e2ada7c57cbbd19 /clang/lib/Serialization
parent3b3f490f9c5706bb4d216068283f78694826100b (diff)
downloadbcm5719-llvm-33d80295891fca25ceca3397a70d423cd03b1337.tar.gz
bcm5719-llvm-33d80295891fca25ceca3397a70d423cd03b1337.zip
PCH + module: make sure we write out macros associated with builtin identifiers.
When we import a module that defines a builtin identifier from prefix header and precompile the prefix header, the macro information related to the identifier is lost. If we don't precompile the prefix header, the source file can still see the macro information. The reason is that we write out the identifier in the pch but not the macro information since the macro is not defined locally. This is related to r251565. In that commit, if we read a builtin identifier from a module that wasn't "interesting" to that module, we will still write it out to a PCH that imports that module. The fix is to write exported module macros for PCH as well. rdar://24666630 Differential Revision: http://reviews.llvm.org/D20383 llvm-svn: 271310
Diffstat (limited to 'clang/lib/Serialization')
-rw-r--r--clang/lib/Serialization/ASTWriter.cpp47
1 files changed, 23 insertions, 24 deletions
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 7540bc03d15..0c9264f4032 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -2187,30 +2187,29 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
// Write out any exported module macros.
bool EmittedModuleMacros = false;
- if (IsModule) {
- auto Leafs = PP.getLeafModuleMacros(Name);
- SmallVector<ModuleMacro*, 8> Worklist(Leafs.begin(), Leafs.end());
- llvm::DenseMap<ModuleMacro*, unsigned> Visits;
- while (!Worklist.empty()) {
- auto *Macro = Worklist.pop_back_val();
-
- // Emit a record indicating this submodule exports this macro.
- ModuleMacroRecord.push_back(
- getSubmoduleID(Macro->getOwningModule()));
- ModuleMacroRecord.push_back(getMacroRef(Macro->getMacroInfo(), Name));
- for (auto *M : Macro->overrides())
- ModuleMacroRecord.push_back(getSubmoduleID(M->getOwningModule()));
-
- Stream.EmitRecord(PP_MODULE_MACRO, ModuleMacroRecord);
- ModuleMacroRecord.clear();
-
- // Enqueue overridden macros once we've visited all their ancestors.
- for (auto *M : Macro->overrides())
- if (++Visits[M] == M->getNumOverridingMacros())
- Worklist.push_back(M);
-
- EmittedModuleMacros = true;
- }
+ // We write out exported module macros for PCH as well.
+ auto Leafs = PP.getLeafModuleMacros(Name);
+ SmallVector<ModuleMacro*, 8> Worklist(Leafs.begin(), Leafs.end());
+ llvm::DenseMap<ModuleMacro*, unsigned> Visits;
+ while (!Worklist.empty()) {
+ auto *Macro = Worklist.pop_back_val();
+
+ // Emit a record indicating this submodule exports this macro.
+ ModuleMacroRecord.push_back(
+ getSubmoduleID(Macro->getOwningModule()));
+ ModuleMacroRecord.push_back(getMacroRef(Macro->getMacroInfo(), Name));
+ for (auto *M : Macro->overrides())
+ ModuleMacroRecord.push_back(getSubmoduleID(M->getOwningModule()));
+
+ Stream.EmitRecord(PP_MODULE_MACRO, ModuleMacroRecord);
+ ModuleMacroRecord.clear();
+
+ // Enqueue overridden macros once we've visited all their ancestors.
+ for (auto *M : Macro->overrides())
+ if (++Visits[M] == M->getNumOverridingMacros())
+ Worklist.push_back(M);
+
+ EmittedModuleMacros = true;
}
if (Record.empty() && !EmittedModuleMacros)
OpenPOWER on IntegriCloud