diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -532,6 +532,20 @@ } }; +/// Lower `fir.boxproc_host` operation. Extracts the host pointer from the +/// boxproc. +/// TODO: Part of supporting Fortran 2003 procedure pointers. +struct BoxProcHostOpConversion : public FIROpConversion { + using FIROpConversion::FIROpConversion; + + mlir::LogicalResult + matchAndRewrite(fir::BoxProcHostOp boxprochost, OpAdaptor adaptor, + mlir::ConversionPatternRewriter &rewriter) const override { + return rewriter.notifyMatchFailure( + boxprochost, "fir.boxproc_host codegen is not implemented yet"); + } +}; + /// Lower `fir.box_tdesc` to the sequence of operations to extract the type /// descriptor from the box. struct BoxTypeDescOpConversion : public FIROpConversion { @@ -1529,6 +1543,20 @@ } }; +/// Lower `fir.emboxproc` operation. Creates a procedure box. +/// TODO: Part of supporting Fortran 2003 procedure pointers. +struct EmboxProcOpConversion : public FIROpConversion { + using FIROpConversion::FIROpConversion; + + mlir::LogicalResult + matchAndRewrite(fir::EmboxProcOp emboxproc, OpAdaptor adaptor, + mlir::ConversionPatternRewriter &rewriter) const override { + return rewriter.notifyMatchFailure( + emboxproc, "fir.emboxproc codegen is not implemented yet"); + } +}; + + // Code shared between insert_value and extract_value Ops. struct ValueOpCommon { // Translate the arguments pertaining to any multidimensional array to @@ -2035,6 +2063,20 @@ } }; +/// Lower `fir.unboxproc` operation. Unbox a procedure box value, yielding its +/// components. +/// TODO: Part of supporting Fortran 2003 procedure pointers. +struct UnboxProcOpConversion : public FIROpConversion { + using FIROpConversion::FIROpConversion; + + mlir::LogicalResult + matchAndRewrite(fir::UnboxProcOp unboxproc, OpAdaptor adaptor, + mlir::ConversionPatternRewriter &rewriter) const override { + return rewriter.notifyMatchFailure( + unboxproc, "fir.unboxproc codegen is not implemented yet"); + } +}; + } // namespace namespace { @@ -2061,20 +2103,21 @@ AbsentOpConversion, AddcOpConversion, AddrOfOpConversion, AllocaOpConversion, BoxAddrOpConversion, BoxCharLenOpConversion, BoxDimsOpConversion, BoxEleSizeOpConversion, BoxIsAllocOpConversion, - BoxIsArrayOpConversion, BoxIsPtrOpConversion, BoxRankOpConversion, - BoxTypeDescOpConversion, CallOpConversion, CmpcOpConversion, - ConstcOpConversion, ConvertOpConversion, DispatchOpConversion, - DispatchTableOpConversion, DTEntryOpConversion, DivcOpConversion, - EmboxOpConversion, EmboxCharOpConversion, ExtractValueOpConversion, - HasValueOpConversion, GenTypeDescOpConversion, GlobalLenOpConversion, - GlobalOpConversion, InsertOnRangeOpConversion, InsertValueOpConversion, + BoxIsArrayOpConversion, BoxIsPtrOpConversion, BoxProcHostOpConversion, + BoxRankOpConversion, BoxTypeDescOpConversion, CallOpConversion, + CmpcOpConversion, ConstcOpConversion, ConvertOpConversion, + DispatchOpConversion, DispatchTableOpConversion, DTEntryOpConversion, + DivcOpConversion, EmboxOpConversion, EmboxCharOpConversion, + EmboxProcOpConversion, ExtractValueOpConversion, HasValueOpConversion, + GenTypeDescOpConversion, GlobalLenOpConversion, GlobalOpConversion, + InsertOnRangeOpConversion, InsertValueOpConversion, IsPresentOpConversion, LoadOpConversion, NegcOpConversion, MulcOpConversion, SelectCaseOpConversion, SelectOpConversion, SelectRankOpConversion, SelectTypeOpConversion, ShapeOpConversion, ShapeShiftOpConversion, ShiftOpConversion, SliceOpConversion, StoreOpConversion, StringLitOpConversion, SubcOpConversion, - UnboxCharOpConversion, UndefOpConversion, UnreachableOpConversion, - ZeroOpConversion>(typeConverter); + UnboxCharOpConversion, UnboxProcOpConversion, UndefOpConversion, + UnreachableOpConversion, ZeroOpConversion>(typeConverter); mlir::populateStdToLLVMConversionPatterns(typeConverter, pattern); mlir::arith::populateArithmeticToLLVMConversionPatterns(typeConverter, pattern); diff --git a/flang/lib/Optimizer/CodeGen/TypeConverter.h b/flang/lib/Optimizer/CodeGen/TypeConverter.h --- a/flang/lib/Optimizer/CodeGen/TypeConverter.h +++ b/flang/lib/Optimizer/CodeGen/TypeConverter.h @@ -54,6 +54,11 @@ LLVM_DEBUG(llvm::dbgs() << "type convert: " << boxchar << '\n'); return convertType(specifics->boxcharMemoryType(boxchar.getEleTy())); }); + addConversion([&](BoxProcType boxproc) { + // TODO: Support for this type will be added later when the Fortran 2003 + // procedure pointer feature is implemented. + return llvm::None; + }); addConversion( [&](fir::CharacterType charTy) { return convertCharType(charTy); }); addConversion([&](HeapType heap) { return convertPointerLike(heap); }); diff --git a/flang/test/Fir/convert-to-llvm-invalid.fir b/flang/test/Fir/convert-to-llvm-invalid.fir --- a/flang/test/Fir/convert-to-llvm-invalid.fir +++ b/flang/test/Fir/convert-to-llvm-invalid.fir @@ -148,3 +148,28 @@ %1 = fir.array_coor %arg0(%0) %i, %j : (!fir.ref>, !fir.shapeshift<2>, index, index) -> !fir.ref return } + +// ----- + +// Test that the type `fir.boxproc` fails to be legalized. +// Not implemented yet. + +// expected-error@+1{{failed to legalize operation 'builtin.func'}} +func private @foo0(%arg0: !fir.boxproc<() -> ()>) + +// ----- + +// Test that `fir.emboxproc` fails to be legalized. +// Not implemented yet. + +func private @method_impl(i32) + +func @emboxproc_test() { + %host_vars = fir.alloca tuple +// expected-error@+1{{failed to legalize operation 'fir.emboxproc'}} + %bproc = fir.emboxproc @method_impl, %host_vars : ((i32) -> (), !fir.ref>) -> !fir.boxproc<(i32) -> ()> + return +} + +// Test that `fir.unboxproc` and `fir.boxproc_host` also fails to be legalized. +// At the moment these cannot be tested since the `fir.boxproc` type does not have a conversion.