public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Andrew Macleod <amacleod@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-2519] Confirm and Handle only ASCII in toupper and tolower ranges. Date: Mon, 26 Jul 2021 23:31:45 +0000 (GMT) [thread overview] Message-ID: <20210726233145.DF0C83886C45@sourceware.org> (raw) https://gcc.gnu.org/g:d5a8c1382718ae084d46ff9b8a26d6b1d0cb684c commit r12-2519-gd5a8c1382718ae084d46ff9b8a26d6b1d0cb684c Author: Andrew MacLeod <amacleod@redhat.com> Date: Mon Jul 26 17:25:06 2021 -0400 Confirm and Handle only ASCII in toupper and tolower ranges. PR tree-optimization/78888 * gimple-range-fold.cc (get_letter_range): New. (fold_using_range::range_of_builtin_call): Call get_letter_range. Diff: --- gcc/gimple-range-fold.cc | 49 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index 8465b4a82f6..410bc4ddca4 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,28 @@ 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)) + { + 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)); + return true; + } + // Unknown character set. + return false; +} + // For a builtin in CALL, return a range in R if known and return // TRUE. Otherwise return FALSE. @@ -873,13 +896,16 @@ fold_using_range::range_of_builtin_call (irange &r, gcall *call, arg = gimple_call_arg (call, 0); if (!src.get_operand (r, arg)) return false; + + int_range<3> lowers; + int_range<3> uppers; + if (!get_letter_range (type, lowers, uppers)) + return false; + // Return the range passed in without any lower case characters, // but including all the upper case ones. - int_range<2> exclude (build_int_cst (type, 'a'), - build_int_cst (type, 'z'), VR_ANTI_RANGE); - r.intersect (exclude); - int_range<2> uppers (build_int_cst (type, 'A'), - build_int_cst (type, 'Z')); + lowers.invert (); + r.intersect (lowers); r.union_ (uppers); return true; } @@ -889,13 +915,16 @@ fold_using_range::range_of_builtin_call (irange &r, gcall *call, arg = gimple_call_arg (call, 0); if (!src.get_operand (r, arg)) return false; + + int_range<3> lowers; + int_range<3> uppers; + if (!get_letter_range (type, lowers, uppers)) + return false; + // Return the range passed in without any upper case characters, // but including all the lower case ones. - int_range<2> exclude (build_int_cst (type, 'A'), - build_int_cst (type, 'Z'), VR_ANTI_RANGE); - r.intersect (exclude); - int_range<2> lowers (build_int_cst (type, 'a'), - build_int_cst (type, 'z')); + uppers.invert (); + r.intersect (uppers); r.union_ (lowers); return true; }
reply other threads:[~2021-07-26 23:31 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210726233145.DF0C83886C45@sourceware.org \ --to=amacleod@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).