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.
This commit is contained in:
parent
f5a2d78072
commit
c86c95edd1
2 changed files with 22 additions and 0 deletions
|
@ -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;
|
||||
|
||||
|
|
16
gcc/testsuite/gcc.dg/pr101741.c
Normal file
16
gcc/testsuite/gcc.dg/pr101741.c
Normal file
|
@ -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;
|
||||
}
|
Loading…
Add table
Reference in a new issue