[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@0be4cebd66
Reviewed-on: https://github.com/flang-compiler/f18/pull/218
Tree-same-pre-rewrite: false
This commit is contained in:
Tim Keith 2018-10-23 17:05:12 -07:00
parent 4687189913
commit ac0c599920

View file

@ -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) {