diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp --- a/flang/lib/Semantics/expression.cpp +++ b/flang/lib/Semantics/expression.cpp @@ -207,6 +207,9 @@ last.name()); } if (auto *component{std::get_if(&ref.u)}) { + if (!CheckDataRef(ref)) { + return std::nullopt; + } return Expr{ProcedureDesignator{std::move(*component)}}; } else if (!std::holds_alternative(ref.u)) { DIE("unexpected alternative in DataRef"); diff --git a/flang/test/Semantics/expr-errors04.f90 b/flang/test/Semantics/expr-errors04.f90 --- a/flang/test/Semantics/expr-errors04.f90 +++ b/flang/test/Semantics/expr-errors04.f90 @@ -92,6 +92,8 @@ !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed call sub0(t%t3%t2%t1%info1(i)) !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed + call sub0(t%t3%t2%t1%info1) + !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed call t%t3%t2%t1%info2 !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed call t%t3%t2%t1%g1 @@ -99,6 +101,8 @@ !ERROR: Reference to rank-2 object 't1' has 1 subscripts call sub0(t%t3%t2%t1(1)%info1(i)) !ERROR: Reference to rank-2 object 't1' has 1 subscripts + call sub0(t%t3%t2%t1(1)%info1) + !ERROR: Reference to rank-2 object 't1' has 1 subscripts call t%t3%t2%t1(1)%info2 !ERROR: Reference to rank-2 object 't1' has 1 subscripts call t%t3%t2%t1(1)%g1 @@ -106,6 +110,8 @@ !ERROR: Reference to rank-2 object 't1' has 1 subscripts call sub0(t%t3%t2%t1(1:)%info1(i)) !ERROR: Reference to rank-2 object 't1' has 1 subscripts + call sub0(t%t3%t2%t1(1:)%info1) + !ERROR: Reference to rank-2 object 't1' has 1 subscripts call t%t3%t2%t1(1:)%info2 !ERROR: Reference to rank-2 object 't1' has 1 subscripts call t%t3%t2%t1(1:)%g1