[flang-commits] [flang] a15ebe0 - [flang] fix procedure fir.box_addr identification in boxed-procedure (#79290)

via flang-commits flang-commits at lists.llvm.org
Thu Jan 25 01:00:10 PST 2024


Author: jeanPerier
Date: 2024-01-25T10:00:06+01:00
New Revision: a15ebe0246c75faedfe9cb2fbc6ea7b62e265026

URL: https://github.com/llvm/llvm-project/commit/a15ebe0246c75faedfe9cb2fbc6ea7b62e265026
DIFF: https://github.com/llvm/llvm-project/commit/a15ebe0246c75faedfe9cb2fbc6ea7b62e265026.diff

LOG: [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.

Added: 
    

Modified: 
    flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
    flang/test/Fir/boxproc-2.fir

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
index 7d73af4d7103dc..83333e2bae5b3d 100644
--- a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
+++ b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
@@ -207,8 +207,8 @@ class BoxedProcedurePass
         if (auto addr = mlir::dyn_cast<BoxAddrOp>(op)) {
           mlir::Type ty = addr.getVal().getType();
           mlir::Type resTy = addr.getResult().getType();
-          if (typeConverter.needsConversion(ty) ||
-              ty.isa<mlir::FunctionType>()) {
+          if (llvm::isa<mlir::FunctionType>(ty) ||
+              llvm::isa<fir::BoxProcType>(ty)) {
             // Rewrite all `fir.box_addr` ops on values of type `!fir.boxproc`
             // or function type to be `fir.convert` ops.
             rewriter.setInsertionPoint(addr);

diff  --git a/flang/test/Fir/boxproc-2.fir b/flang/test/Fir/boxproc-2.fir
index 1550cddac5db9e..b7a5bc69e687e5 100644
--- a/flang/test/Fir/boxproc-2.fir
+++ b/flang/test/Fir/boxproc-2.fir
@@ -94,3 +94,11 @@ func.func @block_arg_rewrite(%arg0: !fir.ref<!fir.type<t{p:!fir.boxproc<() -> ()
 // CHECK:           fir.call @dosomething(%[[VAL_3]]) : (!fir.ref<!fir.type<tUnboxProc{p:() -> ()}>>) -> ()
 
 func.func private @dosomething(!fir.ref<!fir.type<t{p:!fir.boxproc<() -> ()>}>>)
+
+!t2 = !fir.type<t2{i:!fir.boxproc<() -> ()>}>
+func.func @box_addr_test(%arg0: !fir.box<!t2>) -> !fir.ref<!t2> {
+  %3 = fir.box_addr %arg0 : (!fir.box<!t2>) -> !fir.ref<!t2>
+  return %3 : !fir.ref<!t2>
+}
+// CHECK: func.func @box_addr_test(
+// CHECK:   fir.box_addr %{{.*}} : (!fir.box<!fir.type<t2UnboxProc{i:() -> ()}>>) -> !fir.ref<!fir.type<t2UnboxProc{i:() -> ()}>>


        


More information about the flang-commits mailing list