From: Richard Smith Date: Tue, 28 Apr 2015 21:05:07 +0000 (+0000) Subject: Refactor to make MacroState ownership and lifetime clearer. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6ec0dff0c4a5c2d0cf7a6aa3ee768bd93735dd1f;p=clang Refactor to make MacroState ownership and lifetime clearer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236032 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index db3231ef2b..c4765f099e 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -408,11 +408,20 @@ class Preprocessor : public RefCountedBase { public: MacroState() : MacroState(nullptr) {} MacroState(MacroDirective *MD) : State(MD) {} - void destroy() { + MacroState(MacroState &&O) LLVM_NOEXCEPT : State(O.State) { + O.State = (MacroDirective *)nullptr; + } + MacroState &operator=(MacroState &&O) LLVM_NOEXCEPT { + auto S = O.State; + O.State = (MacroDirective *)nullptr; + State = S; + return *this; + } + ~MacroState() { if (auto *Info = State.dyn_cast()) Info->~ModuleMacroInfo(); - State = (MacroDirective*)nullptr; } + MacroDirective *getLatest() const { if (auto *Info = State.dyn_cast()) return Info->MD; diff --git a/lib/Lex/PPLexerChange.cpp b/lib/Lex/PPLexerChange.cpp index 57110aa246..3f0c2bb277 100644 --- a/lib/Lex/PPLexerChange.cpp +++ b/lib/Lex/PPLexerChange.cpp @@ -638,6 +638,8 @@ void Preprocessor::LeaveSubmodule() { bool ExplicitlyPublic = false; for (auto *MD = Macro.second.getLatest(); MD != SavedInfo.Latest; MD = MD->getPrevious()) { + assert(MD && "broken macro directive chain"); + // Skip macros defined in other submodules we #included along the way. Module *Mod = getModuleContainingLocation(MD->getLocation()); if (Mod != Info.M) @@ -673,7 +675,8 @@ void Preprocessor::LeaveSubmodule() { Info.M->NameVisibility = Module::MacrosVisible; Info.M->MacroVisibilityLoc = Info.ImportLoc; ++MacroVisibilityGeneration; - // FIXME: Also mark any exported macros as visible, and check for conflicts. + // FIXME: Also mark any exported modules as visible, and check for + // conflicts. } BuildingSubmoduleStack.pop_back(); diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 80715d5480..92ab2af192 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -142,9 +142,6 @@ Preprocessor::Preprocessor(IntrusiveRefCntPtr PPOpts, Preprocessor::~Preprocessor() { assert(BacktrackPositions.empty() && "EnableBacktrack/Backtrack imbalance!"); - for (auto &Macro : Macros) - Macro.second.destroy(); - IncludeMacroStack.clear(); // Destroy any macro definitions.