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 @@ -167,6 +167,18 @@ } }; +// convert to LLVM IR dialect `unreachable` +struct UnreachableOpConversion : public FIROpConversion { + using FIROpConversion::FIROpConversion; + + mlir::LogicalResult + matchAndRewrite(fir::UnreachableOp unreach, OpAdaptor adaptor, + mlir::ConversionPatternRewriter &rewriter) const override { + rewriter.replaceOpWithNewOp(unreach); + return success(); + } +}; + struct ZeroOpConversion : public FIROpConversion { using FIROpConversion::FIROpConversion; @@ -190,6 +202,7 @@ return success(); } }; + } // namespace namespace { @@ -207,8 +220,10 @@ auto *context = getModule().getContext(); fir::LLVMTypeConverter typeConverter{getModule()}; mlir::OwningRewritePatternList pattern(context); - pattern.insert(typeConverter); + pattern + .insert( + typeConverter); mlir::populateStdToLLVMConversionPatterns(typeConverter, pattern); mlir::arith::populateArithmeticToLLVMConversionPatterns(typeConverter, pattern); diff --git a/flang/test/Fir/convert-to-llvm.fir b/flang/test/Fir/convert-to-llvm.fir --- a/flang/test/Fir/convert-to-llvm.fir +++ b/flang/test/Fir/convert-to-llvm.fir @@ -133,3 +133,15 @@ // CHECK: %{{.*}} = llvm.mlir.constant(0.000000e+00 : f80) : f80 // CHECK: %{{.*}} = llvm.mlir.constant(0.000000e+00 : f128) : f128 // CHECK-NOT: fir.zero_bits + +// ----- + +// Verify that fir.unreachable is transformed to llvm.unreachable + +// CHECK: llvm.func @test_unreachable() { +// CHECK-NEXT: llvm.unreachable +// CHECK-NEXT: } + +func @test_unreachable() { + fir.unreachable +}