aboutsummaryrefslogtreecommitdiff
path: root/lib/Serialization
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-03-15 22:43:10 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-03-15 22:43:10 +0000
commit9cc3ed4e4d7f25b1af8ba7b85d324a0bb8747640 (patch)
tree0269d3ce8cd783a17b41a70cafb81da15aef57cd /lib/Serialization
parent4a18c3b25a2d7eb7f770ce91ee5e14433b2a1cb6 (diff)
[modules] Don't record the macros from the predefines buffer.
These will be available in the current translation unit anyway, for modules they only waste space and deserialization time. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177197 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization')
-rw-r--r--lib/Serialization/ASTWriter.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp
index b113c76f44..716b1fbb30 100644
--- a/lib/Serialization/ASTWriter.cpp
+++ b/lib/Serialization/ASTWriter.cpp
@@ -1793,6 +1793,22 @@ static int compareMacroDefinitions(const void *XPtr, const void *YPtr) {
return X.first->getName().compare(Y.first->getName());
}
+static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule,
+ const Preprocessor &PP) {
+ if (MD->getInfo()->isBuiltinMacro())
+ return true;
+
+ if (IsModule) {
+ SourceLocation Loc = MD->getLocation();
+ if (Loc.isInvalid())
+ return true;
+ if (PP.getSourceManager().getFileID(Loc) == PP.getPredefinesFileID())
+ return true;
+ }
+
+ return false;
+}
+
/// \brief Writes the block containing the serialized form of the
/// preprocessor.
///
@@ -1851,6 +1867,9 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
for (MacroDirective *MD = MacrosToEmit[I].second; MD;
MD = MD->getPrevious()) {
+ if (shouldIgnoreMacro(MD, IsModule, PP))
+ continue;
+
MacroID ID = getMacroRef(MD);
if (!ID)
continue;
@@ -2749,7 +2768,7 @@ class ASTIdentifierTableTrait {
return false;
if (Macro || (Macro = PP.getMacroDirectiveHistory(II)))
- return !Macro->getInfo()->isBuiltinMacro() &&
+ return !shouldIgnoreMacro(Macro, IsModule, PP) &&
(!IsModule || Macro->isPublic());
return false;
@@ -2780,6 +2799,8 @@ public:
DataLen += 2; // 2 bytes for flags
if (hadMacroDefinition(II, Macro)) {
for (MacroDirective *M = Macro; M; M = M->getPrevious()) {
+ if (shouldIgnoreMacro(M, IsModule, PP))
+ continue;
if (Writer.getMacroRef(M) != 0)
DataLen += 4;
}
@@ -2832,6 +2853,8 @@ public:
if (HadMacroDefinition) {
// Write all of the macro IDs associated with this identifier.
for (MacroDirective *M = Macro; M; M = M->getPrevious()) {
+ if (shouldIgnoreMacro(M, IsModule, PP))
+ continue;
if (MacroID ID = Writer.getMacroRef(M))
clang::io::Emit32(Out, ID);
}