[clang] [CIR] Upstream support for switch statements case kinds (PR #138003)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu May 1 10:36:57 PDT 2025
================
@@ -428,6 +429,52 @@ mlir::LogicalResult CIRGenFunction::emitBreakStmt(const clang::BreakStmt &s) {
return mlir::success();
}
+const CaseStmt *CIRGenFunction::foldCaseStmt(const clang::CaseStmt &s,
+ mlir::Type condType,
+ mlir::ArrayAttr &value,
+ cir::CaseOpKind &kind) {
+ const CaseStmt *caseStmt = &s;
+ const CaseStmt *lastCase = &s;
+ SmallVector<mlir::Attribute, 4> caseEltValueListAttr;
+
+ // Fold cascading cases whenever possible to simplify codegen a bit.
+ while (caseStmt) {
+ lastCase = caseStmt;
+
+ auto intVal = caseStmt->getLHS()->EvaluateKnownConstInt(getContext());
+
+ if (auto *rhs = caseStmt->getRHS()) {
----------------
erichkeane wrote:
RHS is only valid for a GNU-range version of a case, do we have a test for that?
https://github.com/llvm/llvm-project/pull/138003
More information about the cfe-commits
mailing list