[flang][runtime] Catch EOSHIFT ARRAY/BOUNDARY type mismatch (#183168)

The ARRAY= and optional BOUNDARY= arguments to EOSHIFT must have the
same dynamic type. Add a runtime check.
This commit is contained in:
Peter Klausler 2026-02-26 07:08:56 -08:00 committed by GitHub
parent 67eb750225
commit 7acc02ff7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -583,6 +583,26 @@ void RTDEF(CshiftVector)(Descriptor &result, const Descriptor &source,
}
}
static void CheckBoundaryType(const Descriptor &array,
const Descriptor &boundary, Terminator &terminator) {
if (const auto *boundaryAddendum{boundary.Addendum()}) {
if (const auto *boundaryDT{boundaryAddendum->derivedType()}) {
if (const auto *arrayAddendum{array.Addendum()}) {
if (const auto *arrayDT{arrayAddendum->derivedType()}) {
if (boundaryDT != arrayDT) {
terminator.Crash("EOSHIFT: BOUNDARY= has type '%.*s' that differs "
"from ARRAY= type '%.*s'",
static_cast<int>(boundaryDT->name().ElementBytes()),
boundaryDT->name().OffsetElement(),
static_cast<int>(arrayDT->name().ElementBytes()),
arrayDT->name().OffsetElement());
}
}
}
}
}
}
// EOSHIFT of rank > 1
void RTDEF(Eoshift)(Descriptor &result, const Descriptor &source,
const Descriptor &shift, const Descriptor *boundary, int dim,
@ -621,6 +641,7 @@ void RTDEF(Eoshift)(Descriptor &result, const Descriptor &source,
}
}
}
CheckBoundaryType(source, *boundary, terminator);
}
ShiftControl shiftControl{shift, terminator, dim};
shiftControl.Init(source, "EOSHIFT");
@ -675,13 +696,13 @@ void RTDEF(EoshiftVector)(Descriptor &result, const Descriptor &source,
if (boundary) {
RUNTIME_CHECK(terminator, boundary->rank() == 0);
RUNTIME_CHECK(terminator, boundary->type() == source.type());
CheckBoundaryType(source, *boundary, terminator);
if (boundary->ElementBytes() != elementLen) {
terminator.Crash("EOSHIFT: BOUNDARY= has element byte length %zd but "
"ARRAY= has length %zd",
boundary->ElementBytes(), elementLen);
}
}
if (!boundary) {
} else {
DefaultInitialize(result, terminator);
}
SubscriptValue lb{source.GetDimension(0).LowerBound()};