From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Piotr Trojanek <trojanek@adacore.com>
Subject: [Ada] Remove redundant explicit calls to UI_From_Int in comparisons
Date: Wed, 5 May 2021 04:20:05 -0400 [thread overview]
Message-ID: <20210505082005.GA31215@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 658 bytes --]
Relational operators for universal integers come in three variants, e.g.:
function "=" (Left : Uint; Right : Uint) return Boolean renames UI_Eq;
function "=" (Left : Int; Right : Uint) return Boolean renames UI_Eq;
function "=" (Left : Uint; Right : Int) return Boolean renames UI_Eq;
precisely to avoid explicit conversions with UI_From_Int, e.g.:
if An_Uint = UI_From_Int (An_Int) then ...
This patch removes such explicit conversions. Code cleanup only;
semantics is unaffected.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* exp_ch4.adb, sem_ch13.adb, sem_eval.adb, sem_res.adb: Remove
redundant calls to UI_From_Int.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2586 bytes --]
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -4262,7 +4262,7 @@ package body Exp_Ch4 is
-- larger type for the operands, to prevent spurious constraint
-- errors on large legal literals of the type.
- if Modulus (Etype (N)) > UI_From_Int (Int (Integer'Last)) then
+ if Modulus (Etype (N)) > Int (Integer'Last) then
Target_Type := Standard_Long_Long_Integer;
else
Target_Type := Standard_Integer;
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -12304,7 +12304,7 @@ package body Sem_Ch13 is
-- Reject patently improper size values
if Is_Elementary_Type (T)
- and then Siz > UI_From_Int (Int'Last)
+ and then Siz > Int'Last
then
Error_Msg_N ("Size value too large for elementary type", N);
diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb
--- a/gcc/ada/sem_eval.adb
+++ b/gcc/ada/sem_eval.adb
@@ -4137,7 +4137,7 @@ package body Sem_Eval is
Len := String_Length (Strval (N));
- if UI_From_Int (Len) > String_Type_Len (Bas) then
+ if Len > String_Type_Len (Bas) then
-- Issue message. Note that this message is a warning if the
-- string literal is not marked as static (happens in some cases
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -11555,14 +11555,14 @@ package body Sem_Res is
Comp_Typ_Hi : constant Node_Id :=
Type_High_Bound (Component_Type (Typ));
- Char_Val : Uint;
+ Char_Val : Int;
begin
if Compile_Time_Known_Value (Comp_Typ_Lo)
and then Compile_Time_Known_Value (Comp_Typ_Hi)
then
for J in 1 .. Strlen loop
- Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
+ Char_Val := Int (Get_String_Char (Str, J));
if Char_Val < Expr_Value (Comp_Typ_Lo)
or else Char_Val > Expr_Value (Comp_Typ_Hi)
@@ -11587,7 +11587,7 @@ package body Sem_Res is
-- heavy artillery for this situation, but it is hard work to avoid.
declare
- Lits : constant List_Id := New_List;
+ Lits : constant List_Id := New_List;
P : Source_Ptr := Loc + 1;
C : Char_Code;
reply other threads:[~2021-05-05 8:20 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=20210505082005.GA31215@adacore.com \
--to=derodat@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=trojanek@adacore.com \
/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: link
Be 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).