@@ -4077,11 +4077,16 @@ class ArrayExprLowering {
40774077 return header;
40784078 }
40794079
4080+ // / Lower mask expressions with implied iteration spaces from the variants of
4081+ // / WHERE syntax. Since it is legal for mask expressions to have side-effects
4082+ // / and modify values that will be used for the lhs, rhs, or both of
4083+ // / subsequent assignments, the mask must be evaluated before the assignment
4084+ // / is processed.
40804085 // / Mask expressions are array expressions too.
40814086 void genMasks () {
4082- auto loc = getLoc ();
40834087 // Lower the mask expressions, if any.
40844088 if (implicitSpaceHasMasks ()) {
4089+ auto loc = getLoc ();
40854090 // Mask expressions are array expressions too.
40864091 for (const auto *e : implicitSpace->getExprs ())
40874092 if (e && !implicitSpace->isLowered (e)) {
@@ -4140,7 +4145,6 @@ class ArrayExprLowering {
41404145 auto ldExt = builder.create <fir::LoadOp>(loc, coor);
41414146 extents.push_back (builder.createConvert (loc, idxTy, ldExt));
41424147 }
4143- destShape = extents;
41444148 // Construct shape of buffer.
41454149 auto shapeOp = builder.genShape (loc, extents);
41464150
@@ -4221,11 +4225,6 @@ class ArrayExprLowering {
42214225 std::pair<IterationSpace, mlir::OpBuilder::InsertPoint>
42224226 genIterSpace (mlir::Type resultType) {
42234227 auto loc = getLoc ();
4224-
4225- // Generate any mask expressions, as necessary. This is the compute step
4226- // that creates the effective masks. See 10.2.3.2 in particular.
4227- genMasks ();
4228-
42294228 auto shape = genIterationShape ();
42304229 if (!destination) {
42314230 // Allocate storage for the result if it is not already provided.
@@ -4675,16 +4674,9 @@ class ArrayExprLowering {
46754674 static ExtValue convertAdjustedType (fir::FirOpBuilder &builder,
46764675 mlir::Location loc, mlir::Type toType,
46774676 const ExtValue &exv) {
4678- auto lenFromBufferType = [&](mlir::Type ty) {
4679- return builder.create <mlir::ConstantIndexOp>(
4680- loc, fir::dyn_cast_ptrEleTy (ty).cast <fir::CharacterType>().getLen ());
4681- };
46824677 return exv.match (
46834678 [&](const fir::CharBoxValue &cb) -> ExtValue {
4684- auto typeParams = fir::getTypeParams (exv);
4685- auto len = typeParams.size () > 0
4686- ? typeParams[0 ]
4687- : lenFromBufferType (cb.getBuffer ().getType ());
4679+ auto len = cb.getLen ();
46884680 auto mem =
46894681 builder.create <fir::AllocaOp>(loc, toType, mlir::ValueRange{len});
46904682 fir::CharBoxValue result (mem, len);
@@ -4706,7 +4698,9 @@ class ArrayExprLowering {
47064698 return [=](IterSpace iters) -> ExtValue {
47074699 auto exv = lambda (iters);
47084700 auto val = fir::getBase (exv);
4709- if (elementTypeWasAdjusted (val.getType ()))
4701+ auto valTy = val.getType ();
4702+ if (elementTypeWasAdjusted (valTy) &&
4703+ !(fir::isa_ref_type (valTy) && fir::isa_integer (ty)))
47104704 return convertAdjustedType (builder, loc, ty, exv);
47114705 return builder.createConvert (loc, ty, val);
47124706 };
@@ -6401,7 +6395,11 @@ class ArrayExprLowering {
64016395 : converter{converter}, builder{converter.getFirOpBuilder ()},
64026396 stmtCtx{stmtCtx}, symMap{symMap},
64036397 explicitSpace (expSpace->isActive () ? expSpace : nullptr),
6404- implicitSpace(impSpace->empty () ? nullptr : impSpace), semant{sem} {}
6398+ implicitSpace(impSpace->empty () ? nullptr : impSpace), semant{sem} {
6399+ // Generate any mask expressions, as necessary. This is the compute step
6400+ // that creates the effective masks. See 10.2.3.2 in particular.
6401+ genMasks ();
6402+ }
64056403
64066404 mlir::Location getLoc () { return converter.getCurrentLocation (); }
64076405
0 commit comments