aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.cc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2025-03-11 08:40:44 +0100
committerRichard Biener <rguenth@gcc.gnu.org>2025-03-11 12:05:01 +0100
commit68932eeb38f66fbc0c3cf4b77ff7dde8a408f2e4 (patch)
treeee522c94a0cb127023651b54b094e97e900710de /gcc/builtins.cc
parent1b7a05770833eb210783ec8babd0027ec237d191 (diff)
downloadgcc-68932eeb38f66fbc0c3cf4b77ff7dde8a408f2e4.zip
gcc-68932eeb38f66fbc0c3cf4b77ff7dde8a408f2e4.tar.gz
gcc-68932eeb38f66fbc0c3cf4b77ff7dde8a408f2e4.tar.bz2
middle-end/119204 - ICE with strcspn folding
The following makes sure to convert the folded expression to the original expression type. PR middle-end/119204 * builtins.cc (fold_builtin_strcspn): Preserve the original expression type. * gcc.dg/pr119204.c: New testcase.
Diffstat (limited to 'gcc/builtins.cc')
-rw-r--r--gcc/builtins.cc5
1 files changed, 3 insertions, 2 deletions
diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index c884103..02556e6 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -11360,7 +11360,7 @@ fold_builtin_strcspn (location_t loc, tree expr, tree s1, tree s2)
{
/* Evaluate and ignore argument s2 in case it has
side-effects. */
- return omit_one_operand_loc (loc, size_type_node,
+ return omit_one_operand_loc (loc, TREE_TYPE (expr),
size_zero_node, s2);
}
@@ -11375,7 +11375,8 @@ fold_builtin_strcspn (location_t loc, tree expr, tree s1, tree s2)
if (!fn)
return NULL_TREE;
- return build_call_expr_loc (loc, fn, 1, s1);
+ return fold_convert_loc (loc, TREE_TYPE (expr),
+ build_call_expr_loc (loc, fn, 1, s1));
}
return NULL_TREE;
}