https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122754
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrew Pinski <[email protected]>: https://gcc.gnu.org/g:c760057058e512027fe6662ed3088313f4dc5cb6 commit r16-5430-gc760057058e512027fe6662ed3088313f4dc5cb6 Author: Andrew Pinski <[email protected]> Date: Tue Nov 18 18:16:02 2025 -0800 gimple: fix strlen+more for references I found that the strlen pass ignores stores via references. This shows up with C++ code more than C. A simple: ``` int g(void) { std::string a="a"; return __builtin_strlen(a.c_str()); } ``` Should be optimized to just `return 1` but does not currently due to use of references. The problem in the code is direct comparison with POINTER_TYPE instead of using POINTER_TYPE_P. This fixes the cases I found all related to strings passes. All of them were added by Martin Sebor which makes me think this was an oversight on his part. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/122754 gcc/ChangeLog: * gimple-fold.cc (get_range_strlen_tree): Use POINTER_TYPE_P instead of direct comparing to POINTER_TYPE. * gimple-ssa-sprintf.cc (format_integer): Likewise. * gimple-ssa-warn-access.cc (maybe_warn_nonstring_arg): Likewise. * gimple-ssa-warn-restrict.cc (pass_wrestrict::check_call): Likewise. * tree-ssa-strlen.cc (maybe_set_strlen_range): Likewise. (is_strlen_related_p): Likewise. (strlen_pass::handle_assign): Likewise. gcc/testsuite/ChangeLog: * g++.dg/tree-ssa/string-strlen-1.C: New test. Signed-off-by: Andrew Pinski <[email protected]>
