================ @@ -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()); ---------------- erichkeane wrote:
I don't have a good idea? perhaps in the pass manager or whatever pass we expect to do this? 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