summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2015-04-28 21:05:07 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2015-04-28 21:05:07 +0000
commit1e1728536a4a453c81fad90d94b3b3c0f9dd5897 (patch)
tree48f63929909953c8b4cf852133a7e99156e48c3b /clang
parent2fbc4e5c4942a3a816c2d13913db0ee65990f448 (diff)
downloadbcm5719-llvm-1e1728536a4a453c81fad90d94b3b3c0f9dd5897.tar.gz
bcm5719-llvm-1e1728536a4a453c81fad90d94b3b3c0f9dd5897.zip
Refactor to make MacroState ownership and lifetime clearer.
llvm-svn: 236032
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Lex/Preprocessor.h13
-rw-r--r--clang/lib/Lex/PPLexerChange.cpp5
-rw-r--r--clang/lib/Lex/Preprocessor.cpp3
3 files changed, 15 insertions, 6 deletions
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index db3231ef2b5..c4765f099e4 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -408,11 +408,20 @@ class Preprocessor : public RefCountedBase<Preprocessor> {
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;
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index 57110aa246f..3f0c2bb2776 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/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/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 80715d54807..92ab2af1921 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -142,9 +142,6 @@ Preprocessor::Preprocessor(IntrusiveRefCntPtr<PreprocessorOptions> PPOpts,
Preprocessor::~Preprocessor() {
assert(BacktrackPositions.empty() && "EnableBacktrack/Backtrack imbalance!");
- for (auto &Macro : Macros)
- Macro.second.destroy();
-
IncludeMacroStack.clear();
// Destroy any macro definitions.
OpenPOWER on IntegriCloud