[flang-commits] [flang] [flang][hlfir] Reset lower bounds to one when bufferizing hlfir.as_expr move (PR #202406)
via flang-commits
flang-commits at lists.llvm.org
Tue Jun 9 01:56:20 PDT 2026
================
@@ -156,8 +156,24 @@ struct AsExprOpConversion : public mlir::OpConversionPattern<hlfir::AsExprOp> {
fir::FirOpBuilder builder(rewriter, module);
if (asExpr.isMove()) {
// Move variable storage for the hlfir.expr buffer.
- mlir::Value bufferizedExpr = packageBufferizedExpr(
- loc, builder, hlfir::Entity{adaptor.getVar()}, adaptor.getMustFree());
+ hlfir::Entity storage{adaptor.getVar()};
+ // An hlfir.expr has lower bounds of one. When the moved storage is a
+ // descriptor that may carry non-default lower bounds (e.g. an allocatable
+ // or pointer function result used in a structure constructor), rebox it
+ // to lower bounds of one so they are not propagated to the users of the
+ // expression. This does not copy the data.
+ if (storage.isArray() && mlir::isa<fir::BaseBoxType>(storage.getType()) &&
+ storage.mayHaveNonDefaultLowerBounds()) {
+ mlir::Value one =
+ builder.createIntegerConstant(loc, builder.getIndexType(), 1);
+ llvm::SmallVector<mlir::Value> ones(storage.getRank(), one);
+ mlir::Value shift = builder.genShift(loc, ones);
----------------
jeanPerier wrote:
No need to add the shift. No shift is equivalent to a shift with all ones and less IR/compiler code.
https://github.com/llvm/llvm-project/pull/202406
More information about the flang-commits
mailing list