[clang] [CIR] Upstream support for switch statements case kinds (PR #138003)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Mon May 5 11:57:35 PDT 2025
================
@@ -515,19 +516,46 @@ CIRGenFunction::emitCaseDefaultCascade(const T *stmt, mlir::Type condType,
mlir::LogicalResult CIRGenFunction::emitCaseStmt(const CaseStmt &s,
mlir::Type condType,
bool buildingTopLevelCase) {
- llvm::APSInt intVal = s.getLHS()->EvaluateKnownConstInt(getContext());
+ cir::CaseOpKind kind;
+ mlir::ArrayAttr value;
+
SmallVector<mlir::Attribute, 1> caseEltValueListAttr;
- caseEltValueListAttr.push_back(cir::IntAttr::get(condType, intVal));
- mlir::ArrayAttr value = builder.getArrayAttr(caseEltValueListAttr);
- if (s.getRHS()) {
- getCIRGenModule().errorNYI(s.getSourceRange(), "SwitchOp range kind");
- return mlir::failure();
+ llvm::APSInt intVal = s.getLHS()->EvaluateKnownConstInt(getContext());
+
+ // If the case statement has an RHS value, it is representing a GNU
+ // case range statement, where LHS is the beginning of the range
+ // and RHS is the end of the range.
+ if (const Expr *rhs = s.getRHS()) {
+
+ llvm::APSInt endVal = rhs->EvaluateKnownConstInt(getContext());
+ SmallVector<mlir::Attribute, 4> rangeCaseAttr = {
+ cir::IntAttr::get(condType, intVal),
+ cir::IntAttr::get(condType, endVal)};
+ value = builder.getArrayAttr(rangeCaseAttr);
----------------
andykaylor wrote:
```suggestion
value = builder.getArrayAttr({
cir::IntAttr::get(condType, intVal),
cir::IntAttr::get(condType, endVal)
});
```
https://github.com/llvm/llvm-project/pull/138003
More information about the cfe-commits
mailing list