From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id 1B21A3858C39; Fri, 1 Oct 2021 06:14:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B21A3858C39 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-4005] [Ada] Improve error message for .ali file version mismatch X-Act-Checkin: gcc X-Git-Author: Steve Baird X-Git-Refname: refs/heads/master X-Git-Oldrev: 8e35980ff82ad5a00de3237ad94c1fe942fb0ba4 X-Git-Newrev: cafd1c1a71325c0e9dc6a6862fdd5dcd7248fbb6 Message-Id: <20211001061431.1B21A3858C39@sourceware.org> Date: Fri, 1 Oct 2021 06:14:31 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Oct 2021 06:14:31 -0000 https://gcc.gnu.org/g:cafd1c1a71325c0e9dc6a6862fdd5dcd7248fbb6 commit r12-4005-gcafd1c1a71325c0e9dc6a6862fdd5dcd7248fbb6 Author: Steve Baird Date: Thu Aug 5 11:18:19 2021 -0700 [Ada] Improve error message for .ali file version mismatch gcc/ada/ * bcheck.adb (Check_Versions): In the case of an ali file version mismatch, if distinct integer values can be extracted from the two version strings then include those values in the generated error message. Diff: --- gcc/ada/bcheck.adb | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/gcc/ada/bcheck.adb b/gcc/ada/bcheck.adb index 804e2fd5d16..bf53b4be25d 100644 --- a/gcc/ada/bcheck.adb +++ b/gcc/ada/bcheck.adb @@ -29,6 +29,7 @@ with Binderr; use Binderr; with Butil; use Butil; with Casing; use Casing; with Fname; use Fname; +with Gnatvsn; with Namet; use Namet; with Opt; use Opt; with Osint; @@ -1324,11 +1325,78 @@ package body Bcheck is or else ALIs.Table (A).Ver (1 .. VL) /= ALIs.Table (ALIs.First).Ver (1 .. VL) then - Error_Msg_File_1 := ALIs.Table (A).Sfile; - Error_Msg_File_2 := ALIs.Table (ALIs.First).Sfile; + declare + No_Version : constant Int := -1; - Consistency_Error_Msg - ("{ and { compiled with different GNAT versions"); + function Extract_Version (S : String) return Int; + -- Attempts to extract and return a nonnegative library + -- version number from the given string; if unsuccessful, + -- then returns No_Version. + + --------------------- + -- Extract_Version -- + --------------------- + + function Extract_Version (S : String) return Int is + use Gnatvsn; + + Prefix : constant String := + Verbose_Library_Version + (1 .. Verbose_Library_Version'Length + - Library_Version'Length); + begin + pragma Assert (S'First = 1); + + if S'Length > Prefix'Length + and then S (1 .. Prefix'Length) = Prefix + then + declare + Suffix : constant String := + S (1 + Prefix'Length .. S'Last); + + Result : Nat := 0; + begin + if Suffix'Length < 10 + and then (for all C of Suffix => C in '0' .. '9') + then + -- Using Int'Value leads to complications in + -- building the binder, so DIY. + + for C of Suffix loop + Result := (10 * Result) + + (Character'Pos (C) - Character'Pos ('0')); + end loop; + return Result; + end if; + end; + end if; + return No_Version; + end Extract_Version; + + V1_Text : constant String := + ALIs.Table (A).Ver (1 .. ALIs.Table (A).Ver_Len); + V2_Text : constant String := + ALIs.Table (ALIs.First).Ver (1 .. VL); + V1 : constant Int := Extract_Version (V1_Text); + V2 : constant Int := Extract_Version (V2_Text); + + Include_Version_Numbers_In_Message : constant Boolean := + (V1 /= V2) and (V1 /= No_Version) and (V2 /= No_Version); + begin + Error_Msg_File_1 := ALIs.Table (A).Sfile; + Error_Msg_File_2 := ALIs.Table (ALIs.First).Sfile; + + if Include_Version_Numbers_In_Message then + Error_Msg_Nat_1 := V1; + Error_Msg_Nat_2 := V2; + Consistency_Error_Msg + ("{ and { compiled with different GNAT versions" + & ", v# and v#"); + else + Consistency_Error_Msg + ("{ and { compiled with different GNAT versions"); + end if; + end; end if; end loop; end Check_Versions;