From c86c95edd165d674614516cda0b1fcb6616c1096 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Mon, 9 Aug 2021 15:53:42 -0400 Subject: 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. --- gcc/gimple-range-fold.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gcc/gimple-range-fold.cc') 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; -- cgit v1.1