diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -2797,8 +2797,8 @@ ```mlir global @g : !fir.type { fir.global_len len1, 10 : i32 - %1 = fir.undefined : !fir.type - return %1 : !fir.type + %1 = fir.undefined !fir.type + fir.has_value %1 : !fir.type } ``` }]; 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 @@ -636,6 +636,18 @@ } }; +/// Lower `fir.global_len` operation. +struct GlobalLenOpConversion : public FIROpConversion { + using FIROpConversion::FIROpConversion; + + mlir::LogicalResult + matchAndRewrite(fir::GlobalLenOp globalLen, OpAdaptor adaptor, + mlir::ConversionPatternRewriter &rewriter) const override { + return rewriter.notifyMatchFailure( + globalLen, "fir.global_len codegen is not implemented yet"); + } +}; + /// Lower `fir.has_value` operation to `llvm.return` operation. struct HasValueOpConversion : public FIROpConversion { using FIROpConversion::FIROpConversion; @@ -1504,8 +1516,8 @@ BoxIsPtrOpConversion, BoxRankOpConversion, CallOpConversion, ConvertOpConversion, DispatchOpConversion, DispatchTableOpConversion, DTEntryOpConversion, DivcOpConversion, EmboxCharOpConversion, - ExtractValueOpConversion, HasValueOpConversion, GlobalOpConversion, - InsertOnRangeOpConversion, InsertValueOpConversion, + ExtractValueOpConversion, HasValueOpConversion, GlobalLenOpConversion, + GlobalOpConversion, InsertOnRangeOpConversion, InsertValueOpConversion, IsPresentOpConversion, LoadOpConversion, NegcOpConversion, MulcOpConversion, SelectCaseOpConversion, SelectOpConversion, SelectRankOpConversion, SelectTypeOpConversion, StoreOpConversion, 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 @@ -72,3 +72,14 @@ %zero = arith.constant 0 : i32 return %zero : i32 } + +// ----- + +// Test `fir.global_len` conversion failure. Not implemented yet. + +fir.global @global_derived : !fir.type { + // expected-error@+1{{failed to legalize operation 'fir.global_len'}} + fir.global_len f, 1 : i32 + %0 = fir.undefined !fir.type + fir.has_value %0 : !fir.type +}