================
@@ -515,19 +517,44 @@ 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);
+    kind = cir::CaseOpKind::Range;
+
+    // We don't currently fold case range statements with other case 
statements.
+    // TODO(cir): Add this capability.
+    assert(!cir::MissingFeatures::foldRangeCase());
----------------
Andres-Salamanca wrote:

I left it there as a reminder to fold the ranges in the future, but you're 
right  it's not appropriate in this spot. Is there a better place to leave the 
comment instead?

https://github.com/llvm/llvm-project/pull/138003
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to