[clang] [CIR] Add the ability to detect enum argument for switch op (PR #172236)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 14 15:30:54 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
@llvm/pr-subscribers-clangir
Author: Jasmine Tang (badumbatish)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/172236.diff
3 Files Affected:
- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+3-1)
- (modified) clang/lib/CIR/CodeGen/CIRGenStmt.cpp (+1)
- (modified) clang/test/CIR/CodeGen/switch.cpp (+2-2)
``````````diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 868b813458aae..3b6f35ae96497 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -1216,7 +1216,8 @@ def CIR_SwitchOp : CIR_Op<"switch", [
let arguments = (ins
CIR_IntType:$condition,
- UnitAttr:$allEnumCasesCovered
+ UnitAttr:$allEnumCasesCovered,
+ UnitAttr:$handling_enum
);
let regions = (region AnyRegion:$body);
@@ -1230,6 +1231,7 @@ def CIR_SwitchOp : CIR_Op<"switch", [
let assemblyFormat = [{
`(` $condition `:` qualified(type($condition)) `)`
(`allEnumCasesCovered` $allEnumCasesCovered^)?
+ (`handling_enum` $handling_enum^)?
$body
attr-dict
}];
diff --git a/clang/lib/CIR/CodeGen/CIRGenStmt.cpp b/clang/lib/CIR/CodeGen/CIRGenStmt.cpp
index c7a95b34a0d6b..4a84376e8afd2 100644
--- a/clang/lib/CIR/CodeGen/CIRGenStmt.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenStmt.cpp
@@ -1106,6 +1106,7 @@ mlir::LogicalResult CIRGenFunction::emitSwitchStmt(const clang::SwitchStmt &s) {
terminateBody(builder, caseOp.getCaseRegion(), caseOp.getLoc());
terminateBody(builder, swop.getBody(), swop.getLoc());
+ swop.setHandlingEnum(s.getCond()->IgnoreParenImpCasts()->getType()->isEnumeralType());
swop.setAllEnumCasesCovered(s.isAllEnumCasesCovered());
return res;
diff --git a/clang/test/CIR/CodeGen/switch.cpp b/clang/test/CIR/CodeGen/switch.cpp
index b7bd2da5e39b8..8ca58e8ca1a5a 100644
--- a/clang/test/CIR/CodeGen/switch.cpp
+++ b/clang/test/CIR/CodeGen/switch.cpp
@@ -1282,7 +1282,7 @@ void testSwitchCoverAllCase(M m) {
break;
}
}
-// CIR: cir.switch(%[[ARG:.*]] : !s32i) allEnumCasesCovered {
+// CIR: cir.switch(%[[ARG:.*]] : !s32i) allEnumCasesCovered handling_enum {
void testSwitchNotCoverAllCase(M m) {
switch (m) {
@@ -1291,4 +1291,4 @@ void testSwitchNotCoverAllCase(M m) {
break;
}
}
-// CIR: cir.switch(%[[ARG:.*]] : !s32i) {
+// CIR: cir.switch(%[[ARG:.*]] : !s32i) handling_enum {
``````````
</details>
https://github.com/llvm/llvm-project/pull/172236
More information about the cfe-commits
mailing list