Skip to content

Commit a3a918a

Browse files
klauslerjeanPerier
authored andcommitted
[flang] Catch error: base of DATA statement object can't be a pointer
A pointer with subscripts, substring indices, or components cannot be initialized by a DATA statement (although of course a whole pointer can be so). Catch the missing cases. Differential Revision: https://reviews.llvm.org/D109931
1 parent b93fc14 commit a3a918a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

flang/lib/Semantics/check-data.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ class DataVarChecker : public evaluate::AllTraverse<DataVarChecker, true> {
7070
: IsHostAssociated(symbol, scope) ? "Host-associated object"
7171
: IsUseAssociated(symbol, scope) ? "USE-associated object"
7272
: symbol.has<AssocEntityDetails>() ? "Construct association"
73-
: nullptr}) {
73+
: IsPointer(symbol) && (hasComponent_ || hasSubscript_)
74+
? "Target of pointer"
75+
: nullptr}) {
7476
context_.Say(source_,
7577
"%s '%s' must not be initialized in a DATA statement"_err_en_US,
7678
whyNot, symbol.name());

flang/test/Semantics/data04.f90

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ subroutine CheckObject(i)
6565
type(large) :: largeNumberArray(i)
6666
type(large) :: largeArray(5)
6767
character :: name(i)
68+
type small
69+
real :: x
70+
end type
71+
type(small), pointer :: sp
6872
!C877
6973
!ERROR: Default-initialized 'largenumber' must not be initialized in a DATA statement
7074
DATA(largeNumber % numsArray(j) % headOfTheList, j = 1, 10) / 10 * NULL() /
@@ -92,6 +96,8 @@ subroutine CheckObject(i)
9296
!C876
9397
!ERROR: Automatic variable 'name' must not be initialized in a DATA statement
9498
DATA name( : 2) / 'Ancd' /
99+
!ERROR: Target of pointer 'sp' must not be initialized in a DATA statement
100+
DATA sp%x / 1.0 /
95101
end
96102
end
97103

0 commit comments

Comments
 (0)