From ae71d81b18382d0967983de64a6bcd5c08bac6ca Mon Sep 17 00:00:00 2001 From: Arnaud Charlet Date: Tue, 31 Jul 2018 09:56:59 +0000 Subject: [PATCH] [Ada] Various code clean-ups from CodePeer messages 2018-07-31 Arnaud Charlet gcc/ada/ * clean.adb, gnatchop.adb, gnatfind.adb, gnatls.adb, gnatmake.ads, gnatxref.adb, make.adb, make.ads, make_util.ads, sfn_scan.adb, vxaddr2line.adb, xeinfo.adb, xoscons.adb, xr_tabls.adb, xref_lib.adb: Address CodePeer messages. From-SVN: r263108 --- gcc/ada/ChangeLog | 7 ++++++ gcc/ada/clean.adb | 1 + gcc/ada/gnatchop.adb | 8 ++++--- gcc/ada/gnatfind.adb | 1 + gcc/ada/gnatls.adb | 51 ++++++++++++++++++++--------------------- gcc/ada/gnatmake.ads | 1 + gcc/ada/gnatxref.adb | 1 + gcc/ada/make.adb | 18 ++++++++------- gcc/ada/make.ads | 1 + gcc/ada/make_util.ads | 2 ++ gcc/ada/sfn_scan.adb | 1 + gcc/ada/vxaddr2line.adb | 3 ++- gcc/ada/xeinfo.adb | 1 + gcc/ada/xoscons.adb | 2 +- gcc/ada/xr_tabls.adb | 3 +++ gcc/ada/xref_lib.adb | 4 ++-- 16 files changed, 64 insertions(+), 41 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index ba9599e2980..c6f1911684d 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,10 @@ +2018-07-31 Arnaud Charlet + + * clean.adb, gnatchop.adb, gnatfind.adb, gnatls.adb, + gnatmake.ads, gnatxref.adb, make.adb, make.ads, make_util.ads, + sfn_scan.adb, vxaddr2line.adb, xeinfo.adb, xoscons.adb, + xr_tabls.adb, xref_lib.adb: Address CodePeer messages. + 2018-07-31 Arnaud Charlet * gnatlink.adb: Fix potential Constraint_Error if diff --git a/gcc/ada/clean.adb b/gcc/ada/clean.adb index 736742d6c8f..387083c41ee 100644 --- a/gcc/ada/clean.adb +++ b/gcc/ada/clean.adb @@ -694,6 +694,7 @@ package body Clean is Arg : constant String := Argument (Index); procedure Bad_Argument; + pragma No_Return (Bad_Argument); -- Signal bad argument ------------------ diff --git a/gcc/ada/gnatchop.adb b/gcc/ada/gnatchop.adb index 7fc942f4646..96a5236bc28 100644 --- a/gcc/ada/gnatchop.adb +++ b/gcc/ada/gnatchop.adb @@ -599,7 +599,7 @@ procedure Gnatchop is Chop_Name : constant String_Access := File.Table (Num).Name; Save_Stdout : constant File_Descriptor := dup (Standout); Offset_Name : Temp_File_Name; - Offset_FD : File_Descriptor; + Offset_FD : File_Descriptor := Invalid_FD; Buffer : String_Access; Success : Boolean; Failure : exception; @@ -685,10 +685,12 @@ procedure Gnatchop is exception when Failure | Types.Terminate_Program => - Close (Offset_FD); + if Offset_FD /= Invalid_FD then + Close (Offset_FD); + end if; + Delete_File (Offset_Name'Address, Success); return False; - end Parse_File; ----------------------- diff --git a/gcc/ada/gnatfind.adb b/gcc/ada/gnatfind.adb index 1f4cd4bf407..dd2e0f649a5 100644 --- a/gcc/ada/gnatfind.adb +++ b/gcc/ada/gnatfind.adb @@ -75,6 +75,7 @@ procedure Gnatfind is -- Display the usage procedure Write_Usage; + pragma No_Return (Write_Usage); -- Print a small help page for program usage and exit program -------------------- diff --git a/gcc/ada/gnatls.adb b/gcc/ada/gnatls.adb index f8d36d7bf18..a05b044e290 100644 --- a/gcc/ada/gnatls.adb +++ b/gcc/ada/gnatls.adb @@ -187,6 +187,7 @@ procedure Gnatls is -- Print usage message procedure Output_License_Information; + pragma No_Return (Output_License_Information); -- Output license statement, and if not found, output reference to COPYING function Image (Restriction : Restriction_Id) return String; @@ -694,40 +695,38 @@ procedure Gnatls is procedure Output_Token (T : Token_Type) is begin - if T in T_No_ALI .. T_Flags then - for J in 1 .. N_Indents loop - Write_Str (" "); - end loop; + case T is + when T_No_ALI .. T_Flags => + for J in 1 .. N_Indents loop + Write_Str (" "); + end loop; - Write_Str (Image (T).all); + Write_Str (Image (T).all); - for J in Image (T)'Length .. 12 loop - Write_Char (' '); - end loop; + for J in Image (T)'Length .. 12 loop + Write_Char (' '); + end loop; - Write_Str ("=>"); + Write_Str ("=>"); - if T in T_No_ALI .. T_With then - Write_Eol; - elsif T in T_Source .. T_Name then - Write_Char (' '); - end if; - - elsif T in T_Preelaborated .. T_Body then - if T in T_Preelaborated .. T_Is_Generic then - if N_Flags = 0 then - Output_Token (T_Flags); + if T in T_No_ALI .. T_With then + Write_Eol; + elsif T in T_Source .. T_Name then + Write_Char (' '); end if; - N_Flags := N_Flags + 1; - end if; + when T_Preelaborated .. T_Body => + if T in T_Preelaborated .. T_Is_Generic then + if N_Flags = 0 then + Output_Token (T_Flags); + end if; - Write_Char (' '); - Write_Str (Image (T).all); + N_Flags := N_Flags + 1; + end if; - else - Write_Str (Image (T).all); - end if; + Write_Char (' '); + Write_Str (Image (T).all); + end case; end Output_Token; ----------------- diff --git a/gcc/ada/gnatmake.ads b/gcc/ada/gnatmake.ads index 13bde861a8d..d98e717081f 100644 --- a/gcc/ada/gnatmake.ads +++ b/gcc/ada/gnatmake.ads @@ -24,6 +24,7 @@ ------------------------------------------------------------------------------ procedure Gnatmake; +pragma No_Return (Gnatmake); -- The driver for the gnatmake tool. This utility can be used to automatically -- (re)compile a set of ada sources by giving the name of the root compilation -- unit or the source file containing it. For more information on gnatmake diff --git a/gcc/ada/gnatxref.adb b/gcc/ada/gnatxref.adb index 2991fc595a7..3714ffff099 100644 --- a/gcc/ada/gnatxref.adb +++ b/gcc/ada/gnatxref.adb @@ -63,6 +63,7 @@ procedure Gnatxref is -- Display the usage procedure Write_Usage; + pragma No_Return (Write_Usage); -- Print a small help page for program usage -------------------- diff --git a/gcc/ada/make.adb b/gcc/ada/make.adb index 50aaf5b48e5..953db4272ef 100644 --- a/gcc/ada/make.adb +++ b/gcc/ada/make.adb @@ -85,6 +85,7 @@ package body Make is procedure Sigint_Intercepted; pragma Convention (C, Sigint_Intercepted); + pragma No_Return (Sigint_Intercepted); -- Called when the program is interrupted by Ctrl-C to delete the -- temporary mapping files and configuration pragmas files. @@ -254,6 +255,7 @@ package body Make is No_Shared_Libgcc_Switch'Access; procedure Make_Failed (S : String); + pragma No_Return (Make_Failed); -- Delete all temp files created by Gnatmake and call Osint.Fail, with the -- parameter S (see osint.ads). @@ -545,6 +547,7 @@ package body Make is -- Display_Executed_Programs is set. The lower bound of Args must be 1. procedure Report_Compilation_Failed; + pragma No_Return (Report_Compilation_Failed); -- Delete all temporary files and fail graciously ----------------- @@ -580,7 +583,7 @@ package body Make is Gnatmake_Mapping_File : String_Access := null; -- The path name of a mapping file specified by switch -C= - procedure Init_Mapping_File (File_Index : in out Natural); + procedure Init_Mapping_File (File_Index : out Natural); -- Create a new mapping file or reuse one already created. package Temp_File_Paths is new Table.Table @@ -2347,10 +2350,10 @@ package body Make is Full_Lib_File : File_Name_Type := No_File; Lib_File_Attr : aliased File_Attributes; Read_Only : Boolean := False; - ALI : ALI_Id; + ALI : ALI_Id := No_ALI_Id; -- The ALI file and its attributes (size, stamp, ...) - Obj_File : File_Name_Type; + Obj_File : File_Name_Type := No_File; Obj_Stamp : Time_Stamp_Type; -- The object file @@ -3614,7 +3617,7 @@ package body Make is -- Init_Mapping_File -- ----------------------- - procedure Init_Mapping_File (File_Index : in out Natural) is + procedure Init_Mapping_File (File_Index : out Natural) is FD : File_Descriptor; Status : Boolean; -- For call to Close @@ -4378,9 +4381,7 @@ package body Make is Look_In_Primary_Dir := False; elsif Program_Args = Compiler then - if Argv (3 .. Argv'Last) /= "-" then - Add_Source_Search_Dir (Argv (3 .. Argv'Last)); - end if; + Add_Source_Search_Dir (Argv (3 .. Argv'Last)); elsif Program_Args = Binder then Add_Library_Search_Dir (Argv (3 .. Argv'Last)); @@ -4690,7 +4691,8 @@ package body Make is -- -m - elsif Argv (2) = 'm' and then Argv'Last = 2 then + elsif Argv (2) = 'm' then + pragma Assert (Argv'Last = 2); Minimal_Recompilation := True; -- -u diff --git a/gcc/ada/make.ads b/gcc/ada/make.ads index 117f5ed53a5..4cd346acafb 100644 --- a/gcc/ada/make.ads +++ b/gcc/ada/make.ads @@ -29,6 +29,7 @@ package Make is procedure Gnatmake; + pragma No_Return (Gnatmake); -- The driver of gnatmake. For more information on gnatmake and its -- precise usage please refer to the gnat documentation. diff --git a/gcc/ada/make_util.ads b/gcc/ada/make_util.ads index bdf57961a26..9c7bb4dc336 100644 --- a/gcc/ada/make_util.ads +++ b/gcc/ada/make_util.ads @@ -184,11 +184,13 @@ package Make_Util is procedure Fail_Program (S : String; Flush_Messages : Boolean := True); + pragma No_Return (Fail_Program); -- Terminate program with a message and a fatal status code procedure Finish_Program (Exit_Code : Osint.Exit_Code_Type := Osint.E_Success; S : String := ""); + pragma No_Return (Finish_Program); -- Terminate program, with or without a message, setting the status code -- according to Fatal. This properly removes all temporary files. diff --git a/gcc/ada/sfn_scan.adb b/gcc/ada/sfn_scan.adb index 5dd65fb4939..e37906d3f45 100644 --- a/gcc/ada/sfn_scan.adb +++ b/gcc/ada/sfn_scan.adb @@ -106,6 +106,7 @@ package body SFN_Scan is -- ('a' .. 'z'). procedure Error (Err : String); + pragma No_Return (Error); -- Called if an error is detected. Raises Syntax_Error_In_GNAT_ADC -- with a message of the form gnat.adc:line:col: xxx, where xxx is -- the string Err passed as a parameter. diff --git a/gcc/ada/vxaddr2line.adb b/gcc/ada/vxaddr2line.adb index 3370c8288c6..e893aa4f658 100644 --- a/gcc/ada/vxaddr2line.adb +++ b/gcc/ada/vxaddr2line.adb @@ -209,6 +209,7 @@ procedure VxAddr2Line is -- Prints the message and then terminates the program procedure Usage; + pragma No_Return (Usage); -- Displays the short help message and then terminates the program function Get_Reference_Offset return Unsigned_64; @@ -319,7 +320,7 @@ procedure VxAddr2Line is declare Match_String : constant String := Expect_Out_Match (Pd); Matches : Match_Array (0 .. 1); - Value : Unsigned_64; + Value : Unsigned_64 := 0; begin Match (Reference, Match_String, Matches); diff --git a/gcc/ada/xeinfo.adb b/gcc/ada/xeinfo.adb index edb871a8505..5131907eed4 100644 --- a/gcc/ada/xeinfo.adb +++ b/gcc/ada/xeinfo.adb @@ -151,6 +151,7 @@ procedure XEinfo is Lastinlined : Boolean; procedure Badfunc; + pragma No_Return (Badfunc); -- Signal bad function in body function Getlin return VString; diff --git a/gcc/ada/xoscons.adb b/gcc/ada/xoscons.adb index 48a25d11c8f..ca4121fe44e 100644 --- a/gcc/ada/xoscons.adb +++ b/gcc/ada/xoscons.adb @@ -166,7 +166,7 @@ procedure XOSCons is A2 : Long_Unsigned renames V2.Abs_Value; begin return (P1 and then not P2) - or else (P1 and then P2 and then A1 > A2) + or else (P1 and then A1 > A2) or else (not P1 and then not P2 and then A1 < A2); end ">"; diff --git a/gcc/ada/xr_tabls.adb b/gcc/ada/xr_tabls.adb index 8df26868751..1831d69fef4 100644 --- a/gcc/ada/xr_tabls.adb +++ b/gcc/ada/xr_tabls.adb @@ -761,6 +761,9 @@ package body Xr_Tabls is With_Dir : Boolean := False; Strip : Natural := 0) return String is + pragma Annotate (CodePeer, Skip_Analysis); + -- ??? To disable false positives currently generated + Tmp : GNAT.OS_Lib.String_Access; function Internal_Strip (Full_Name : String) return String; diff --git a/gcc/ada/xref_lib.adb b/gcc/ada/xref_lib.adb index b656ac02efc..d211a28036c 100644 --- a/gcc/ada/xref_lib.adb +++ b/gcc/ada/xref_lib.adb @@ -75,7 +75,7 @@ package body Xref_Lib is procedure Open (Name : String; - File : out ALI_File; + File : in out ALI_File; Dependencies : Boolean := False); -- Open a new ALI file. If Dependencies is True, the insert every library -- file 'with'ed in the files database (used for gnatxref) @@ -688,7 +688,7 @@ package body Xref_Lib is procedure Open (Name : String; - File : out ALI_File; + File : in out ALI_File; Dependencies : Boolean := False) is Ali : String_Access renames File.Buffer; -- 2.30.2