-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flang] Correct disambiguation of possible statement function definit…
…ions The statement "A(J) = expr" could be an assignment to an element of an array A, an assignment to the target of a pointer-valued function A, or the definition of a new statement function in the local scope named A, depending on whether it appears in (what might still be) the specification part of a program or subprogram and what other declarations and definitions for A might exist in the local scope or have been imported into it. The standard requires that the name of a statement function appear in an earlier type declaration statement if it is also the name of an entity in the enclosing scope. Some other Fortran compilers mistakenly enforce that rule in the case of an assignment to the target of a pointer-valued function in the containing scope, after misinterpreting the assignment as a new local statement function definition. This patch cleans up the handling of the various possibilities and resolves what was a crash in the case of a statement function definition whose name was the same as that of a procedure in the outer scope whose result is *not* a pointer. Differential Revision: https://reviews.llvm.org/D155493
- Loading branch information
Showing
5 changed files
with
75 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
! RUN: %python %S/test_errors.py %s %flang_fc1 | ||
integer :: g(10) | ||
f(i) = i + 1 ! statement function | ||
g(i) = i + 2 ! mis-parsed array assignment | ||
!ERROR: 'h' has not been declared as an array | ||
g(i) = i + 2 ! mis-parsed assignment | ||
!ERROR: 'h' has not been declared as an array or pointer-valued function | ||
h(i) = i + 3 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
! RUN: %python %S/test_errors.py %s %flang_fc1 | ||
module m | ||
real, target :: x = 1. | ||
contains | ||
function rpf(x) | ||
real, intent(in out), target :: x | ||
real, pointer :: rpf | ||
rpf => x | ||
end | ||
real function rf(x) | ||
rf = x | ||
end | ||
subroutine test1 | ||
! This is a valid assignment, not a statement function. | ||
! Every other Fortran compiler misinterprets it! | ||
rpf(x) = 2. ! statement function or indirect assignment? | ||
print *, x | ||
end | ||
subroutine test2 | ||
!PORTABILITY: Name 'rf' from host scope should have a type declaration before its local statement function definition | ||
rf(x) = 3. | ||
end | ||
subroutine test3 | ||
external sf | ||
!ERROR: 'sf' has not been declared as an array or pointer-valued function | ||
sf(x) = 4. | ||
end | ||
end |