diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-01-16 16:19:38 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-01-16 16:19:38 +0000 |
commit | f40f67af436c33a0c76ead87d23f77d186abd8e4 (patch) | |
tree | a62048082072c03f59205860a5363b72b4fbd9fa /clang/lib/Serialization/ASTReader.cpp | |
parent | a1dc93a5bd96017b060d1b138443135ff8231a44 (diff) | |
download | bcm5719-llvm-f40f67af436c33a0c76ead87d23f77d186abd8e4.tar.gz bcm5719-llvm-f40f67af436c33a0c76ead87d23f77d186abd8e4.zip |
[PCH/Modules] Change how macro [re]definitions are de/serialized.
Previously we would serialize the macro redefinitions as a list, part of
the identifier, and try to chain them together across modules individually
without having the info that they were already chained at definition time.
Change this by serializing the macro redefinition chain and then try
to synthesize the chain parts across modules. This allows us to correctly
pinpoint when 2 different definitions are ambiguous because they came from
unrelated modules.
Fixes bogus "ambiguous expansion of macro" warning when a macro in a PCH
is redefined without undef'ing it first.
rdar://13016031
llvm-svn: 172620
Diffstat (limited to 'clang/lib/Serialization/ASTReader.cpp')
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 59 |
1 files changed, 19 insertions, 40 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 81d3cea7ba7..5b1c5cd6e53 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -525,13 +525,9 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, // If this identifier is a macro, deserialize the macro // definition. if (hadMacroDefinition) { - SmallVector<MacroID, 4> MacroIDs; - while (uint32_t LocalID = ReadUnalignedLE32(d)) { - MacroIDs.push_back(Reader.getGlobalMacroID(F, LocalID)); - DataLen -= 4; - } DataLen -= 4; - Reader.setIdentifierIsMacro(II, MacroIDs); + uint32_t LocalID = ReadUnalignedLE32(d); + Reader.addMacroIDForDeserialization(II, Reader.getGlobalMacroID(F,LocalID)); } Reader.SetIdentifierInfo(ID, II); @@ -1061,8 +1057,7 @@ bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, } } -void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset, - MacroInfo *Hint) { +void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) { llvm::BitstreamCursor &Stream = F.MacroCursor; // Keep track of where we are in the stream, then jump back there @@ -1074,24 +1069,6 @@ void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset, SmallVector<IdentifierInfo*, 16> MacroArgs; MacroInfo *Macro = 0; - // RAII object to add the loaded macro information once we're done - // adding tokens. - struct AddLoadedMacroInfoRAII { - Preprocessor &PP; - MacroInfo *Hint; - MacroInfo *MI; - IdentifierInfo *II; - - AddLoadedMacroInfoRAII(Preprocessor &PP, MacroInfo *Hint) - : PP(PP), Hint(Hint), MI(), II() { } - ~AddLoadedMacroInfoRAII( ) { - if (MI) { - // Finally, install the macro. - PP.addLoadedMacroInfo(II, MI, Hint); - } - } - } AddLoadedMacroInfo(PP, Hint); - while (true) { unsigned Code = Stream.ReadCode(); switch (Code) { @@ -1146,6 +1123,8 @@ void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset, SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex); MacroInfo *MI = PP.AllocateMacroInfo(Loc); MI->setDefinitionEndLoc(ReadSourceLocation(F, Record, NextIndex)); + MacroInfo *PrevMI = getMacro(getGlobalMacroID(F, Record[NextIndex++])); + MI->setPreviousDefinition(PrevMI); // Record this macro. MacrosLoaded[GlobalID - NUM_PREDEF_MACRO_IDS] = MI; @@ -1230,10 +1209,6 @@ void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset, } MI->setHidden(Hidden); - // Make sure we install the macro once we're done. - AddLoadedMacroInfo.MI = MI; - AddLoadedMacroInfo.II = II; - // Remember that we saw this macro last so that we add the tokens that // form its body to it. Macro = MI; @@ -1341,10 +1316,13 @@ HeaderFileInfoTrait::ReadData(const internal_key_type, const unsigned char *d, return HFI; } -void ASTReader::setIdentifierIsMacro(IdentifierInfo *II, ArrayRef<MacroID> IDs){ +void ASTReader::addMacroIDForDeserialization(IdentifierInfo *II, MacroID ID){ II->setHadMacroDefinition(true); assert(NumCurrentElementsDeserializing > 0 &&"Missing deserialization guard"); - PendingMacroIDs[II].append(IDs.begin(), IDs.end()); + SmallVector<serialization::MacroID, 2> &MacroIDs = PendingMacroIDs[II]; + assert(std::find(MacroIDs.begin(), MacroIDs.end(), ID) == MacroIDs.end() && + "Already added the macro ID for deserialization"); + MacroIDs.push_back(ID); } void ASTReader::ReadDefinedMacros() { @@ -6158,7 +6136,7 @@ IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) { return LocalID + I->second; } -MacroInfo *ASTReader::getMacro(MacroID ID, MacroInfo *Hint) { +MacroInfo *ASTReader::getMacro(MacroID ID) { if (ID == 0) return 0; @@ -6174,7 +6152,7 @@ MacroInfo *ASTReader::getMacro(MacroID ID, MacroInfo *Hint) { assert(I != GlobalMacroMap.end() && "Corrupted global macro map"); ModuleFile *M = I->second; unsigned Index = ID - M->BaseMacroID; - ReadMacroRecord(*M, M->MacroOffsets[Index], Hint); + ReadMacroRecord(*M, M->MacroOffsets[Index]); } return MacrosLoaded[ID]; @@ -6873,13 +6851,14 @@ void ASTReader::finishPendingActions() { PendingDeclChains.clear(); // Load any pending macro definitions. + // Note that new macros may be added while deserializing a macro. for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) { - // FIXME: std::move here - SmallVector<MacroID, 2> GlobalIDs = PendingMacroIDs.begin()[I].second; - MacroInfo *Hint = 0; - for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs; - ++IDIdx) { - Hint = getMacro(GlobalIDs[IDIdx], Hint); + PendingMacroIDsMap::iterator PMIt = PendingMacroIDs.begin() + I; + SmallVector<serialization::MacroID, 2> &MacroIDs = PMIt->second; + for (SmallVectorImpl<serialization::MacroID>::iterator + MIt = MacroIDs.begin(), ME = MacroIDs.end(); MIt != ME; ++MIt) { + MacroInfo *MI = getMacro(*MIt); + PP.addLoadedMacroInfo(PMIt->first, MI); } } PendingMacroIDs.clear(); |