Skip to content

Commit a15ebe0

Browse files
authored
[flang] fix procedure fir.box_addr identification in boxed-procedure (#79290)
The pass was mistakenly identifying a fir.box_addr on a fir.box/fir.class of a derived type with procedure pointer components as being a fir.box_addr on a procedure. Simply check if the input type is a fir.box_proc or function type (if input already rewritten) and insert convert only in this case. This caused "invalid fir.convert" internal error.
1 parent d5c9d40 commit a15ebe0

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ class BoxedProcedurePass
207207
if (auto addr = mlir::dyn_cast<BoxAddrOp>(op)) {
208208
mlir::Type ty = addr.getVal().getType();
209209
mlir::Type resTy = addr.getResult().getType();
210-
if (typeConverter.needsConversion(ty) ||
211-
ty.isa<mlir::FunctionType>()) {
210+
if (llvm::isa<mlir::FunctionType>(ty) ||
211+
llvm::isa<fir::BoxProcType>(ty)) {
212212
// Rewrite all `fir.box_addr` ops on values of type `!fir.boxproc`
213213
// or function type to be `fir.convert` ops.
214214
rewriter.setInsertionPoint(addr);

flang/test/Fir/boxproc-2.fir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,11 @@ func.func @block_arg_rewrite(%arg0: !fir.ref<!fir.type<t{p:!fir.boxproc<() -> ()
9494
// CHECK: fir.call @dosomething(%[[VAL_3]]) : (!fir.ref<!fir.type<tUnboxProc{p:() -> ()}>>) -> ()
9595

9696
func.func private @dosomething(!fir.ref<!fir.type<t{p:!fir.boxproc<() -> ()>}>>)
97+
98+
!t2 = !fir.type<t2{i:!fir.boxproc<() -> ()>}>
99+
func.func @box_addr_test(%arg0: !fir.box<!t2>) -> !fir.ref<!t2> {
100+
%3 = fir.box_addr %arg0 : (!fir.box<!t2>) -> !fir.ref<!t2>
101+
return %3 : !fir.ref<!t2>
102+
}
103+
// CHECK: func.func @box_addr_test(
104+
// CHECK: fir.box_addr %{{.*}} : (!fir.box<!fir.type<t2UnboxProc{i:() -> ()}>>) -> !fir.ref<!fir.type<t2UnboxProc{i:() -> ()}>>

0 commit comments

Comments
 (0)