3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-08-02 20:23:27 +00:00

Make implicit switch case fall-throughs explicit (#10284)

This is another PR towards the goal of getting Z3 to compile cleanly
when included via FetchContents into clang-tidy, which uses a pretty
strict set of warnings.

This PR enable the "-Wimplicit-fallthrough" warning, then fix all the
warnings this gets
in the clang build, by:
* Augmenting UNREACHABLE to add __builtin_unreachable(), which
suppresses
warnings for fallthrough in that cse.
* Adding Z3_fallthrough in many cases, to make it clear that
fallthroughs are intentional.
* Adding [[noreturn]] to functions that throw, so the compiler knows
they don't fall through to the next case.
* In a couple of cases, there's a fall-through to a default case, which
does "break", or "return nullptr". In those cases, I duplicated the
action in the preceding case, to make it more self-contained, and robust
in the face of change.

In some cases, I am concerned about whether the warnings are identifying
real bugs. For example, the fall-throughs in these files seem at least a
little suspect:
nnf.cpp
seq_rewriter.cpp
lar_solver.cpp 

while very probably correct, also seem at least a tiny bit suspect.
However, this PR does *not* attempt to change any behavior, only to
silence the warnings. It would be great if somebody with more knowledge
of the code could vet these cases. If vetted, the explicit presence of
the Z3_fallthrough would reassure future readers of the code that the
fall-through is intentional, not accidental.
This commit is contained in:
davedets 2026-07-29 09:05:42 -07:00 committed by GitHub
parent 1c89937473
commit d46fbad3b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 42 additions and 8 deletions

View file

@ -480,6 +480,7 @@ struct aig_manager::imp {
case OP_EQ:
if (!m.m().is_bool(tapp->get_arg(0)))
break;
Z3_fallthrough;
case OP_NOT:
case OP_OR:
case OP_AND:
@ -1272,10 +1273,12 @@ struct aig_manager::imp {
fr.m_idx++;
if (!visit(left(n)))
goto start;
Z3_fallthrough;
case 1:
fr.m_idx++;
if (!visit(right(n)))
goto start;
Z3_fallthrough;
default:
if (!is_cached(n))
improve_sharing(n);

View file

@ -135,7 +135,7 @@ struct has_nlmul {
arith_util a;
has_nlmul(ast_manager& m):m(m), a(m) {}
void throw_found(expr* e) {
[[noreturn]] void throw_found(expr* e) {
TRACE(probe, tout << expr_ref(e, m) << ": " << sort_ref(e->get_sort(), m) << "\n";);
throw found();
}

View file

@ -763,6 +763,7 @@ class elim_uncnstr_tactic : public tactic {
}
return r;
}
return nullptr;
default:
return nullptr;
}

View file

@ -95,7 +95,7 @@ class tseitin_cnf_tactic : public tactic {
void push_frame(app * n) { m_frame_stack.push_back(frame(n)); }
void throw_op_not_handled() {
[[noreturn]] void throw_op_not_handled() {
throw tactic_exception("operator not supported, apply simplifier before invoking this strategy");
}