@@ -4293,23 +4293,30 @@ void Fortran::lower::attachDeclarePostAllocAction(
42934293 const Fortran::semantics::Symbol &sym) {
42944294 std::stringstream fctName;
42954295 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" );
42974304
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>(
43004307 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 ()));
43064313 } 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=*/ {}));
43134320 }
43144321}
43154322
0 commit comments