[PATCH] D84588: [flang] Fix implicit declarations in statement functions
Tim Keith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 25 08:23:14 PDT 2020
tskeith created this revision.
tskeith added reviewers: klausler, PeteSteinfeld, jeanPerier.
tskeith added a project: Flang.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: DavidTruby.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
If a symbol (that is not a dummy argument) is implicitly declared inside
a statement function, don't create it in the statement function's scope.
Instead, treat statement functions like blocks when finding the inclusive
scope and create the symbol there.
Add a new flag, StmtFunction, to symbols that represent statement functions.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D84588
Files:
flang/include/flang/Semantics/scope.h
flang/include/flang/Semantics/symbol.h
flang/lib/Semantics/resolve-names.cpp
flang/lib/Semantics/scope.cpp
flang/test/Semantics/symbol16.f90
Index: flang/test/Semantics/symbol16.f90
===================================================================
--- flang/test/Semantics/symbol16.f90
+++ flang/test/Semantics/symbol16.f90
@@ -3,7 +3,7 @@
!DEF: /p1 MainProgram
program p1
- !DEF: /p1/f (Function) Subprogram INTEGER(4)
+ !DEF: /p1/f (Function, StmtFunction) Subprogram INTEGER(4)
!DEF: /p1/i ObjectEntity INTEGER(4)
!DEF: /p1/j ObjectEntity INTEGER(4)
integer f, i, j
@@ -15,3 +15,13 @@
!REF: /p1/f
j = f(2)
end program
+
+!DEF: /p2 MainProgram
+program p2
+ !DEF: /p2/f (Function, StmtFunction) Subprogram REAL(4)
+ !DEF: /p2/f/x (Implicit) ObjectEntity REAL(4)
+ !DEF: /p2/y (Implicit) ObjectEntity REAL(4)
+ f(x) = y
+ !REF: /p2/y
+ y = 1.0
+end program
Index: flang/lib/Semantics/scope.cpp
===================================================================
--- flang/lib/Semantics/scope.cpp
+++ flang/lib/Semantics/scope.cpp
@@ -333,6 +333,10 @@
return os;
}
+bool Scope::IsStmtFunction() const {
+ return symbol_ && symbol_->test(Symbol::Flag::StmtFunction);
+}
+
bool Scope::IsParameterizedDerivedType() const {
if (!IsDerivedType()) {
return false;
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -2014,7 +2014,8 @@
Scope &ScopeHandler::InclusiveScope() {
for (auto *scope{&currScope()};; scope = &scope->parent()) {
- if (scope->kind() != Scope::Kind::Block && !scope->IsDerivedType()) {
+ if (scope->kind() != Scope::Kind::Block && !scope->IsDerivedType() &&
+ !scope->IsStmtFunction()) {
return *scope;
}
}
@@ -2691,6 +2692,7 @@
return true;
}
auto &symbol{PushSubprogramScope(name, Symbol::Flag::Function)};
+ symbol.set(Symbol::Flag::StmtFunction);
EraseSymbol(symbol); // removes symbol added by PushSubprogramScope
auto &details{symbol.get<SubprogramDetails>()};
for (const auto &dummyName : std::get<std::list<parser::Name>>(x.t)) {
Index: flang/include/flang/Semantics/symbol.h
===================================================================
--- flang/include/flang/Semantics/symbol.h
+++ flang/include/flang/Semantics/symbol.h
@@ -482,6 +482,7 @@
Error, // an error has been reported on this symbol
Function, // symbol is a function
Subroutine, // symbol is a subroutine
+ StmtFunction, // symbol is a statement function (Function is set too)
Implicit, // symbol is implicitly typed
ModFile, // symbol came from .mod file
ParentComp, // symbol is the "parent component" of an extended type
Index: flang/include/flang/Semantics/scope.h
===================================================================
--- flang/include/flang/Semantics/scope.h
+++ flang/include/flang/Semantics/scope.h
@@ -87,6 +87,7 @@
bool IsModule() const; // only module, not submodule
bool IsSubmodule() const;
bool IsDerivedType() const { return kind_ == Kind::DerivedType; }
+ bool IsStmtFunction() const;
bool IsParameterizedDerivedType() const;
Symbol *symbol() { return symbol_; }
const Symbol *symbol() const { return symbol_; }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84588.280683.patch
Type: text/x-patch
Size: 3196 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200725/c4277571/attachment.bin>
More information about the llvm-commits
mailing list