Skip to content

Commit 1fe966e

Browse files
Add early return after NYI to prevent crashes
1 parent 91a1051 commit 1fe966e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

clang/lib/CIR/CodeGen/CIRGenStmt.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,10 @@ CIRGenFunction::emitCaseDefaultCascade(const T *stmt, mlir::Type condType,
493493
// simple form later since the conversion itself should be harmless.
494494
if (subStmtKind == SubStmtKind::Case)
495495
result = emitCaseStmt(*cast<CaseStmt>(sub), condType, buildingTopLevelCase);
496-
else if (subStmtKind == SubStmtKind::Default)
496+
else if (subStmtKind == SubStmtKind::Default) {
497497
getCIRGenModule().errorNYI(sub->getSourceRange(), "Default case");
498-
else if (buildingTopLevelCase)
498+
return mlir::failure();
499+
} else if (buildingTopLevelCase)
499500
// If we're building a top level case, try to restore the insert point to
500501
// the case we're building, then we can attach more random stmts to the
501502
// case to make generating `cir.switch` operation to be a simple form.
@@ -513,6 +514,7 @@ mlir::LogicalResult CIRGenFunction::emitCaseStmt(const CaseStmt &s,
513514
mlir::ArrayAttr value = builder.getArrayAttr(caseEltValueListAttr);
514515
if (s.getRHS()) {
515516
getCIRGenModule().errorNYI(s.getSourceRange(), "SwitchOp range kind");
517+
return mlir::failure();
516518
}
517519
assert(!cir::MissingFeatures::foldCaseStmt());
518520
return emitCaseDefaultCascade(&s, condType, value, cir::CaseOpKind::Equal,
@@ -528,8 +530,10 @@ mlir::LogicalResult CIRGenFunction::emitSwitchCase(const SwitchCase &s,
528530
return emitCaseStmt(cast<CaseStmt>(s), condTypeStack.back(),
529531
buildingTopLevelCase);
530532

531-
if (s.getStmtClass() == Stmt::DefaultStmtClass)
533+
if (s.getStmtClass() == Stmt::DefaultStmtClass) {
532534
getCIRGenModule().errorNYI(s.getSourceRange(), "Default case");
535+
return mlir::failure();
536+
}
533537

534538
llvm_unreachable("expect case or default stmt");
535539
}
@@ -724,7 +728,7 @@ mlir::LogicalResult CIRGenFunction::emitSwitchBody(const Stmt *s) {
724728
// ...
725729
// }
726730
if (!isa<CompoundStmt>(s))
727-
return emitStmt(s, /*useCurrentScope=*/!false);
731+
return emitStmt(s, /*useCurrentScope=*/true);
728732

729733
auto *compoundStmt = cast<CompoundStmt>(s);
730734

0 commit comments

Comments
 (0)