diff --git a/flang/lib/Evaluate/fold-designator.cpp b/flang/lib/Evaluate/fold-designator.cpp --- a/flang/lib/Evaluate/fold-designator.cpp +++ b/flang/lib/Evaluate/fold-designator.cpp @@ -298,7 +298,9 @@ // Reconstructs a Designator from a symbol, an offset, and a size. std::optional> OffsetToDesignator(FoldingContext &context, const Symbol &baseSymbol, ConstantSubscript offset, std::size_t size) { - CHECK(offset >= 0); + if (offset < 0) { + return std::nullopt; + } if (std::optional dataRef{ OffsetToDataRef(context, NamedEntity{baseSymbol}, offset, size)}) { const Symbol &symbol{dataRef->GetLastSymbol()}; diff --git a/flang/test/Semantics/data06.f90 b/flang/test/Semantics/data06.f90 --- a/flang/test/Semantics/data06.f90 +++ b/flang/test/Semantics/data06.f90 @@ -28,6 +28,9 @@ integer :: a4(3) !ERROR: DATA statement designator 'a4(5_8)' is out of range data (a4(j),j=1,5,2) /3*222/ + integer :: a5(3) + !ERROR: DATA statement designator 'a5(-2_8)' is out of range + data a5(-2) / 1 / interface real function rfunc(x) real, intent(in) :: x