https://gcc.gnu.org/g:d8b136429f5df8e1a8435ee665cce803f58a596d
commit r17-6649-gd8b136429f5df8e1a8435ee665cce803f58a596d Author: Torbjörn SVENSSON <[email protected]> Date: Mon Nov 23 19:27:00 2026 +0100 analyzer: strip casts from representative tree after fixup Since r17-6246-g7647c00b77ee1a, get_representative_tree can return a cast. Casts are stripped before fixup_tree_for_diagnostic is called, but the fixup can rebuild a temporary from its defining statement. If that statement is a conversion, the result is a new top-level cast. For example, the taint warning for "malloc (num * 16)" says '(unsigned int)(num * 16)' instead of 'num * 16'. Strip casts again after the fixup. This fixes: FAIL: gcc.dg/analyzer/taint-alloc-1.c (test for warnings, line 62) FAIL: gcc.dg/analyzer/taint-alloc-1.c (test for excess errors) FAIL: gcc.dg/analyzer/taint-alloc-2.c (test for excess errors) FAIL: gcc.dg/analyzer/taint-alloc-2.c final event with expr at line 22 (test for warnings, line 21) FAIL: gcc.dg/analyzer/taint-alloc-2.c warning (test for warnings, line 21) FAIL: gcc.dg/analyzer/taint-alloc-5.c (test for excess errors) FAIL: gcc.dg/analyzer/taint-alloc-5.c final event with expr at line 17 (test for warnings, line 16) FAIL: gcc.dg/analyzer/taint-alloc-5.c warning (test for warnings, line 16) gcc/analyzer/ChangeLog: * region-model.cc (region_model::get_representative_tree): Also strip top-level casts after calling fixup_tree_for_diagnostic. Signed-off-by: Torbjörn SVENSSON <[email protected]> Diff: --- gcc/analyzer/region-model.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index 94e0589f8028..1269e5320c8c 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -5346,7 +5346,13 @@ region_model::get_representative_tree (const svalue *sval, logger *logger) const while (expr && TREE_CODE (expr) == NOP_EXPR) expr = TREE_OPERAND (expr, 0); - return fixup_tree_for_diagnostic (expr); + expr = fixup_tree_for_diagnostic (expr); + + /* The fixup can add a cast; strip it too. */ + while (expr && TREE_CODE (expr) == NOP_EXPR) + expr = TREE_OPERAND (expr, 0); + + return expr; } tree
