Index: flang/docs/ProcedurePointer.md =================================================================== --- flang/docs/ProcedurePointer.md +++ flang/docs/ProcedurePointer.md @@ -470,7 +470,7 @@ NOTE: There are any number of possible implementations. -- fir.global for procedure pointers +BoxedProcedure pass or Index: flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp =================================================================== --- flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp +++ flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp @@ -252,6 +252,14 @@ 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)) { Index: flang/test/Fir/boxproc-2.fir =================================================================== --- flang/test/Fir/boxproc-2.fir +++ flang/test/Fir/boxproc-2.fir @@ -44,3 +44,24 @@ // 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> +}