@@ -1185,6 +1185,53 @@ def check_help_flags() -> bool:
11851185 return ok
11861186
11871187
1188+ _SMT_BACKEND_UNAVAILABLE = "is not available in this build"
1189+
1190+
1191+ def check_smt_unavailable_backend_warning () -> bool :
1192+ """
1193+ `--smt=on` must say on stderr when a backend it uses is not compiled in. This run also
1194+ needs Z3: without it the dedicated smt-z3 fixture pass silently checks nothing.
1195+ """
1196+ print ("=== Testing SMT backend availability ===" )
1197+ if _runner_has_explicit_smt_args ():
1198+ print (" [info] skipped (runner already has --smt args)" )
1199+ print ()
1200+ return True
1201+
1202+ fixture = str (fixture_path_with_fallback ("integer-overflow/nsw-flag-must-not-discharge-itself.c" ))
1203+ # (analyzer arguments, backend that must be reported once, or None for no warning)
1204+ cases = [
1205+ (["--smt=on" , "--smt-backend=z3" ], None ),
1206+ (["--smt=on" , "--smt-backend=cvc5" ], "cvc5" ),
1207+ (["--smt=on" , "--smt-backend=Interval" ], None ),
1208+ (["--smt=on" , "--smt-mode=portfolio" , "--smt-secondary-backend=cvc5" ], "cvc5" ),
1209+ (["--smt=on" , "--smt-mode=single" , "--smt-secondary-backend=cvc5" ], None ),
1210+ (["--smt-backend=cvc5" , "--smt=off" ], None ),
1211+ ]
1212+ ok = True
1213+ for args , backend in cases :
1214+ result = run_analyzer ([* args , fixture ])
1215+ stderr = result .stderr or ""
1216+ warnings = stderr .count (_SMT_BACKEND_UNAVAILABLE )
1217+ label = " " .join (args )
1218+ if _SMT_BACKEND_UNAVAILABLE in (result .stdout or "" ):
1219+ print (f" ❌ { label } : the warning must go to stderr, not stdout" )
1220+ ok = False
1221+ elif backend is None and warnings :
1222+ print (f" ❌ { label } : unexpected warning" )
1223+ if "SMT backend 'z3'" in stderr :
1224+ print (" this analyzer has no Z3: install it (libz3-dev or brew z3) and rebuild" )
1225+ ok = False
1226+ elif backend is not None and (warnings != 1 or f"SMT backend '{ backend } '" not in stderr ):
1227+ print (f" ❌ { label } : expected one warning for '{ backend } ', got { warnings } " )
1228+ ok = False
1229+ if ok :
1230+ print (" ✅ SMT backend availability OK" )
1231+ print ()
1232+ return ok
1233+
1234+
11881235def check_multi_file_json () -> bool :
11891236 """
11901237 Check that analysis accepts multiple files and JSON aggregates correctly.
@@ -3440,6 +3487,7 @@ def record_ok(ok: bool):
34403487 # after the pool completes.
34413488 parallel_checks = [
34423489 check_help_flags ,
3490+ check_smt_unavailable_backend_warning ,
34433491 check_analyzer_module_unit_tests ,
34443492 check_multi_file_json ,
34453493 check_multi_file_total_summary ,
0 commit comments