Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion failure on switch statement with code outside a case #521

Open
dkolsen-pgi opened this issue Mar 24, 2024 · 1 comment
Open

Assertion failure on switch statement with code outside a case #521

dkolsen-pgi opened this issue Mar 24, 2024 · 1 comment

Comments

@dkolsen-pgi
Copy link
Collaborator

ClangIR hits an assertion failure when a switch statement contains code that is not covered by a case label.

int f(int x) {
  switch (x) {
    return 0; // Dead code
  case 1:
    return -1;
  }
  return x;
}
clang++: .../clang/lib/CIR/CodeGen/CIRGenStmt.cpp:974: 
cir::CIRGenFunction::buildSwitchStmt(const clang::SwitchStmt&)::<lambda()>::<lambda(mlir::OpBuilder&, mlir::Location, mlir::OperationState&)>: 
Assertion `lastCaseBlock && "expects pre-existing case block"' failed.

While code like this should never appear in production and will only ever be found in test suites that try to break the compiler, it is legal code in both C and C++ and should not trigger an internal compiler error.

@smeenai
Copy link
Collaborator

smeenai commented Sep 6, 2024

Note that code outside a case isn't necessarily dead, because you can do things like https://godbolt.org/z/PqEGzKEzb to reach it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants