diff --git a/flang/docs/ProcedurePointer.md b/flang/docs/ProcedurePointer.md index cfa036b22fdf..b41c4003518e 100644 --- a/flang/docs/ProcedurePointer.md +++ b/flang/docs/ProcedurePointer.md @@ -470,7 +470,7 @@ Current list of TODOs in code generation: NOTE: There are any number of possible implementations. -- fir.global for procedure pointers +BoxedProcedure pass or diff --git a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp index 8456c4a4b14b..4df4dcb2d02b 100644 --- a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp +++ b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp @@ -253,6 +253,14 @@ public: rewriter.replaceOpWithNewOp(embox, toTy, embox.getFunc()); } + } else if (auto global = mlir::dyn_cast(op)) { + auto ty = global.getType(); + if (typeConverter.needsConversion(ty)) { + rewriter.startRootUpdate(global); + auto toTy = typeConverter.convertType(ty); + global.setType(toTy); + rewriter.finalizeRootUpdate(global); + } } else if (auto mem = mlir::dyn_cast(op)) { auto ty = mem.getType(); if (typeConverter.needsConversion(ty)) { diff --git a/flang/test/Fir/boxproc-2.fir b/flang/test/Fir/boxproc-2.fir index b9a11591e796..bd6595c2d9e9 100644 --- a/flang/test/Fir/boxproc-2.fir +++ b/flang/test/Fir/boxproc-2.fir @@ -44,3 +44,24 @@ func.func @proc_pointer_component(%arg0 : !fir.boxproc<(!fir.ref) -> f32>, // CHECK: %[[VAL_11:.*]] = fir.call %[[VAL_10]](%[[VAL_1]]) : (!fir.ref) -> f32 } + +// CHECK-LABEL: fir.global internal @ProcedurePointer : (!fir.ref) -> f32 { +fir.global internal @ProcedurePointer : !fir.boxproc<(!fir.ref) -> f32> { + %0 = fir.zero_bits (!fir.ref) -> f32 + %1 = fir.emboxproc %0 : ((!fir.ref) -> f32) -> !fir.boxproc<(!fir.ref) -> f32> + fir.has_value %1 : !fir.boxproc<(!fir.ref) -> f32> + +// CHECK: %[[VAL_0:.*]] = fir.zero_bits (!fir.ref) -> f32 +// CHECK: %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : ((!fir.ref) -> f32) -> ((!fir.ref) -> f32) +// CHECK: fir.has_value %[[VAL_1]] : (!fir.ref) -> f32 +} + +// CHECK-LABEL: func.func @proc_pointer_global() { +func.func @proc_pointer_global() { + %0 = fir.address_of(@ProcedurePointer) : !fir.ref) -> f32>> + %1 = fir.load %0 : !fir.ref) -> f32>> + return + +// CHECK: %[[VAL_0:.*]] = fir.address_of(@ProcedurePointer) : !fir.ref<(!fir.ref) -> f32> +// CHECK: %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref<(!fir.ref) -> f32> +}