From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 3E72038346B3 for ; Tue, 10 May 2022 08:21:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3E72038346B3 Received: by mail-wm1-x335.google.com with SMTP id n6-20020a05600c3b8600b0039492b44ce7so900320wms.5 for ; Tue, 10 May 2022 01:21:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=KpoF1y6KLoMdWneG3IiIZ4VYUUQ+HppyVIlTmU3FBo0=; b=gH0KUdYLau9JjW92GZ0x5pQ04Z6LUIy/PLEfQz3yxxroUtkZZzHObLFP0mLFWxzC6U fBEzjkOfDp33l0L5UIpCEG4UBzmVBpiwWbZILt6OCFOFFCUj09vxbx5Dz+AqWUm2xTVu FNWRWkvIB9y3xRc6oHrE1DRYtmltlZJEn7h+Am+NIXVFKbq+EBdEuTUROv0tmIc8iSij IATU3qmIpipNaNw2Qvm5byCCbWxiPDKOxwKsnvPOObk3HgbncgvzFhWqT7Ej3JfbbYC+ N2PBhBwDjdRnsN8Iv9DpyOoNoOqAYhtih+VGASVOIrPukgB5PCuZk7ve+MnAWpv57m+B VRRw== X-Gm-Message-State: AOAM532zqRRzqZZ9u/BEe9+QWcPPoC9PHuVB94SG5wIST2Sjo4Eu4o47 97fVdKGbAib7wmF05NHcRs6X8+2Ev4sAmQ== X-Google-Smtp-Source: ABdhPJwIrfinIQwth2YisG4lBOdANEe70kZPasw7+iOQUl/Wn8kHx2c8aRFPGQBki1zQMBikKlQCYQ== X-Received: by 2002:a05:600c:1c1f:b0:394:6950:2bda with SMTP id j31-20020a05600c1c1f00b0039469502bdamr25263760wms.52.1652170870884; Tue, 10 May 2022 01:21:10 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id z10-20020a1c4c0a000000b003942a244ed7sm1758191wmf.28.2022.05.10.01.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 May 2022 01:21:10 -0700 (PDT) Date: Tue, 10 May 2022 08:21:09 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [Ada] Remove repeated conversions between Source_Ptr and Int Message-ID: <20220510082109.GA3029262@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="W/nzBZO5zC0uMSeA" Content-Disposition: inline X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 May 2022 08:21:18 -0000 --W/nzBZO5zC0uMSeA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Both Source_Ptr and Int are integer types (and even happen to have equal ranges). Their values can be calculated without converting back-and-forth, e.g.: Int (Loc1) - Int (Loc2) can be written simply as: Int (Loc1 - Loc2) Code cleanup related to handling of references to unset objects. Offending occurrences found with various invocations of grep. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * par-ch10.adb, scng.adb, sem_res.adb, sinfo-utils.adb, treepr.adb: Simplify calculations with Source_Ptr and Loc values. --W/nzBZO5zC0uMSeA Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/par-ch10.adb b/gcc/ada/par-ch10.adb --- a/gcc/ada/par-ch10.adb +++ b/gcc/ada/par-ch10.adb @@ -1194,7 +1194,7 @@ package body Ch10 is Write_Int (Int (Line)); Write_Str (", file offset "); - Write_Int (Int (Loc) - Int (Source_First (Sind))); + Write_Int (Int (Loc - Source_First (Sind))); end Unit_Location; end Ch10; diff --git a/gcc/ada/scng.adb b/gcc/ada/scng.adb --- a/gcc/ada/scng.adb +++ b/gcc/ada/scng.adb @@ -130,11 +130,7 @@ package body Scng is procedure Check_End_Of_Line is Len : constant Int := - Int (Scan_Ptr) - - Int (Current_Line_Start) - - Wide_Char_Byte_Count; - - -- Start of processing for Check_End_Of_Line + Int (Scan_Ptr - Current_Line_Start) - Wide_Char_Byte_Count; begin if Style_Check then 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 @@ -11754,7 +11754,7 @@ package body Sem_Res is Error_Msg ("literal out of range of type Standard.Character", - Source_Ptr (Int (Loc) + J)); + Loc + Source_Ptr (J)); return; end if; end loop; @@ -11783,7 +11783,7 @@ package body Sem_Res is Error_Msg ("literal out of range of type Standard.Wide_Character", - Source_Ptr (Int (Loc) + J)); + Loc + Source_Ptr (J)); return; end if; end loop; diff --git a/gcc/ada/sinfo-utils.adb b/gcc/ada/sinfo-utils.adb --- a/gcc/ada/sinfo-utils.adb +++ b/gcc/ada/sinfo-utils.adb @@ -191,7 +191,7 @@ package body Sinfo.Utils is function End_Location (N : Node_Id) return Source_Ptr is L : constant Valid_Uint := End_Span (N); begin - return Source_Ptr (Int (Sloc (N)) + UI_To_Int (L)); + return Sloc (N) + Source_Ptr (UI_To_Int (L)); end End_Location; -------------------- @@ -214,7 +214,7 @@ package body Sinfo.Utils is procedure Set_End_Location (N : Node_Id; S : Source_Ptr) is begin Set_End_Span (N, - UI_From_Int (Int (S) - Int (Sloc (N)))); + UI_From_Int (Int (S - Sloc (N)))); end Set_End_Location; -------------------------- diff --git a/gcc/ada/treepr.adb b/gcc/ada/treepr.adb --- a/gcc/ada/treepr.adb +++ b/gcc/ada/treepr.adb @@ -1229,7 +1229,7 @@ package body Treepr is else Sfile := Get_Source_File_Index (Sloc (N)); - Print_Int (Int (Sloc (N)) - Int (Source_Text (Sfile)'First)); + Print_Int (Int (Sloc (N) - Source_Text (Sfile)'First)); Write_Str (" "); Write_Location (Sloc (N)); end if; --W/nzBZO5zC0uMSeA--