diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp --- a/flang/lib/Lower/ConvertExpr.cpp +++ b/flang/lib/Lower/ConvertExpr.cpp @@ -7238,17 +7238,19 @@ mlir::Operation *op = boxBase.getDefiningOp(); mlir::Type actualTy = converter.genType(expr); - if (auto embox = mlir::dyn_cast(op)) { - auto newBox = builder.create( - loc, fir::BoxType::get(actualTy), embox.getMemref(), embox.getShape(), - embox.getSlice(), embox.getTypeparams()); - return fir::substBase(box, newBox); - } - if (auto rebox = mlir::dyn_cast(op)) { - auto newBox = builder.create(loc, fir::BoxType::get(actualTy), - rebox.getBox(), rebox.getShape(), - rebox.getSlice()); - return fir::substBase(box, newBox); + if (op) { + if (auto embox = mlir::dyn_cast(op)) { + auto newBox = builder.create( + loc, fir::BoxType::get(actualTy), embox.getMemref(), embox.getShape(), + embox.getSlice(), embox.getTypeparams()); + return fir::substBase(box, newBox); + } + if (auto rebox = mlir::dyn_cast(op)) { + auto newBox = builder.create( + loc, fir::BoxType::get(actualTy), rebox.getBox(), rebox.getShape(), + rebox.getSlice()); + return fir::substBase(box, newBox); + } } mlir::Value empty;