From: Richard Smith Date: Thu, 23 Apr 2015 20:40:50 +0000 (+0000) Subject: [modules] Store a ModuleMacro* on an imported macro directive rather than duplicating... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=713369b057bc6401e88abbc65cab1fc0a8f688e0;p=platform%2Fupstream%2Fllvm.git [modules] Store a ModuleMacro* on an imported macro directive rather than duplicating the info within it. llvm-svn: 235644 --- diff --git a/clang/include/clang/Lex/MacroInfo.h b/clang/include/clang/Lex/MacroInfo.h index 6d2de9b..12f008a 100644 --- a/clang/include/clang/Lex/MacroInfo.h +++ b/clang/include/clang/Lex/MacroInfo.h @@ -24,6 +24,7 @@ namespace clang { class Module; +class ModuleMacro; class Preprocessor; /// \brief Encapsulates the data about a macro definition (e.g. its tokens). @@ -350,29 +351,20 @@ protected: /// \brief True if this macro was imported from a module. bool IsImported : 1; - /// \brief For an imported directive, the number of modules whose macros are - /// overridden by this directive. Only used if IsImported. - unsigned NumOverrides : 26; - - unsigned *getModuleDataStart(); - const unsigned *getModuleDataStart() const { - return const_cast(this)->getModuleDataStart(); + struct ImportData { + ModuleMacro *ImportedFrom; + }; + ImportData *getImportData(); + const ImportData *getImportData() const { + return const_cast(this)->getImportData(); } MacroDirective(Kind K, SourceLocation Loc, - unsigned ImportedFromModuleID = 0, - ArrayRef Overrides = None) + ModuleMacro *ImportedFrom = nullptr) : Previous(nullptr), Loc(Loc), MDKind(K), IsFromPCH(false), - IsAmbiguous(false), IsPublic(true), IsImported(ImportedFromModuleID), - NumOverrides(Overrides.size()) { - assert(NumOverrides == Overrides.size() && "too many overrides"); - assert((IsImported || !NumOverrides) && "overrides for non-module macro"); - - if (IsImported) { - unsigned *Extra = getModuleDataStart(); - *Extra++ = ImportedFromModuleID; - std::copy(Overrides.begin(), Overrides.end(), Extra); - } + IsAmbiguous(false), IsPublic(true), IsImported(ImportedFrom) { + if (IsImported) + getImportData()->ImportedFrom = ImportedFrom; } public: @@ -400,23 +392,14 @@ public: /// Note that this is never the case for a VisibilityMacroDirective. bool isImported() const { return IsImported; } - /// \brief If this directive was imported from a module, get the submodule - /// whose directive this is. Note that this may be different from the module - /// that owns the MacroInfo for a DefMacroDirective due to #pragma pop_macro - /// and similar effects. - unsigned getOwningModuleID() const { + /// \brief If this directive was imported from a module, get the module + /// macro from which this directive was created. + ModuleMacro *getOwningModuleMacro() const { if (isImported()) - return *getModuleDataStart(); + return getImportData()->ImportedFrom; return 0; } - /// \brief Get the module IDs of modules whose macros are overridden by this - /// directive. Only valid if this is an imported directive. - ArrayRef getOverriddenModules() const { - assert(IsImported && "can only get overridden modules for imported macro"); - return llvm::makeArrayRef(getModuleDataStart() + 1, NumOverrides); - } - class DefInfo { DefMacroDirective *DefDirective; SourceLocation UndefLoc; @@ -488,20 +471,21 @@ public: class DefMacroDirective : public MacroDirective { MacroInfo *Info; -public: - explicit DefMacroDirective(MacroInfo *MI) - : MacroDirective(MD_Define, MI->getDefinitionLoc()), Info(MI) { - assert(MI && "MacroInfo is null"); - } - DefMacroDirective(MacroInfo *MI, SourceLocation Loc, - unsigned ImportedFromModuleID = 0, - ArrayRef Overrides = None) - : MacroDirective(MD_Define, Loc, ImportedFromModuleID, Overrides), - Info(MI) { + ModuleMacro *ImportedFrom) + : MacroDirective(MD_Define, Loc, ImportedFrom), Info(MI) { assert(MI && "MacroInfo is null"); } +public: + DefMacroDirective(MacroInfo *MI, SourceLocation Loc) + : DefMacroDirective(MI, Loc, nullptr) {} + explicit DefMacroDirective(MacroInfo *MI) + : DefMacroDirective(MI, MI->getDefinitionLoc()) {} + static DefMacroDirective *createImported(Preprocessor &PP, MacroInfo *MI, + SourceLocation Loc, + ModuleMacro *ImportedFrom); + /// \brief The data for the macro definition. const MacroInfo *getInfo() const { return Info; } MacroInfo *getInfo() { return Info; } @@ -521,14 +505,19 @@ public: /// \brief A directive for an undefined macro. class UndefMacroDirective : public MacroDirective { -public: - explicit UndefMacroDirective(SourceLocation UndefLoc, - unsigned ImportedFromModuleID = 0, - ArrayRef Overrides = None) - : MacroDirective(MD_Undefine, UndefLoc, ImportedFromModuleID, Overrides) { - assert((UndefLoc.isValid() || ImportedFromModuleID) && "Invalid UndefLoc!"); + UndefMacroDirective(SourceLocation UndefLoc, ModuleMacro *ImportedFrom) + : MacroDirective(MD_Undefine, UndefLoc, ImportedFrom) { + // FIXME: We should have a valid UndefLoc even for an imported macro. + assert((UndefLoc.isValid() || ImportedFrom) && "Invalid UndefLoc!"); } +public: + explicit UndefMacroDirective(SourceLocation UndefLoc) + : UndefMacroDirective(UndefLoc, nullptr) {} + static UndefMacroDirective *createImported(Preprocessor &PP, + SourceLocation UndefLoc, + ModuleMacro *ImportedFrom); + static bool classof(const MacroDirective *MD) { return MD->getKind() == MD_Undefine; } @@ -539,7 +528,7 @@ public: class VisibilityMacroDirective : public MacroDirective { public: explicit VisibilityMacroDirective(SourceLocation Loc, bool Public) - : MacroDirective(MD_Visibility, Loc) { + : MacroDirective(MD_Visibility, Loc) { IsPublic = Public; } @@ -553,11 +542,12 @@ public: static bool classof(const VisibilityMacroDirective *) { return true; } }; -inline unsigned *MacroDirective::getModuleDataStart() { +inline MacroDirective::ImportData *MacroDirective::getImportData() { + assert(IsImported && "only an imported macro has import data"); if (auto *Def = dyn_cast(this)) - return reinterpret_cast(Def + 1); + return reinterpret_cast(Def + 1); else - return reinterpret_cast(cast(this) + 1); + return reinterpret_cast(cast(this) + 1); } inline SourceLocation MacroDirective::DefInfo::getLocation() const { @@ -639,8 +629,8 @@ public: overrides_iterator overrides_end() const { return overrides_begin() + NumOverrides; } - llvm::iterator_range overrides() const { - return llvm::make_range(overrides_begin(), overrides_end()); + ArrayRef overrides() const { + return llvm::makeArrayRef(overrides_begin(), overrides_end()); } /// \} diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index a4fd42b..94c4e24 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -716,15 +716,14 @@ public: void appendMacroDirective(IdentifierInfo *II, MacroDirective *MD); DefMacroDirective *appendDefMacroDirective(IdentifierInfo *II, MacroInfo *MI, SourceLocation Loc, - unsigned ImportedFromModuleID, - ArrayRef Overrides) { - DefMacroDirective *MD = - AllocateDefMacroDirective(MI, Loc, ImportedFromModuleID, Overrides); + ModuleMacro *MM = nullptr) { + DefMacroDirective *MD = AllocateDefMacroDirective(MI, Loc, MM); appendMacroDirective(II, MD); return MD; } - DefMacroDirective *appendDefMacroDirective(IdentifierInfo *II, MacroInfo *MI){ - return appendDefMacroDirective(II, MI, MI->getDefinitionLoc(), 0, None); + DefMacroDirective *appendDefMacroDirective(IdentifierInfo *II, + MacroInfo *MI) { + return appendDefMacroDirective(II, MI, MI->getDefinitionLoc()); } /// \brief Set a MacroDirective that was loaded from a PCH file. void setLoadedMacroDirective(IdentifierInfo *II, MacroDirective *MD); @@ -1509,14 +1508,11 @@ private: /// \brief Allocate a new MacroInfo object. MacroInfo *AllocateMacroInfo(); - DefMacroDirective * - AllocateDefMacroDirective(MacroInfo *MI, SourceLocation Loc, - unsigned ImportedFromModuleID = 0, - ArrayRef Overrides = None); - UndefMacroDirective * - AllocateUndefMacroDirective(SourceLocation UndefLoc, - unsigned ImportedFromModuleID = 0, - ArrayRef Overrides = None); + DefMacroDirective *AllocateDefMacroDirective(MacroInfo *MI, + SourceLocation Loc, + ModuleMacro *MM = nullptr); + UndefMacroDirective *AllocateUndefMacroDirective(SourceLocation UndefLoc, + ModuleMacro *MM = nullptr); VisibilityMacroDirective *AllocateVisibilityMacroDirective(SourceLocation Loc, bool isPublic); diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h index 330fc5b..2748b83 100644 --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -73,6 +73,7 @@ class GlobalModuleIndex; class GotoStmt; class MacroDefinition; class MacroDirective; +class ModuleMacro; class NamedDecl; class OpaqueValueExpr; class Preprocessor; @@ -1856,14 +1857,13 @@ public: typedef llvm::TinyPtrVector AmbiguousMacros; llvm::DenseMap AmbiguousMacroDefs; - void - removeOverriddenMacros(IdentifierInfo *II, SourceLocation Loc, - AmbiguousMacros &Ambig, - ArrayRef Overrides); + void removeOverriddenMacros(IdentifierInfo *II, SourceLocation Loc, + AmbiguousMacros &Ambig, + ArrayRef Overrides); - AmbiguousMacros * - removeOverriddenMacros(IdentifierInfo *II, SourceLocation Loc, - ArrayRef Overrides); + AmbiguousMacros *removeOverriddenMacros(IdentifierInfo *II, + SourceLocation Loc, + ArrayRef Overrides); /// \brief Retrieve the macro with the given ID. MacroInfo *getMacro(serialization::MacroID ID); diff --git a/clang/lib/Lex/MacroInfo.cpp b/clang/lib/Lex/MacroInfo.cpp index d7f4831..dbc8044 100644 --- a/clang/lib/Lex/MacroInfo.cpp +++ b/clang/lib/Lex/MacroInfo.cpp @@ -235,6 +235,25 @@ void MacroDirective::dump() const { Out << "\n"; } +DefMacroDirective * +DefMacroDirective::createImported(Preprocessor &PP, MacroInfo *MI, + SourceLocation Loc, + ModuleMacro *ImportedFrom) { + void *Mem = PP.getPreprocessorAllocator().Allocate( + sizeof(DefMacroDirective) + sizeof(MacroDirective::ImportData), + llvm::alignOf()); + return new (Mem) DefMacroDirective(MI, Loc, ImportedFrom); +} + +UndefMacroDirective * +UndefMacroDirective::createImported(Preprocessor &PP, SourceLocation Loc, + ModuleMacro *ImportedFrom) { + void *Mem = PP.getPreprocessorAllocator().Allocate( + sizeof(UndefMacroDirective) + sizeof(MacroDirective::ImportData), + llvm::alignOf()); + return new (Mem) UndefMacroDirective(Loc, ImportedFrom); +} + ModuleMacro *ModuleMacro::create(Preprocessor &PP, Module *OwningModule, IdentifierInfo *II, MacroInfo *Macro, ArrayRef Overrides) { diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index c22b059..4f3efa5 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -64,24 +64,16 @@ MacroInfo *Preprocessor::AllocateDeserializedMacroInfo(SourceLocation L, DefMacroDirective * Preprocessor::AllocateDefMacroDirective(MacroInfo *MI, SourceLocation Loc, - unsigned ImportedFromModuleID, - ArrayRef Overrides) { - unsigned NumExtra = (ImportedFromModuleID ? 1 : 0) + Overrides.size(); - return new (BP.Allocate(sizeof(DefMacroDirective) + - sizeof(unsigned) * NumExtra, - llvm::alignOf())) - DefMacroDirective(MI, Loc, ImportedFromModuleID, Overrides); + ModuleMacro *MM) { + if (MM) return DefMacroDirective::createImported(*this, MI, Loc, MM); + return new (BP) DefMacroDirective(MI, Loc); } UndefMacroDirective * Preprocessor::AllocateUndefMacroDirective(SourceLocation UndefLoc, - unsigned ImportedFromModuleID, - ArrayRef Overrides) { - unsigned NumExtra = (ImportedFromModuleID ? 1 : 0) + Overrides.size(); - return new (BP.Allocate(sizeof(UndefMacroDirective) + - sizeof(unsigned) * NumExtra, - llvm::alignOf())) - UndefMacroDirective(UndefLoc, ImportedFromModuleID, Overrides); + ModuleMacro *MM) { + if (MM) return UndefMacroDirective::createImported(*this, UndefLoc, MM); + return new (BP) UndefMacroDirective(UndefLoc); } VisibilityMacroDirective * diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index 883f2d5..54f72f6 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -65,21 +65,18 @@ void Preprocessor::appendMacroDirective(IdentifierInfo *II, MacroDirective *MD){ return; for (auto *PrevMD = OldMD; PrevMD; PrevMD = PrevMD->getPrevious()) { - // FIXME: Store a ModuleMacro * on an imported directive. Module *DirectiveMod = getModuleForLocation(PrevMD->getLocation()); - Module *PrevOwningMod = - PrevMD->isImported() - ? getExternalSource()->getModule(PrevMD->getOwningModuleID()) - : DirectiveMod; - auto *MM = getModuleMacro(PrevOwningMod, II); - if (!MM) { + if (ModuleMacro *PrevMM = PrevMD->getOwningModuleMacro()) + StoredMD.addOverriddenMacro(*this, PrevMM); + else if (ModuleMacro *PrevMM = getModuleMacro(DirectiveMod, II)) + // The previous macro was from another submodule that we #included. + // FIXME: Create an import directive when importing a macro from a local + // submodule. + StoredMD.addOverriddenMacro(*this, PrevMM); + else // We're still within the module defining the previous macro. We don't // override it. - assert(!PrevMD->isImported() && - "imported macro with no corresponding ModuleMacro"); break; - } - StoredMD.addOverriddenMacro(*this, MM); // Stop once we leave the original macro's submodule. // diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index bfac3fd..5625842 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -600,11 +600,9 @@ void Preprocessor::HandlePragmaPopMacro(Token &PopMacroTok) { // Get the MacroInfo we want to reinstall. MacroInfo *MacroToReInstall = iter->second.back(); - if (MacroToReInstall) { + if (MacroToReInstall) // Reinstall the previously pushed macro. - appendDefMacroDirective(IdentInfo, MacroToReInstall, MessageLoc, - /*isImported=*/false, /*Overrides*/None); - } + appendDefMacroDirective(IdentInfo, MacroToReInstall, MessageLoc); // Pop PragmaPushMacroInfo stack. iter->second.pop_back(); diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 8b91832..62fefed 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -1724,24 +1724,20 @@ void ASTReader::markIdentifierUpToDate(IdentifierInfo *II) { } struct ASTReader::ModuleMacroInfo { - SubmoduleID SubModID; - MacroInfo *MI; - ArrayRef Overrides; + ModuleMacro *MM; // FIXME: Remove this. ModuleFile *F; - bool isDefine() const { return MI; } + bool isDefine() const { return MM->getMacroInfo(); } - SubmoduleID getSubmoduleID() const { return SubModID; } - - ArrayRef getOverriddenSubmodules() const { return Overrides; } + ArrayRef getOverriddenMacros() const { + return MM->overrides(); + } MacroDirective *import(Preprocessor &PP, SourceLocation ImportLoc) const { - if (!MI) - return PP.AllocateUndefMacroDirective(ImportLoc, SubModID, - getOverriddenSubmodules()); - return PP.AllocateDefMacroDirective(MI, ImportLoc, SubModID, - getOverriddenSubmodules()); + if (auto *MI = MM->getMacroInfo()) + return PP.AllocateDefMacroDirective(MI, ImportLoc, MM); + return PP.AllocateUndefMacroDirective(ImportLoc, MM); } }; @@ -1753,7 +1749,12 @@ void ASTReader::resolvePendingMacro(IdentifierInfo *II, SavedStreamPosition SavedPosition(Cursor); Cursor.JumpToBit(PMInfo.MacroDirectivesOffset); - llvm::SmallVector ModuleMacros; + struct ModuleMacroRecord { + SubmoduleID SubModID; + MacroInfo *MI; + SmallVector Overrides; + }; + llvm::SmallVector ModuleMacros; // We expect to see a sequence of PP_MODULE_MACRO records listing exported // macros, followed by a PP_MACRO_DIRECTIVE_HISTORY record with the complete @@ -1773,20 +1774,12 @@ void ASTReader::resolvePendingMacro(IdentifierInfo *II, break; case PP_MODULE_MACRO: { - ModuleMacroInfo Info; + ModuleMacros.push_back(ModuleMacroRecord()); + auto &Info = ModuleMacros.back(); Info.SubModID = getGlobalSubmoduleID(M, Record[0]); Info.MI = getMacro(getGlobalMacroID(M, Record[1])); - Info.F = &M; - - if (Record.size() > 2) { - auto *Overrides = new (Context) SubmoduleID[Record.size() - 2]; - for (int I = 2, N = Record.size(); I != N; ++I) - Overrides[I - 2] = getGlobalSubmoduleID(M, Record[I]); - Info.Overrides = - llvm::makeArrayRef(Overrides, Overrides + Record.size() - 2); - } - - ModuleMacros.push_back(Info); + for (int I = 2, N = Record.size(); I != N; ++I) + Info.Overrides.push_back(getGlobalSubmoduleID(M, Record[I])); continue; } @@ -1804,9 +1797,9 @@ void ASTReader::resolvePendingMacro(IdentifierInfo *II, { std::reverse(ModuleMacros.begin(), ModuleMacros.end()); llvm::SmallVector Overrides; - for (auto &MMI : ModuleMacros) { + for (auto &MMR : ModuleMacros) { Overrides.clear(); - for (unsigned ModID : MMI.Overrides) { + for (unsigned ModID : MMR.Overrides) { Module *Mod = getSubmodule(ModID); auto *Macro = PP.getModuleMacro(Mod, II); assert(Macro && "missing definition for overridden macro"); @@ -1814,11 +1807,12 @@ void ASTReader::resolvePendingMacro(IdentifierInfo *II, } bool Inserted = false; - Module *Owner = getSubmodule(MMI.getSubmoduleID()); - PP.addModuleMacro(Owner, II, MMI.MI, Overrides, Inserted); + Module *Owner = getSubmodule(MMR.SubModID); + auto *MM = PP.addModuleMacro(Owner, II, MMR.MI, Overrides, Inserted); if (!Inserted) continue; + ModuleMacroInfo MMI = { MM, &M }; if (Owner->NameVisibility == Module::Hidden) { // Macros in the owning module are hidden. Just remember this macro to // install if we make this module visible. @@ -1844,35 +1838,21 @@ void ASTReader::resolvePendingMacro(IdentifierInfo *II, MacroDirective::Kind K = (MacroDirective::Kind)Record[Idx++]; switch (K) { case MacroDirective::MD_Define: { - GlobalMacroID GMacID = getGlobalMacroID(M, Record[Idx++]); - MacroInfo *MI = getMacro(GMacID); - SubmoduleID ImportedFrom = getGlobalSubmoduleID(M, Record[Idx++]); + MacroInfo *MI = getMacro(getGlobalMacroID(M, Record[Idx++])); bool IsAmbiguous = Record[Idx++]; - llvm::SmallVector Overrides; - if (ImportedFrom) { - Overrides.insert(Overrides.end(), - &Record[Idx] + 1, &Record[Idx] + 1 + Record[Idx]); - for (auto &ID : Overrides) - ID = getGlobalSubmoduleID(M, ID); - Idx += Overrides.size() + 1; - } - DefMacroDirective *DefMD = - PP.AllocateDefMacroDirective(MI, Loc, ImportedFrom, Overrides); + ModuleMacro *MM = nullptr; + if (SubmoduleID ImportedFrom = getGlobalSubmoduleID(M, Record[Idx++])) + MM = PP.getModuleMacro(getSubmodule(ImportedFrom), II); + DefMacroDirective *DefMD = PP.AllocateDefMacroDirective(MI, Loc, MM); DefMD->setAmbiguous(IsAmbiguous); MD = DefMD; break; } case MacroDirective::MD_Undefine: { - SubmoduleID ImportedFrom = getGlobalSubmoduleID(M, Record[Idx++]); - llvm::SmallVector Overrides; - if (ImportedFrom) { - Overrides.insert(Overrides.end(), - &Record[Idx] + 1, &Record[Idx] + 1 + Record[Idx]); - for (auto &ID : Overrides) - ID = getGlobalSubmoduleID(M, ID); - Idx += Overrides.size() + 1; - } - MD = PP.AllocateUndefMacroDirective(Loc, ImportedFrom, Overrides); + ModuleMacro *MM = nullptr; + if (SubmoduleID ImportedFrom = getGlobalSubmoduleID(M, Record[Idx++])) + MM = PP.getModuleMacro(getSubmodule(ImportedFrom), II); + MD = PP.AllocateUndefMacroDirective(Loc, MM); break; } case MacroDirective::MD_Visibility: @@ -1912,13 +1892,11 @@ static bool areDefinedInSystemModules(MacroInfo *PrevMI, MacroInfo *NewMI, void ASTReader::removeOverriddenMacros(IdentifierInfo *II, SourceLocation ImportLoc, AmbiguousMacros &Ambig, - ArrayRef Overrides) { - for (unsigned OI = 0, ON = Overrides.size(); OI != ON; ++OI) { - SubmoduleID OwnerID = Overrides[OI]; - + ArrayRef Overrides) { + for (ModuleMacro *Overridden : Overrides) { + Module *Owner = Overridden->getOwningModule(); // If this macro is not yet visible, remove it from the hidden names list. // It won't be there if we're in the middle of making the owner visible. - Module *Owner = getSubmodule(OwnerID); auto HiddenIt = HiddenNamesMap.find(Owner); if (HiddenIt != HiddenNamesMap.end()) { HiddenNames &Hidden = HiddenIt->second; @@ -1927,7 +1905,7 @@ void ASTReader::removeOverriddenMacros(IdentifierInfo *II, // Register the macro now so we don't lose it when we re-export. PP.appendMacroDirective(II, HI->second->import(PP, ImportLoc)); - auto SubOverrides = HI->second->getOverriddenSubmodules(); + auto SubOverrides = HI->second->getOverriddenMacros(); Hidden.HiddenMacros.erase(HI); removeOverriddenMacros(II, ImportLoc, Ambig, SubOverrides); } @@ -1936,7 +1914,7 @@ void ASTReader::removeOverriddenMacros(IdentifierInfo *II, // If this macro is already in our list of conflicts, remove it from there. Ambig.erase( std::remove_if(Ambig.begin(), Ambig.end(), [&](DefMacroDirective *MD) { - return MD->getInfo()->getOwningModuleID() == OwnerID; + return getSubmodule(MD->getInfo()->getOwningModuleID()) == Owner; }), Ambig.end()); } @@ -1945,7 +1923,7 @@ void ASTReader::removeOverriddenMacros(IdentifierInfo *II, ASTReader::AmbiguousMacros * ASTReader::removeOverriddenMacros(IdentifierInfo *II, SourceLocation ImportLoc, - ArrayRef Overrides) { + ArrayRef Overrides) { MacroDirective *Prev = PP.getMacroDirective(II); if (!Prev && Overrides.empty()) return nullptr; @@ -1997,7 +1975,7 @@ void ASTReader::installImportedMacro(IdentifierInfo *II, ModuleMacroInfo &MMI, } AmbiguousMacros *Prev = - removeOverriddenMacros(II, ImportLoc, MMI.getOverriddenSubmodules()); + removeOverriddenMacros(II, ImportLoc, MMI.getOverriddenMacros()); // Create a synthetic macro definition corresponding to the import (or null // if this was an undefinition of the macro). diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 59191f2..9714893 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -2068,20 +2068,17 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { if (auto *DefMD = dyn_cast(MD)) { MacroID InfoID = getMacroRef(DefMD->getInfo(), Name); Record.push_back(InfoID); - Record.push_back(DefMD->getOwningModuleID()); Record.push_back(DefMD->isAmbiguous()); - } else if (auto *UndefMD = dyn_cast(MD)) { - Record.push_back(UndefMD->getOwningModuleID()); - } else { - auto *VisMD = cast(MD); + } else if (auto *VisMD = dyn_cast(MD)) { Record.push_back(VisMD->isPublic()); + // No owning module macro. + continue; } - if (MD->isImported()) { - auto Overrides = MD->getOverriddenModules(); - Record.push_back(Overrides.size()); - Record.append(Overrides.begin(), Overrides.end()); - } + if (auto *MM = MD->getOwningModuleMacro()) + Record.push_back(getSubmoduleID(MM->getOwningModule())); + else + Record.push_back(0); } // Write out any exported module macros.