@@ -4077,11 +4077,16 @@ class ArrayExprLowering {
4077
4077
return header;
4078
4078
}
4079
4079
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.
4080
4085
// / Mask expressions are array expressions too.
4081
4086
void genMasks () {
4082
- auto loc = getLoc ();
4083
4087
// Lower the mask expressions, if any.
4084
4088
if (implicitSpaceHasMasks ()) {
4089
+ auto loc = getLoc ();
4085
4090
// Mask expressions are array expressions too.
4086
4091
for (const auto *e : implicitSpace->getExprs ())
4087
4092
if (e && !implicitSpace->isLowered (e)) {
@@ -4140,7 +4145,6 @@ class ArrayExprLowering {
4140
4145
auto ldExt = builder.create <fir::LoadOp>(loc, coor);
4141
4146
extents.push_back (builder.createConvert (loc, idxTy, ldExt));
4142
4147
}
4143
- destShape = extents;
4144
4148
// Construct shape of buffer.
4145
4149
auto shapeOp = builder.genShape (loc, extents);
4146
4150
@@ -4221,11 +4225,6 @@ class ArrayExprLowering {
4221
4225
std::pair<IterationSpace, mlir::OpBuilder::InsertPoint>
4222
4226
genIterSpace (mlir::Type resultType) {
4223
4227
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
-
4229
4228
auto shape = genIterationShape ();
4230
4229
if (!destination) {
4231
4230
// Allocate storage for the result if it is not already provided.
@@ -4675,16 +4674,9 @@ class ArrayExprLowering {
4675
4674
static ExtValue convertAdjustedType (fir::FirOpBuilder &builder,
4676
4675
mlir::Location loc, mlir::Type toType,
4677
4676
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
- };
4682
4677
return exv.match (
4683
4678
[&](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 ();
4688
4680
auto mem =
4689
4681
builder.create <fir::AllocaOp>(loc, toType, mlir::ValueRange{len});
4690
4682
fir::CharBoxValue result (mem, len);
@@ -4706,7 +4698,9 @@ class ArrayExprLowering {
4706
4698
return [=](IterSpace iters) -> ExtValue {
4707
4699
auto exv = lambda (iters);
4708
4700
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)))
4710
4704
return convertAdjustedType (builder, loc, ty, exv);
4711
4705
return builder.createConvert (loc, ty, val);
4712
4706
};
@@ -6401,7 +6395,11 @@ class ArrayExprLowering {
6401
6395
: converter{converter}, builder{converter.getFirOpBuilder ()},
6402
6396
stmtCtx{stmtCtx}, symMap{symMap},
6403
6397
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
+ }
6405
6403
6406
6404
mlir::Location getLoc () { return converter.getCurrentLocation (); }
6407
6405
0 commit comments