r236032 - Refactor to make MacroState ownership and lifetime clearer.
Richard Smith
richard-llvm at metafoo.co.uk
Tue Apr 28 14:05:08 PDT 2015
Author: rsmith
Date: Tue Apr 28 16:05:07 2015
New Revision: 236032
URL: http://llvm.org/viewvc/llvm-project?rev=236032&view=rev
Log:
Refactor to make MacroState ownership and lifetime clearer.
Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Lex/PPLexerChange.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=236032&r1=236031&r2=236032&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Tue Apr 28 16:05:07 2015
@@ -408,11 +408,20 @@ class Preprocessor : public RefCountedBa
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<ModuleMacroInfo*>())
Info->~ModuleMacroInfo();
- State = (MacroDirective*)nullptr;
}
+
MacroDirective *getLatest() const {
if (auto *Info = State.dyn_cast<ModuleMacroInfo*>())
return Info->MD;
Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=236032&r1=236031&r2=236032&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Tue Apr 28 16:05:07 2015
@@ -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();
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=236032&r1=236031&r2=236032&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Tue Apr 28 16:05:07 2015
@@ -142,9 +142,6 @@ Preprocessor::Preprocessor(IntrusiveRefC
Preprocessor::~Preprocessor() {
assert(BacktrackPositions.empty() && "EnableBacktrack/Backtrack imbalance!");
- for (auto &Macro : Macros)
- Macro.second.destroy();
-
IncludeMacroStack.clear();
// Destroy any macro definitions.
More information about the cfe-commits
mailing list