https://gcc.gnu.org/g:7a1b120e3653f6a4993f3ae2557b5744679d0131
commit r17-6647-g7a1b120e3653f6a4993f3ae2557b5744679d0131 Author: Torbjörn SVENSSON <[email protected]> Date: Mon Nov 23 18:18:04 2026 +0100 analyzer: ignore qualifiers when checking for casts Since r17-6246-g7647c00b77ee1a, copies that differ only in qualifiers can lead to bogus -Wanalyzer-allocation-size warnings, because is_any_cast_p treats them as casts. Copying "this", a "T *const", into a "T *" temporary is one example. This shows up on arm-none-eabi, where constructors return "this", which leads to such copies. This fixes: FAIL: g++.dg/analyzer/out-of-bounds-placement-new.C -std=c++20 (test for excess errors) FAIL: g++.dg/analyzer/out-of-bounds-placement-new.C -std=c++29 (test for excess errors) FAIL: g++.dg/analyzer/out-of-bounds-placement-new.C -std=c++98 (test for excess errors) gcc/analyzer/ChangeLog: * region-model.cc (is_any_cast_p): Compare the main variants of the lhs and rhs types. Signed-off-by: Torbjörn SVENSSON <[email protected]> Diff: --- gcc/analyzer/region-model.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index 24101bbf6190..94e0589f8028 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -3799,7 +3799,8 @@ struct_or_union_with_inheritance_p (tree struc) return false; } -/* Return true if the lhs and rhs of an assignment have different types. */ +/* Return true if the lhs and rhs of an assignment have different types, + ignoring qualifiers and typedefs. */ static bool is_any_cast_p (const gimple *stmt) @@ -3807,14 +3808,14 @@ is_any_cast_p (const gimple *stmt) if (const gassign *assign = dyn_cast <const gassign *> (stmt)) return gimple_assign_cast_p (assign) || !pending_diagnostic::same_tree_p ( - TREE_TYPE (gimple_assign_lhs (assign)), - TREE_TYPE (gimple_assign_rhs1 (assign))); + TYPE_MAIN_VARIANT (TREE_TYPE (gimple_assign_lhs (assign))), + TYPE_MAIN_VARIANT (TREE_TYPE (gimple_assign_rhs1 (assign)))); else if (const gcall *call = dyn_cast <const gcall *> (stmt)) { tree lhs = gimple_call_lhs (call); return lhs != NULL_TREE && !pending_diagnostic::same_tree_p ( - TREE_TYPE (gimple_call_lhs (call)), - gimple_call_return_type (call)); + TYPE_MAIN_VARIANT (TREE_TYPE (lhs)), + TYPE_MAIN_VARIANT (gimple_call_return_type (call))); } return false;
