[llvm-branch-commits] [cfe-branch] r115431 - in /cfe/branches/Apple/whitney: include/clang/Serialization/ASTDeserializationListener.h include/clang/Serialization/ASTReader.h include/clang/Serialization/ASTWriter.h lib/Serialization/ASTReader.cpp lib/Serialization/ASTWriter.cpp test/PCH/chain-macro-override.c test/PCH/chain-macro.c
Daniel Dunbar
daniel at zuster.org
Sat Oct 2 16:23:44 PDT 2010
Author: ddunbar
Date: Sat Oct 2 18:23:44 2010
New Revision: 115431
URL: http://llvm.org/viewvc/llvm-project?rev=115431&view=rev
Log:
Merge r115417:
--
Author: Douglas Gregor <dgregor at apple.com>
Date: Sat Oct 2 19:29:26 2010 +0000
Implement chained PCH support for the macro definitions stored within
the "detailed" preprocessing record.
Modified:
cfe/branches/Apple/whitney/include/clang/Serialization/ASTDeserializationListener.h
cfe/branches/Apple/whitney/include/clang/Serialization/ASTReader.h
cfe/branches/Apple/whitney/include/clang/Serialization/ASTWriter.h
cfe/branches/Apple/whitney/lib/Serialization/ASTReader.cpp
cfe/branches/Apple/whitney/lib/Serialization/ASTWriter.cpp
cfe/branches/Apple/whitney/test/PCH/chain-macro-override.c
cfe/branches/Apple/whitney/test/PCH/chain-macro.c
Modified: cfe/branches/Apple/whitney/include/clang/Serialization/ASTDeserializationListener.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/include/clang/Serialization/ASTDeserializationListener.h?rev=115431&r1=115430&r2=115431&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/include/clang/Serialization/ASTDeserializationListener.h (original)
+++ cfe/branches/Apple/whitney/include/clang/Serialization/ASTDeserializationListener.h Sat Oct 2 18:23:44 2010
@@ -22,7 +22,8 @@
class Decl;
class ASTReader;
class QualType;
-
+class MacroDefinition;
+
class ASTDeserializationListener {
protected:
virtual ~ASTDeserializationListener() {}
@@ -42,6 +43,9 @@
virtual void DeclRead(serialization::DeclID ID, const Decl *D) = 0;
/// \brief A selector was read from the AST file.
virtual void SelectorRead(serialization::SelectorID iD, Selector Sel) = 0;
+ /// \brief A macro definition was read from the AST file.
+ virtual void MacroDefinitionRead(serialization::MacroID,
+ MacroDefinition *MD) = 0;
};
}
Modified: cfe/branches/Apple/whitney/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/include/clang/Serialization/ASTReader.h?rev=115431&r1=115430&r2=115431&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/include/clang/Serialization/ASTReader.h (original)
+++ cfe/branches/Apple/whitney/include/clang/Serialization/ASTReader.h Sat Oct 2 18:23:44 2010
@@ -816,6 +816,11 @@
return static_cast<unsigned>(SelectorsLoaded.size());
}
+ /// \brief Returns the number of macro definitions found in the chain.
+ unsigned getTotalNumMacroDefinitions() const {
+ return static_cast<unsigned>(MacroDefinitionsLoaded.size());
+ }
+
/// \brief Reads a TemplateArgumentLocInfo appropriate for the
/// given TemplateArgument kind.
TemplateArgumentLocInfo
Modified: cfe/branches/Apple/whitney/include/clang/Serialization/ASTWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/include/clang/Serialization/ASTWriter.h?rev=115431&r1=115430&r2=115431&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/branches/Apple/whitney/include/clang/Serialization/ASTWriter.h Sat Oct 2 18:23:44 2010
@@ -163,7 +163,7 @@
/// \brief Offset of each selector within the method pool/selector
/// table, indexed by the Selector ID (-1).
std::vector<uint32_t> SelectorOffsets;
-
+
/// \brief Offsets of each of the macro identifiers into the
/// bitstream.
///
@@ -172,6 +172,12 @@
/// defined.
llvm::DenseMap<const IdentifierInfo *, uint64_t> MacroOffsets;
+ /// \brief The first ID number we can use for our own macro definitions.
+ serialization::MacroID FirstMacroID;
+
+ /// \brief The decl ID that will be assigned to the next new macro definition.
+ serialization::MacroID NextMacroID;
+
/// \brief Mapping from macro definitions (as they occur in the preprocessing
/// record) to the macro IDs.
llvm::DenseMap<const MacroDefinition *, serialization::MacroID>
@@ -481,7 +487,8 @@
void IdentifierRead(serialization::IdentID ID, IdentifierInfo *II);
void TypeRead(serialization::TypeIdx Idx, QualType T);
void DeclRead(serialization::DeclID ID, const Decl *D);
- void SelectorRead(serialization::SelectorID iD, Selector Sel);
+ void SelectorRead(serialization::SelectorID ID, Selector Sel);
+ void MacroDefinitionRead(serialization::MacroID ID, MacroDefinition *MD);
};
/// \brief AST and semantic-analysis consumer that generates a
Modified: cfe/branches/Apple/whitney/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Serialization/ASTReader.cpp?rev=115431&r1=115430&r2=115431&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Serialization/ASTReader.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Serialization/ASTReader.cpp Sat Oct 2 18:23:44 2010
@@ -1459,19 +1459,29 @@
if (PPRec.getPreprocessedEntity(Record[0]))
return;
- if (Record[1] >= MacroDefinitionsLoaded.size()) {
+ if (Record[1] > MacroDefinitionsLoaded.size()) {
Error("out-of-bounds macro definition record");
return;
}
- MacroDefinition *MD
- = new (PPRec) MacroDefinition(DecodeIdentifierInfo(Record[4]),
+ // Decode the identifier info and then check again; if the macro is
+ // still defined and associated with the identifier,
+ IdentifierInfo *II = DecodeIdentifierInfo(Record[4]);
+ if (!MacroDefinitionsLoaded[Record[1] - 1]) {
+ MacroDefinition *MD
+ = new (PPRec) MacroDefinition(II,
SourceLocation::getFromRawEncoding(Record[5]),
SourceRange(
SourceLocation::getFromRawEncoding(Record[2]),
SourceLocation::getFromRawEncoding(Record[3])));
- PPRec.SetPreallocatedEntity(Record[0], MD);
- MacroDefinitionsLoaded[Record[1]] = MD;
+
+ PPRec.SetPreallocatedEntity(Record[0], MD);
+ MacroDefinitionsLoaded[Record[1] - 1] = MD;
+
+ if (DeserializationListener)
+ DeserializationListener->MacroDefinitionRead(Record[1], MD);
+ }
+
return;
}
}
@@ -1548,23 +1558,23 @@
}
MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) {
- if (ID == 0 || ID >= MacroDefinitionsLoaded.size())
+ if (ID == 0 || ID > MacroDefinitionsLoaded.size())
return 0;
- if (!MacroDefinitionsLoaded[ID]) {
- unsigned Index = ID;
+ if (!MacroDefinitionsLoaded[ID - 1]) {
+ unsigned Index = ID - 1;
for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
PerFileData &F = *Chain[N - I - 1];
if (Index < F.LocalNumMacroDefinitions) {
- ReadMacroRecord(F.Stream, F.MacroDefinitionOffsets[Index]);
+ ReadMacroRecord(F.Stream, F.MacroDefinitionOffsets[Index]);
break;
}
Index -= F.LocalNumMacroDefinitions;
}
- assert(MacroDefinitionsLoaded[ID] && "Broken chain");
+ assert(MacroDefinitionsLoaded[ID - 1] && "Broken chain");
}
- return MacroDefinitionsLoaded[ID];
+ return MacroDefinitionsLoaded[ID - 1];
}
/// \brief If we are loading a relocatable PCH file, and the filename is
Modified: cfe/branches/Apple/whitney/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Serialization/ASTWriter.cpp?rev=115431&r1=115430&r2=115431&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Serialization/ASTWriter.cpp Sat Oct 2 18:23:44 2010
@@ -1359,11 +1359,17 @@
if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) {
// Record this macro definition's location.
MacroID ID = getMacroDefinitionID(MD);
- if (ID != MacroDefinitionOffsets.size()) {
- if (ID > MacroDefinitionOffsets.size())
- MacroDefinitionOffsets.resize(ID + 1);
+
+ // Don't write the macro definition if it is from another AST file.
+ if (ID < FirstMacroID)
+ continue;
+
+ unsigned Position = ID - FirstMacroID;
+ if (Position != MacroDefinitionOffsets.size()) {
+ if (Position > MacroDefinitionOffsets.size())
+ MacroDefinitionOffsets.resize(Position + 1);
- MacroDefinitionOffsets[ID] = Stream.GetCurrentBitNo();
+ MacroDefinitionOffsets[Position] = Stream.GetCurrentBitNo();
} else
MacroDefinitionOffsets.push_back(Stream.GetCurrentBitNo());
@@ -2205,7 +2211,8 @@
: Stream(Stream), Chain(0), FirstDeclID(1), NextDeclID(FirstDeclID),
FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID),
FirstIdentID(1), NextIdentID(FirstIdentID), FirstSelectorID(1),
- NextSelectorID(FirstSelectorID), CollectedStmts(&StmtsToEmit),
+ NextSelectorID(FirstSelectorID), FirstMacroID(1), NextMacroID(FirstMacroID),
+ CollectedStmts(&StmtsToEmit),
NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0),
NumVisibleDeclContexts(0) {
}
@@ -2438,10 +2445,12 @@
FirstTypeID += Chain->getTotalNumTypes();
FirstIdentID += Chain->getTotalNumIdentifiers();
FirstSelectorID += Chain->getTotalNumSelectors();
+ FirstMacroID += Chain->getTotalNumMacroDefinitions();
NextDeclID = FirstDeclID;
NextTypeID = FirstTypeID;
NextIdentID = FirstIdentID;
NextSelectorID = FirstSelectorID;
+ NextMacroID = FirstMacroID;
ASTContext &Context = SemaRef.Context;
Preprocessor &PP = SemaRef.PP;
@@ -2732,7 +2741,7 @@
MacroID &ID = MacroDefinitions[MD];
if (ID == 0)
- ID = MacroDefinitions.size();
+ ID = NextMacroID++;
return ID;
}
@@ -3105,6 +3114,7 @@
FirstTypeID == NextTypeID &&
FirstIdentID == NextIdentID &&
FirstSelectorID == NextSelectorID &&
+ FirstMacroID == NextMacroID &&
"Setting chain after writing has started.");
Chain = Reader;
}
@@ -3124,3 +3134,8 @@
void ASTWriter::SelectorRead(SelectorID ID, Selector S) {
SelectorIDs[S] = ID;
}
+
+void ASTWriter::MacroDefinitionRead(serialization::MacroID ID,
+ MacroDefinition *MD) {
+ MacroDefinitions[MD] = ID;
+}
Modified: cfe/branches/Apple/whitney/test/PCH/chain-macro-override.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/PCH/chain-macro-override.c?rev=115431&r1=115430&r2=115431&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/PCH/chain-macro-override.c (original)
+++ cfe/branches/Apple/whitney/test/PCH/chain-macro-override.c Sat Oct 2 18:23:44 2010
@@ -1,9 +1,9 @@
// Test this without pch.
-// RUN: %clang_cc1 -include %S/Inputs/chain-macro-override1.h -include %S/Inputs/chain-macro-override2.h -fsyntax-only -verify %s
+// RUN: %clang_cc1 -include %S/Inputs/chain-macro-override1.h -include %S/Inputs/chain-macro-override2.h -fsyntax-only -verify -detailed-preprocessing-record %s
// Test with pch.
-// RUN: %clang_cc1 -emit-pch -o %t1 %S/Inputs/chain-macro-override1.h
-// RUN: %clang_cc1 -emit-pch -o %t2 %S/Inputs/chain-macro-override2.h -include-pch %t1 -chained-pch
+// RUN: %clang_cc1 -emit-pch -o %t1 %S/Inputs/chain-macro-override1.h -detailed-preprocessing-record
+// RUN: %clang_cc1 -emit-pch -o %t2 %S/Inputs/chain-macro-override2.h -include-pch %t1 -chained-pch -detailed-preprocessing-record
// RUN: %clang_cc1 -include-pch %t2 -fsyntax-only -verify %s
int foo() {
Modified: cfe/branches/Apple/whitney/test/PCH/chain-macro.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/PCH/chain-macro.c?rev=115431&r1=115430&r2=115431&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/PCH/chain-macro.c (original)
+++ cfe/branches/Apple/whitney/test/PCH/chain-macro.c Sat Oct 2 18:23:44 2010
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -emit-pch -o %t1 %S/Inputs/chain-macro1.h
-// RUN: %clang_cc1 -emit-pch -o %t2 %S/Inputs/chain-macro2.h -include-pch %t1 -chained-pch
+// RUN: %clang_cc1 -emit-pch -o %t1 -detailed-preprocessing-record %S/Inputs/chain-macro1.h
+// RUN: %clang_cc1 -emit-pch -o %t2 -detailed-preprocessing-record %S/Inputs/chain-macro2.h -include-pch %t1 -chained-pch
// RUN: %clang_cc1 -fsyntax-only -verify -include-pch %t2 %s
// RUN: %clang_cc1 -ast-print -include-pch %t2 %s | FileCheck %s
More information about the llvm-branch-commits
mailing list