aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAndrew MacLeod <amacleod@redhat.com>2021-08-09 15:53:42 -0400
committerAndrew MacLeod <amacleod@redhat.com>2021-08-09 16:24:05 -0400
commitc86c95edd165d674614516cda0b1fcb6616c1096 (patch)
tree6913e1adb20c43817eff84403208ff1bf0ed58e2 /gcc
parentf5a2d78072fc161e8ca3117126030041f1503c3f (diff)
downloadgcc-c86c95edd165d674614516cda0b1fcb6616c1096.zip
gcc-c86c95edd165d674614516cda0b1fcb6616c1096.tar.gz
gcc-c86c95edd165d674614516cda0b1fcb6616c1096.tar.bz2
Ensure toupper and tolower follow the expected pattern.
If the parameter is not compatible with the LHS, assume this is not really a builtin function to avoid a trap. gcc/ PR tree-optimization/101741 * gimple-range-fold.cc (fold_using_range::range_of_builtin_call): Check type of parameter for toupper/tolower. gcc/testsuite/ * gcc.dg/pr101741.c: New.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gimple-range-fold.cc6
-rw-r--r--gcc/testsuite/gcc.dg/pr101741.c16
2 files changed, 22 insertions, 0 deletions
diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc
index 410bc4d..d3e3e14 100644
--- a/gcc/gimple-range-fold.cc
+++ b/gcc/gimple-range-fold.cc
@@ -894,6 +894,9 @@ fold_using_range::range_of_builtin_call (irange &r, gcall *call,
case CFN_BUILT_IN_TOUPPER:
{
arg = gimple_call_arg (call, 0);
+ // If the argument isn't compatible with the LHS, do nothing.
+ if (!range_compatible_p (type, TREE_TYPE (arg)))
+ return false;
if (!src.get_operand (r, arg))
return false;
@@ -913,6 +916,9 @@ fold_using_range::range_of_builtin_call (irange &r, gcall *call,
case CFN_BUILT_IN_TOLOWER:
{
arg = gimple_call_arg (call, 0);
+ // If the argument isn't compatible with the LHS, do nothing.
+ if (!range_compatible_p (type, TREE_TYPE (arg)))
+ return false;
if (!src.get_operand (r, arg))
return false;
diff --git a/gcc/testsuite/gcc.dg/pr101741.c b/gcc/testsuite/gcc.dg/pr101741.c
new file mode 100644
index 0000000..6587dca
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr101741.c
@@ -0,0 +1,16 @@
+/* PR tree-optimization/101741 */
+/* { dg-do compile } */
+/* { dg-options "-O2 " } */
+
+int
+foo (void);
+
+unsigned int
+toupper (int c)
+{
+ c = foo ();
+ while (c)
+ c = toupper (c);
+
+ return c;
+}