[flang-commits] [flang] [flang][cuda] Preserve array lower bounds in implicit device-to-host transfer (PR #227824)
via flang-commits
flang-commits at lists.llvm.org
Thu Oct 1 06:11:08 PDT 2026
================
@@ -43,6 +43,35 @@ fir::ExtendedValue fir::substBase(const fir::ExtendedValue &exv,
[=](const auto &x) { return fir::ExtendedValue(x.clone(base)); });
}
+fir::ExtendedValue
+fir::updateRuntimeLBounds(const fir::ExtendedValue &exv,
+ llvm::ArrayRef<mlir::Value> lbounds) {
+ if (lbounds.empty())
+ return exv;
+ return exv.match(
+ [&](const fir::ArrayBoxValue &v) -> fir::ExtendedValue {
+ return fir::ArrayBoxValue(v.getAddr(), v.getExtents(), lbounds,
+ v.getSourceBox());
+ },
+ [&](const fir::CharArrayBoxValue &v) -> fir::ExtendedValue {
+ return fir::CharArrayBoxValue(v.getAddr(), v.getLen(), v.getExtents(),
+ lbounds);
+ },
+ [&](const fir::BoxValue &v) -> fir::ExtendedValue {
+ return fir::BoxValue(v.getAddr(), lbounds, v.getExplicitParameters(),
+ v.getExplicitExtents());
+ },
+ [&](const fir::MutableBoxValue &v) -> fir::ExtendedValue {
+ // MutableBoxValue stores lower bounds in the runtime descriptor
+ // (or in mutableProperties when isDescribedByVariables). The caller
+ // is responsible for extracting them (e.g. via genDimInfoFromBox)
+ // before calling this helper. We represent the result as a BoxValue
+ // with explicit lbounds so that genDeclare can emit fir.shape_shift.
+ return fir::BoxValue(v.getAddr(), lbounds, v.nonDeferredLenParams());
----------------
jeanPerier wrote:
That is invalid, the base address of a fir::BoxValue should be a fir.box, not a fir.ref<fir.box>.
In general, I am not sure that something like `updateRuntimeLBounds` should handle POINTER/ALLOCATABLE as this requires modifying the fir.ref<fir.box> which is a non trivial action that I am not sure we should hide in this helper until there is any need for it.
Prefer placing a fatal_error here and describing that this should not be called for MutableBoxValue.
https://github.com/llvm/llvm-project/pull/227824
More information about the flang-commits
mailing list