@@ -4293,23 +4293,30 @@ void Fortran::lower::attachDeclarePostAllocAction(
4293
4293
const Fortran::semantics::Symbol &sym) {
4294
4294
std::stringstream fctName;
4295
4295
fctName << converter.mangleName (sym) << declarePostAllocSuffix.str ();
4296
- mlir::Operation &op = builder.getInsertionBlock ()->back ();
4296
+ mlir::Operation *op = &builder.getInsertionBlock ()->back ();
4297
+
4298
+ if (auto resOp = mlir::dyn_cast<fir::ResultOp>(*op)) {
4299
+ assert (resOp.getOperands ().size () == 0 &&
4300
+ " expect only fir.result op with no operand" );
4301
+ op = op->getPrevNode ();
4302
+ }
4303
+ assert (op && " expect operation to attach the post allocation action" );
4297
4304
4298
- if (op. hasAttr (mlir::acc::getDeclareActionAttrName ())) {
4299
- auto attr = op. getAttrOfType <mlir::acc::DeclareActionAttr>(
4305
+ if (op-> hasAttr (mlir::acc::getDeclareActionAttrName ())) {
4306
+ auto attr = op-> getAttrOfType <mlir::acc::DeclareActionAttr>(
4300
4307
mlir::acc::getDeclareActionAttrName ());
4301
- op. setAttr (mlir::acc::getDeclareActionAttrName (),
4302
- mlir::acc::DeclareActionAttr::get (
4303
- builder.getContext (), attr.getPreAlloc (),
4304
- /* postAlloc=*/ builder.getSymbolRefAttr (fctName.str ()),
4305
- attr.getPreDealloc (), attr.getPostDealloc ()));
4308
+ op-> setAttr (mlir::acc::getDeclareActionAttrName (),
4309
+ mlir::acc::DeclareActionAttr::get (
4310
+ builder.getContext (), attr.getPreAlloc (),
4311
+ /* postAlloc=*/ builder.getSymbolRefAttr (fctName.str ()),
4312
+ attr.getPreDealloc (), attr.getPostDealloc ()));
4306
4313
} else {
4307
- op. setAttr (mlir::acc::getDeclareActionAttrName (),
4308
- mlir::acc::DeclareActionAttr::get (
4309
- builder.getContext (),
4310
- /* preAlloc=*/ {},
4311
- /* postAlloc=*/ builder.getSymbolRefAttr (fctName.str ()),
4312
- /* preDealloc=*/ {}, /* postDealloc=*/ {}));
4314
+ op-> setAttr (mlir::acc::getDeclareActionAttrName (),
4315
+ mlir::acc::DeclareActionAttr::get (
4316
+ builder.getContext (),
4317
+ /* preAlloc=*/ {},
4318
+ /* postAlloc=*/ builder.getSymbolRefAttr (fctName.str ()),
4319
+ /* preDealloc=*/ {}, /* postDealloc=*/ {}));
4313
4320
}
4314
4321
}
4315
4322
0 commit comments