3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-08-03 04:33:28 +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

@ -2116,6 +2116,7 @@ namespace smt {
switch(ctx.get_assignment(c.lit(i))) {
case l_true:
++sum;
Z3_fallthrough;
case l_undef:
++maxsum;
break;
@ -2147,6 +2148,7 @@ namespace smt {
switch(ctx.get_assignment(c.lit(i))) {
case l_true:
sum += c.coeff(i);
Z3_fallthrough;
case l_undef:
maxsum += c.coeff(i);
break;