From ac0c59992051bae128bd46df06a63bd74cdcaa8b Mon Sep 17 00:00:00 2001 From: Tim Keith Date: Tue, 23 Oct 2018 17:05:12 -0700 Subject: [PATCH] [flang] Fix bug with popping scopes. Processing a SUBMODULE can cause any number of scopes to be pushed on the scope stack. We don't know how many to pop at the end, so add `ClearScopes()` to reset the scope stack to its original state. Original-commit: flang-compiler/f18@0be4cebd66b81281bfa07016eb2b1393cf271e69 Reviewed-on: https://github.com/flang-compiler/f18/pull/218 Tree-same-pre-rewrite: false --- flang/lib/semantics/resolve-names.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/flang/lib/semantics/resolve-names.cc b/flang/lib/semantics/resolve-names.cc index 88c8922..0dc4459 100644 --- a/flang/lib/semantics/resolve-names.cc +++ b/flang/lib/semantics/resolve-names.cc @@ -262,6 +262,9 @@ public: protected: void PushScope(); void PopScope(); + void ClearScopes() { + implicitRules_.reset(nullptr); + } private: // implicit rules in effect for current scope @@ -323,6 +326,11 @@ public: void PushScope(Scope::Kind kind, Symbol *symbol); void PushScope(Scope &scope); void PopScope(); + void ClearScopes() { + PopScope(); + currScope_ = &context().globalScope(); + ImplicitRulesVisitor::ClearScopes(); + } Symbol *FindSymbol(const SourceName &name); void EraseSymbol(const SourceName &name); @@ -1509,8 +1517,7 @@ bool ModuleVisitor::Pre(const parser::Submodule &x) { return true; } void ModuleVisitor::Post(const parser::Submodule &) { - PopScope(); // submodule's scope - PopScope(); // parent's scope + ClearScopes(); } bool ModuleVisitor::Pre(const parser::Module &x) { -- 2.7.4