From 51fe22391654cf6eb3a054e48a9c3a3c599911b2 Mon Sep 17 00:00:00 2001 From: Tim Keith Date: Mon, 26 Aug 2019 15:46:49 -0700 Subject: [PATCH] [flang] Fix bug with statement functions When the name of a statement function was previously declared, we weren't correctly recognizing it as a statement function. E.g. ``` integer :: f, i f(i) = i + 1 ``` `f` was entered in the symbol table with `EntityDetails` and the `parser::Name` on the first line was resolved to that symbol. On the second line we replaced the symbol for `f` in the scope with a subprogram symbol, but that didn't change the symbol in the first `parser::Name`. The fix requires: 1. don't erase the original symbol for `f`, just replace its details 2. when we erase the symbol for `f` in the subprogram scope, don't unresolve it Original-commit: flang-compiler/f18@31212686ea357503840c0562853c6977bfc1ffe5 --- flang/lib/semantics/resolve-names.cc | 4 ++-- flang/test/semantics/CMakeLists.txt | 1 + flang/test/semantics/symbol16.f90 | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 flang/test/semantics/symbol16.f90 diff --git a/flang/lib/semantics/resolve-names.cc b/flang/lib/semantics/resolve-names.cc index 8ea3d12..1435cdc 100644 --- a/flang/lib/semantics/resolve-names.cc +++ b/flang/lib/semantics/resolve-names.cc @@ -2353,7 +2353,7 @@ bool SubprogramVisitor::HandleStmtFunction(const parser::StmtFunctionStmt &x) { } // TODO: check that attrs are compatible with stmt func resultType = details->type(); - EraseSymbol(name); + symbol->details() = UnknownDetails{}; // will be replaced below } if (badStmtFuncFound_) { Say(name, "'%s' has not been declared as an array"_err_en_US); @@ -2372,7 +2372,7 @@ bool SubprogramVisitor::HandleStmtFunction(const parser::StmtFunctionStmt &x) { } details.add_dummyArg(MakeSymbol(dummyName, std::move(dummyDetails))); } - EraseSymbol(name); // added by PushSubprogramScope + EraseSymbol(symbol); // added by PushSubprogramScope EntityDetails resultDetails; if (resultType) { resultDetails.set_type(*resultType); diff --git a/flang/test/semantics/CMakeLists.txt b/flang/test/semantics/CMakeLists.txt index 5626ad2..5675526 100644 --- a/flang/test/semantics/CMakeLists.txt +++ b/flang/test/semantics/CMakeLists.txt @@ -177,6 +177,7 @@ set(SYMBOL_TESTS symbol13.f90 symbol14.f90 symbol15.f90 + symbol16.f90 kinds01.f90 kinds03.f90 procinterface01.f90 diff --git a/flang/test/semantics/symbol16.f90 b/flang/test/semantics/symbol16.f90 new file mode 100644 index 0000000..d6785f3 --- /dev/null +++ b/flang/test/semantics/symbol16.f90 @@ -0,0 +1,30 @@ +! Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. +! +! Licensed under the Apache License, Version 2.0 (the "License"); +! you may not use this file except in compliance with the License. +! You may obtain a copy of the License at +! +! http://www.apache.org/licenses/LICENSE-2.0 +! +! Unless required by applicable law or agreed to in writing, software +! distributed under the License is distributed on an "AS IS" BASIS, +! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +! See the License for the specific language governing permissions and +! limitations under the License. + +! Statement functions + +!DEF: /p1 MainProgram +program p1 + !DEF: /p1/f Subprogram INTEGER(4) + !DEF: /p1/i ObjectEntity INTEGER(4) + !DEF: /p1/j ObjectEntity INTEGER(4) + integer f, i, j + !REF: /p1/f + !REF: /p1/i + !DEF: /p1/f/i ObjectEntity INTEGER(4) + f(i) = i + 1 + !REF: /p1/j + !REF: /p1/f + j = f(2) +end program -- 2.7.4