From: Richard Smith Date: Thu, 30 Apr 2015 02:16:23 +0000 (+0000) Subject: Remove dead code: a MacroDirective can't be imported or ambiguous any more. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=59365bd6ea721cd8fb11dda4ebacb55e2da3d7a0;p=clang Remove dead code: a MacroDirective can't be imported or ambiguous any more. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236197 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Lex/MacroInfo.h b/include/clang/Lex/MacroInfo.h index 9d1db2ac38..c3a9472036 100644 --- a/include/clang/Lex/MacroInfo.h +++ b/include/clang/Lex/MacroInfo.h @@ -305,15 +305,8 @@ class DefMacroDirective; /// /// MacroDirectives, associated with an identifier, are used to model the macro /// history. Usually a macro definition (MacroInfo) is where a macro name -/// becomes active (MacroDirective) but modules can have their own macro -/// history, separate from the local (current translation unit) macro history. -/// -/// For example, if "@import A;" imports macro FOO, there will be a new local -/// MacroDirective created to indicate that "FOO" became active at the import -/// location. Module "A" itself will contain another MacroDirective in its macro -/// history (at the point of the definition of FOO) and both MacroDirectives -/// will point to the same MacroInfo object. -/// +/// becomes active (MacroDirective) but #pragma push_macro / pop_macro can +/// create additional DefMacroDirectives for the same MacroInfo. class MacroDirective { public: enum Kind { @@ -334,38 +327,15 @@ protected: /// \brief True if the macro directive was loaded from a PCH file. bool IsFromPCH : 1; - // Used by DefMacroDirective -----------------------------------------------// - - /// \brief Whether the definition of this macro is ambiguous, due to - /// multiple definitions coming in from multiple modules. - bool IsAmbiguous : 1; - // Used by VisibilityMacroDirective ----------------------------------------// /// \brief Whether the macro has public visibility (when described in a /// module). bool IsPublic : 1; - // Used by DefMacroDirective and UndefMacroDirective -----------------------// - - /// \brief True if this macro was imported from a module. - bool IsImported : 1; - - struct ImportData { - ModuleMacro *ImportedFrom; - }; - ImportData *getImportData(); - const ImportData *getImportData() const { - return const_cast(this)->getImportData(); - } - - MacroDirective(Kind K, SourceLocation Loc, - ModuleMacro *ImportedFrom = nullptr) + MacroDirective(Kind K, SourceLocation Loc) : Previous(nullptr), Loc(Loc), MDKind(K), IsFromPCH(false), - IsAmbiguous(false), IsPublic(true), IsImported(ImportedFrom) { - if (IsImported) - getImportData()->ImportedFrom = ImportedFrom; - } + IsPublic(true) {} public: Kind getKind() const { return Kind(MDKind); } @@ -388,18 +358,6 @@ public: void setIsFromPCH() { IsFromPCH = true; } - /// \brief True if this macro was imported from a module. - /// 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 module - /// macro from which this directive was created. - ModuleMacro *getOwningModuleMacro() const { - if (isImported()) - return getImportData()->ImportedFrom; - return 0; - } - class DefInfo { DefMacroDirective *DefDirective; SourceLocation UndefLoc; @@ -471,32 +429,18 @@ public: class DefMacroDirective : public MacroDirective { MacroInfo *Info; - DefMacroDirective(MacroInfo *MI, SourceLocation Loc, - ModuleMacro *ImportedFrom) - : MacroDirective(MD_Define, Loc, ImportedFrom), Info(MI) { - assert(MI && "MacroInfo is null"); - } - public: DefMacroDirective(MacroInfo *MI, SourceLocation Loc) - : DefMacroDirective(MI, Loc, nullptr) {} + : MacroDirective(MD_Define, Loc), Info(MI) { + assert(MI && "MacroInfo is null"); + } 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; } - /// \brief Determine whether this macro definition is ambiguous with - /// other macro definitions. - bool isAmbiguous() const { return IsAmbiguous; } - - /// \brief Set whether this macro definition is ambiguous. - void setAmbiguous(bool Val) { IsAmbiguous = Val; } - static bool classof(const MacroDirective *MD) { return MD->getKind() == MD_Define; } @@ -505,17 +449,11 @@ public: /// \brief A directive for an undefined macro. class UndefMacroDirective : public MacroDirective { - UndefMacroDirective(SourceLocation UndefLoc, ModuleMacro *ImportedFrom) - : MacroDirective(MD_Undefine, UndefLoc, ImportedFrom) { - assert(UndefLoc.isValid() && "Invalid UndefLoc!"); - } - public: explicit UndefMacroDirective(SourceLocation UndefLoc) - : UndefMacroDirective(UndefLoc, nullptr) {} - static UndefMacroDirective *createImported(Preprocessor &PP, - SourceLocation UndefLoc, - ModuleMacro *ImportedFrom); + : MacroDirective(MD_Undefine, UndefLoc) { + assert(UndefLoc.isValid() && "Invalid UndefLoc!"); + } static bool classof(const MacroDirective *MD) { return MD->getKind() == MD_Undefine; @@ -541,14 +479,6 @@ public: static bool classof(const VisibilityMacroDirective *) { return true; } }; -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); - else - return reinterpret_cast(cast(this) + 1); -} - inline SourceLocation MacroDirective::DefInfo::getLocation() const { if (isInvalid()) return SourceLocation(); diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 8322e00260..ad8589e086 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -1678,9 +1678,6 @@ private: VisibilityMacroDirective *AllocateVisibilityMacroDirective(SourceLocation Loc, bool isPublic); - MacroDirective *AllocateImportedMacroDirective(ModuleMacro *MM, - SourceLocation Loc); - /// \brief Lex and validate a macro name, which occurs after a /// \#define or \#undef. /// diff --git a/lib/Lex/MacroInfo.cpp b/lib/Lex/MacroInfo.cpp index dbc804490b..7581fe3cd7 100644 --- a/lib/Lex/MacroInfo.cpp +++ b/lib/Lex/MacroInfo.cpp @@ -218,8 +218,6 @@ void MacroDirective::dump() const { if (auto *Prev = getPrevious()) Out << " prev " << Prev; if (IsFromPCH) Out << " from_pch"; - if (IsImported) Out << " imported"; - if (IsAmbiguous) Out << " ambiguous"; if (IsPublic) Out << " public"; @@ -235,25 +233,6 @@ 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/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index 6c25bd87a2..1c66aac533 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -78,15 +78,6 @@ Preprocessor::AllocateVisibilityMacroDirective(SourceLocation Loc, return new (BP) VisibilityMacroDirective(Loc, isPublic); } -MacroDirective * -Preprocessor::AllocateImportedMacroDirective(ModuleMacro *MM, - SourceLocation Loc) { - if (auto *MI = MM->getMacroInfo()) - return DefMacroDirective::createImported(*this, MI, Loc, MM); - else - return UndefMacroDirective::createImported(*this, Loc, MM); -} - /// \brief Read and discard all tokens remaining on the current line until /// the tok::eod token is found. void Preprocessor::DiscardUntilEndOfDirective() { diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index cc8b7fe6db..0aff712abb 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -55,7 +55,7 @@ void Preprocessor::appendMacroDirective(IdentifierInfo *II, MacroDirective *MD){ II->setHasMacroDefinition(true); if (!MD->isDefined() && LeafModuleMacros.find(II) == LeafModuleMacros.end()) II->setHasMacroDefinition(false); - if (II->isFromAST() && !MD->isImported()) + if (II->isFromAST()) II->setChangedSinceDeserialization(); } diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 921c06ce67..7225d2f610 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -1809,21 +1809,11 @@ void ASTReader::resolvePendingMacro(IdentifierInfo *II, switch (K) { case MacroDirective::MD_Define: { MacroInfo *MI = getMacro(getGlobalMacroID(M, Record[Idx++])); - bool IsAmbiguous = Record[Idx++]; - ModuleMacro *MM = nullptr; - if (SubmoduleID ImportedFrom = getGlobalSubmoduleID(M, Record[Idx++])) - MM = PP.getModuleMacro(getSubmodule(ImportedFrom), II); - MD = MM ? PP.AllocateImportedMacroDirective(MM, Loc) - : PP.AllocateDefMacroDirective(MI, Loc); - cast(MD)->setAmbiguous(IsAmbiguous); + MD = PP.AllocateDefMacroDirective(MI, Loc); break; } case MacroDirective::MD_Undefine: { - ModuleMacro *MM = nullptr; - if (SubmoduleID ImportedFrom = getGlobalSubmoduleID(M, Record[Idx++])) - MM = PP.getModuleMacro(getSubmodule(ImportedFrom), II); - MD = MM ? PP.AllocateImportedMacroDirective(MM, Loc) - : PP.AllocateUndefMacroDirective(Loc); + MD = PP.AllocateUndefMacroDirective(Loc); break; } case MacroDirective::MD_Visibility: diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 9fe83234a1..3843697734 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -1979,10 +1979,6 @@ static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule, return true; if (IsModule) { - // Re-export any imported directives. - if (MD->isImported()) - return false; - SourceLocation Loc = MD->getLocation(); if (Loc.isInvalid()) return true; @@ -2066,19 +2062,10 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { AddSourceLocation(MD->getLocation(), Record); Record.push_back(MD->getKind()); if (auto *DefMD = dyn_cast(MD)) { - MacroID InfoID = getMacroRef(DefMD->getInfo(), Name); - Record.push_back(InfoID); - Record.push_back(DefMD->isAmbiguous()); + Record.push_back(getMacroRef(DefMD->getInfo(), Name)); } else if (auto *VisMD = dyn_cast(MD)) { Record.push_back(VisMD->isPublic()); - // No owning module macro. - continue; } - - if (auto *MM = MD->getOwningModuleMacro()) - Record.push_back(getSubmoduleID(MM->getOwningModule())); - else - Record.push_back(0); } // Write out any exported module macros.