https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98447
--- Comment #11 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by David Malcolm <[email protected]>: https://gcc.gnu.org/g:498fb8a24516b10897dfbe08bb8f7574b2d28839 commit r16-7365-g498fb8a24516b10897dfbe08bb8f7574b2d28839 Author: David Malcolm <[email protected]> Date: Fri Feb 6 10:54:52 2026 -0500 analyzer: use value_range and range_op in eval_condition [PR98447] PR analyzer/98447 covers a false positive from -fanalyzer. The root cause is that the analyzer's constraint-handling code doesn't "know" that if X := Y % 64, then X < 64. This patch adds some minimal usage of value_range and range_op to -fanalyzer. It adds a new svalue::maybe_get_value_range vfunc, which attempts to get a value_range for an svalue (but bails out for awkward cases), and if value_ranges are available, uses them in eval_condition to determine if the result is known based on range_op. Doing so fixes the above false positive, improves a couple of other tests in the DejaGnu testsuite, and eliminates 31 false +ves in the analyzer integration testsuite (out of ~2200), along with a slight speedup to the latter (albeit testing with a debug build of gcc). A deeper integration with ranger could probably be made, but that is clearly stage 1 material. gcc/analyzer/ChangeLog: PR analyzer/98447 * common.h: Include "value-range.h". * region-model.cc: Include "value-relation.h" and "range-op.h". (region_model::eval_condition): Try using range_op to see if we can get a known boolean from the value_ranges of the operands. * svalue.cc: Include "value-relation.h" and "range-op.h". (type_can_have_value_range_p): New. (svalue::maybe_get_value_range): New. (constant_svalue::maybe_get_value_range): New. (unknown_svalue::maybe_get_value_range): New. (unaryop_svalue::maybe_get_value_range): New. (binop_svalue::maybe_get_value_range): New. * svalue.h (svalue::maybe_get_value_range): New vfunc decl. (constant_svalue::maybe_get_value_range): New decl. (unknown_svalue::maybe_get_value_range): New decl. (unaryop_svalue::maybe_get_value_range): New decl. (binop_svalue::maybe_get_value_range): New decl. gcc/testsuite/ChangeLog: PR analyzer/98447 * c-c++-common/analyzer/conditionals-pr98447-1.c: New test. * c-c++-common/analyzer/conditionals-pr98447-2.c: New test. * c-c++-common/analyzer/null-deref-pr108400-SoftEtherVPN-WebUi.c: Updated for false positive being fixed for C. * gcc.dg/analyzer/data-model-1.c: Update expected output to reflect improved output. Signed-off-by: David Malcolm <[email protected]>
