From 0d701085e0cda1e1d685891c9fbf8fa4030a12a5 Mon Sep 17 00:00:00 2001 From: Tim Keith Date: Tue, 19 Jun 2018 14:59:41 -0700 Subject: [PATCH] [flang] Fix bug in adding symbols to parse tree. We were collecting symbols in a map of SourceName to Symbol*. This is wrong because sometimes different occurrences of a name map to different symbols (e.g. in different scopes). SourceName::begin() is unique for each occurrence so use that as the map key instead. The problem can be reproduced by running: `f18 -fdebug-resolve-names -fparse-only -fdebug-dump-parse-tree` on the following source. The two symbols 'i' should have different types and they were both coming out as INTEGER because they both pointed to the first symbol for 'i'. ``` module m integer :: i contains subroutine s real :: i end end ``` Original-commit: flang-compiler/f18@a165c717ff20d3ccca334b91fa538f54b54071cf Reviewed-on: https://github.com/flang-compiler/f18/pull/107 Tree-same-pre-rewrite: false --- flang/lib/semantics/rewrite-parse-tree.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/flang/lib/semantics/rewrite-parse-tree.cc b/flang/lib/semantics/rewrite-parse-tree.cc index d3cc1be..816e168 100644 --- a/flang/lib/semantics/rewrite-parse-tree.cc +++ b/flang/lib/semantics/rewrite-parse-tree.cc @@ -23,7 +23,7 @@ namespace Fortran::semantics { // Symbols collected during name resolution that are added to parse tree. -using symbolMap = std::map; +using symbolMap = std::map; /// Walk the parse tree and add symbols from the symbolMap in Name nodes. /// Convert mis-identified statement functions to array element assignments. @@ -37,7 +37,7 @@ public: // Fill in name.symbol if there is a corresponding symbol void Post(parser::Name &name) { - const auto it = symbols_.find(name.source); + const auto it = symbols_.find(name.source.begin()); if (it != symbols_.end()) { name.symbol = it->second; } @@ -104,9 +104,9 @@ private: static void CollectSymbols(Scope &scope, symbolMap &symbols) { for (auto &pair : scope) { - Symbol &symbol{pair.second}; - for (const auto &name : symbol.occurrences()) { - symbols.emplace(name, &symbol); + Symbol *symbol{pair.second}; + for (const auto &name : symbol->occurrences()) { + symbols.emplace(name.begin(), symbol); } } for (auto &child : scope.children()) { -- 2.7.4