https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119219
--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-13 branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:997b3e922f57219b6cc1f293bb57a84468fd5d9e commit r13-9599-g997b3e922f57219b6cc1f293bb57a84468fd5d9e Author: Jakub Jelinek <ja...@redhat.com> Date: Wed Mar 12 08:27:17 2025 +0100 builtins: Fix up strspn/strcspn folding [PR119219] The PR119204 r15-7955 fix caused some regressions. The problem is that the fold_builtin* APIs document that expr is either a CALL_EXPR of the call or NULL, so using TREE_TYPE (expr) can crash e.g. during constexpr evaluation etc. As can be seen in the surrounding patch, for the neighbouring builtins (both modf and strpbrk) fold_builtin_2 passes down type, which is the result type, TREE_TYPE (TREE_TYPE (fndecl)) and those builtins use it to build the return value, while strspn was always building size_type_node and strcspn had this change from that to TREE_TYPE (expr). The patch passes type to these two and uses it there as well. The patch keeps passing expr because it is used in the check_nul_terminated_array calls done for both strspn and strcspn, those calls clearly can deal with NULL expr but prefer if it is non-NULL for some warning. 2025-03-12 Jakub Jelinek <ja...@redhat.com> PR middle-end/119204 PR middle-end/119219 * builtins.cc (fold_builtin_2): Pass type as another argument to fold_builtin_strspn and fold_builtin_strcspn. (fold_builtin_strspn): Add type argument, use it instead of size_type_node. (fold_builtin_strcspn): Add type argument, use it instead of TREE_TYPE (expr). (cherry picked from commit da967f0ff324053304b350fdb18384607a346ebd)