[flang-commits] [flang] [flang] lower remaining cases of pointer assignments inside forall (PR #130772)
via flang-commits
flang-commits at lists.llvm.org
Thu Mar 13 02:11:40 PDT 2025
================
@@ -4400,22 +4382,74 @@ class FirConverter : public Fortran::lower::AbstractConverter {
builder->setInsertionPointAfter(regionAssignOp);
}
+ mlir::Value lowerToIndexValue(mlir::Location loc,
+ const Fortran::evaluate::ExtentExpr &expr,
+ Fortran::lower::StatementContext &stmtCtx) {
+ mlir::Value val = fir::getBase(genExprValue(toEvExpr(expr), stmtCtx));
+ return builder->createConvert(loc, builder->getIndexType(), val);
+ }
+
mlir::Value
genForallPointerAssignmentRhs(mlir::Location loc, mlir::Value lhs,
const Fortran::evaluate::Assignment &assign,
Fortran::lower::StatementContext &rhsContext) {
- if (Fortran::evaluate::IsProcedureDesignator(assign.rhs))
+ if (Fortran::evaluate::IsProcedureDesignator(assign.lhs)) {
+ if (Fortran::evaluate::UnwrapExpr<Fortran::evaluate::NullPointer>(
+ assign.rhs))
+ return fir::factory::createNullBoxProc(
+ *builder, loc, fir::unwrapRefType(lhs.getType()));
return fir::getBase(Fortran::lower::convertExprToAddress(
loc, *this, assign.rhs, localSymbols, rhsContext));
+ }
// Data target.
+ auto lhsBoxType =
+ llvm::cast<fir::BaseBoxType>(fir::unwrapRefType(lhs.getType()));
+ // For NULL, create disassociated descriptor whose dynamic type is
+ // the static type of the LHS.
+ if (Fortran::evaluate::UnwrapExpr<Fortran::evaluate::NullPointer>(
+ assign.rhs))
+ return fir::factory::createUnallocatedBox(*builder, loc, lhsBoxType,
+ std::nullopt);
hlfir::Entity rhs = Fortran::lower::convertExprToHLFIR(
loc, *this, assign.rhs, localSymbols, rhsContext);
// Create pointer descriptor value from the RHS.
if (rhs.isMutableBox())
rhs = hlfir::Entity{builder->create<fir::LoadOp>(loc, rhs)};
- auto lhsBoxType =
- llvm::cast<fir::BaseBoxType>(fir::unwrapRefType(lhs.getType()));
- return hlfir::genVariableBox(loc, *builder, rhs, lhsBoxType);
+ mlir::Value rhsBox = hlfir::genVariableBox(
+ loc, *builder, rhs, lhsBoxType.getBoxTypeWithNewShape(rhs.getRank()));
+ mlir::Type indexTy = builder->getIndexType();
+ // Bounds
----------------
jeanPerier wrote:
```suggestion
// Apply lower bounds or reshaping if any.
```
https://github.com/llvm/llvm-project/pull/130772
More information about the flang-commits
mailing list