analyzer: fix ICE due to sloppy types in unaryop_svalue [PR124104]

gcc/analyzer/ChangeLog:
	PR analyzer/124104
	* svalue.cc (unaryop_svalue::maybe_get_value_range): Bail out for
	incompatible types.

gcc/testsuite/ChangeLog:
	PR analyzer/124104
	* c-c++-common/analyzer/casts-3.c: New test.
	* gcc.dg/analyzer/ice-pr124104.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
This commit is contained in:
David Malcolm
2026-02-17 18:04:17 -05:00
parent 5869ac36fa
commit f310e487e1
3 changed files with 24 additions and 1 deletions

View File

@@ -1585,7 +1585,8 @@ unaryop_svalue::maybe_get_value_range (value_range &out) const
if (m_arg->maybe_get_value_range (arg_vr))
{
range_op_handler handler (m_op);
if (handler)
if (handler
&& handler.operand_check_p (type, arg_vr.type (), type))
{
/* For unary ops, range_op_hander::fold_range expects
a VARYING of the unknown value as the 2nd operand. */

View File

@@ -0,0 +1,13 @@
#include "analyzer-decls.h"
static int __attribute__((noipa))
as_int (unsigned char c)
{
return c;
}
void test_1 (unsigned char c)
{
__analyzer_eval (as_int (c) >= 0); /* { dg-warning "TRUE" } */
__analyzer_eval (as_int (c) < 256); /* { dg-warning "TRUE" } */
}

View File

@@ -0,0 +1,9 @@
short s;
short
foo()
{
short t = 0;
__atomic_fetch_sub(&t, s, 0);
return t ?: 5;
}