On Mon, Jul 26, 2021 at 04:57:14PM -0400, Andrew MacLeod wrote:
>     Handle ASCII and EBCDIC in toupper and tolower ranges.
>     
>             gcc/
>             PR tree-optimization/78888
>             * gimple-range-fold.cc (get_letter_range): New.
>             (fold_using_range::range_of_builtin_call): Call get_letter_range.
>     
>             gcc/testsuite/
>             * gcc.dg/pr78888.c: Add extra non-standard verifications.
> 
> diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc
> index 8465b4a82f6..a952f693c77 100644
> --- a/gcc/gimple-range-fold.cc
> +++ b/gcc/gimple-range-fold.cc
> @@ -37,6 +37,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "cfgloop.h"
>  #include "tree-ssa-loop.h"
>  #include "tree-scalar-evolution.h"
> +#include "langhooks.h"
>  #include "vr-values.h"
>  #include "range.h"
>  #include "value-query.h"
> @@ -835,6 +836,30 @@ fold_using_range::range_of_builtin_ubsan_call (irange 
> &r, gcall *call,
>      r.set_varying (type);
>  }
>  
> +// Return TRUE if we recognize the target character set and return the
> +// range for lower case and upper case letters.
> +
> +static bool
> +get_letter_range (tree type, irange &lowers, irange &uppers)
> +{
> +  // ASCII
> +  int a = lang_hooks.to_target_charset ('a');
> +  int z = lang_hooks.to_target_charset ('z');
> +  int A = lang_hooks.to_target_charset ('A');
> +  int Z = lang_hooks.to_target_charset ('Z');
> +
> +  if ((z - a == 25) && (Z - A == 25))

I would leave the extraneous ()s around both comparisons.

> +    {
> +      lowers = int_range<2> (build_int_cst (type, 'a'),
> +                           build_int_cst (type, 'z'));
> +      uppers = int_range<2> (build_int_cst (type, 'A'),
> +                          build_int_cst (type, 'Z'));

Here you should use a, z, A and Z instead of 'a', etc.
It is the target values, not the host ones you care about.
So e.g. in the unlikely case host is EBCDIC and target ASCII,
the above would still create weirdo ranges...

Otherwise LGTM.

        Jakub

Reply via email to