diff options
author | Slava Zakharin <szakharin@nvidia.com> | 2023-05-11 19:16:56 -0700 |
---|---|---|
committer | Slava Zakharin <szakharin@nvidia.com> | 2023-05-12 11:33:45 -0700 |
commit | 1644adfc74b4bde822b37398b3811f038073d9a9 (patch) | |
tree | 40c531664550b0db82754447a64318e297d8f2a2 /flang/lib | |
parent | 868591501c61bc1aa56da537bab85cc67439f16d (diff) | |
download | llvm-1644adfc74b4bde822b37398b3811f038073d9a9.tar.gz |
[flang][hlfir] Fixed AssociateOp codegen for 0-dim variables.
The codegen tried to fir.convert !fir.box to !fir.ref for this case.
I used BoxAddr under a check for the type mismatch, but I am not sure
if this is the right fix. Maybe it has to be handled in the lowering.
Diffstat (limited to 'flang/lib')
-rw-r--r-- | flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp index 3b30feb3b65f..7b12fad984f4 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp @@ -346,9 +346,27 @@ struct AssociateOpConversion auto replaceWith = [&](mlir::Value hlfirVar, mlir::Value firVar, mlir::Value flag) { - hlfirVar = - builder.createConvert(loc, associate.getResultTypes()[0], hlfirVar); + // 0-dim variables may need special handling: + // %0 = hlfir.as_expr %x move %true : + // (!fir.box<!fir.heap<!fir.type<_T{y:i32}>>>, i1) -> + // !hlfir.expr<!fir.type<_T{y:i32}>> + // %1:3 = hlfir.associate %0 {uniq_name = "adapt.valuebyref"} : + // (!hlfir.expr<!fir.type<_T{y:i32}>>) -> + // (!fir.ref<!fir.type<_T{y:i32}>>, + // !fir.ref<!fir.type<_T{y:i32}>>, + // i1) + // + // !fir.box<!fir.heap<!fir.type<_T{y:i32}>>> value must be propagated + // as the box address !fir.ref<!fir.type<_T{y:i32}>>. + mlir::Type associateHlfirVarType = associate.getResultTypes()[0]; + if (hlfirVar.getType().isa<fir::BaseBoxType>() && + !associateHlfirVarType.isa<fir::BaseBoxType>()) + hlfirVar = builder.create<fir::BoxAddrOp>(loc, associateHlfirVarType, + hlfirVar); + else + hlfirVar = builder.createConvert(loc, associateHlfirVarType, hlfirVar); associate.getResult(0).replaceAllUsesWith(hlfirVar); + mlir::Type associateFirVarType = associate.getResultTypes()[1]; if ((firVar.getType().isa<fir::BaseBoxType>() && !associateFirVarType.isa<fir::BaseBoxType>()) || |