[flang-commits] [flang] 3f0f834 - [flang] fix codegen of fir.select with only default case (#181373)
via flang-commits
flang-commits at lists.llvm.org
Mon Feb 16 01:30:33 PST 2026
Author: jeanPerier
Date: 2026-02-16T10:30:28+01:00
New Revision: 3f0f8349ac9dc3d1f245912121207b5465a08473
URL: https://github.com/llvm/llvm-project/commit/3f0f8349ac9dc3d1f245912121207b5465a08473
DIFF: https://github.com/llvm/llvm-project/commit/3f0f8349ac9dc3d1f245912121207b5465a08473.diff
LOG: [flang] fix codegen of fir.select with only default case (#181373)
The case where fir.select only has a "unit" block target (i.e., it is a
switch with only the default case) was not handled correctly in codegen.
Added:
Modified:
flang/lib/Optimizer/CodeGen/CodeGen.cpp
flang/test/Fir/select.fir
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 625701725003f..f9d469f869619 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -3750,6 +3750,14 @@ struct SelectOpConversionBase : public fir::FIROpConversion<OP> {
defaultDestination = *convertedBlock;
}
+ // Deal with the case where there is only a default destination. Handle it
+ // now because emitting empty case values is not legal.
+ if (caseValues.empty()) {
+ rewriter.replaceOpWithNewOp<mlir::LLVM::BrOp>(select, defaultOperands,
+ defaultDestination);
+ return mlir::success();
+ }
+
selector =
this->integerCast(loc, rewriter, rewriter.getI64Type(), selector);
diff --git a/flang/test/Fir/select.fir b/flang/test/Fir/select.fir
index 5e88048446407..b342b7cff1c6a 100644
--- a/flang/test/Fir/select.fir
+++ b/flang/test/Fir/select.fir
@@ -67,3 +67,17 @@ func.func @h(%a : i32) -> i32 {
// CHECK: ret i32
return %x : i32
}
+
+func.func @empty_cases(%arg0 : i32) {
+ fir.select %arg0 : i32 [unit, ^bb1]
+^bb1: // pred: ^bb0
+ fir.call @crash() fastmath<contract> : () -> ()
+ fir.unreachable
+}
+func.func private @crash()
+
+//CHECK-LABEL: @empty_cases(i32 %0) {
+//CHECK: br label %[[BLOCK:.*]]
+//CHECK: [[BLOCK]]:
+//CHECK: call void @crash()
+//CHECK: unreachable
More information about the flang-commits
mailing list