]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Address potentially uninitialized variables and dead code
authorArnaud Charlet <charlet@adacore.com>
Thu, 12 Dec 2019 13:01:03 +0000 (14:01 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 2 Jun 2020 08:58:05 +0000 (04:58 -0400)
2020-06-02  Arnaud Charlet  <charlet@adacore.com>

gcc/ada/

* bcheck.adb, binde.adb, bindo-diagnostics.adb, checks.adb,
exp_aggr.adb, exp_ch3.adb, exp_ch4.adb, exp_ch7.adb,
exp_ch9.adb, gnatname.adb, sem_case.adb, sem_ch13.adb,
sem_ch5.adb, sem_prag.adb, sem_util.adb, uintp.adb, urealp.adb,
xoscons.adb, xr_tabls.adb, xref_lib.adb: Initialize objects more
explicitly and add corresponding assertions. Remove dead code.
Also add a few Annotate pragmas to help static analysis.
* libgnat/a-caldel.adb, libgnat/a-calend.adb,
libgnat/a-ngcoty.adb, libgnat/a-ngelfu.adb,
libgnat/a-ngrear.adb, libgnat/a-strfix.adb,
libgnat/g-calend.adb, libgnat/g-catiio.adb,
libgnat/g-comlin.adb, libgnat/g-debpoo.adb,
libgnat/g-dirope.adb, libgnat/g-hesorg.adb,
libgnat/g-pehage.adb, libgnat/g-socket.adb, libgnat/i-cobol.adb,
libgnat/s-dwalin.adb, libgnat/s-dwalin.ads,
libgnat/s-fatgen.adb, libgnat/s-gearop.adb,
libgnat/s-genbig.adb, libgnat/s-imgrea.adb,
libgnat/s-os_lib.adb, libgnat/s-rannum.adb,
libgnat/s-regpat.adb, libgnat/s-trasym__dwarf.adb,
libgnat/s-valrea.adb: Ditto.

46 files changed:
gcc/ada/bcheck.adb
gcc/ada/binde.adb
gcc/ada/bindo-diagnostics.adb
gcc/ada/checks.adb
gcc/ada/exp_aggr.adb
gcc/ada/exp_ch3.adb
gcc/ada/exp_ch4.adb
gcc/ada/exp_ch7.adb
gcc/ada/exp_ch9.adb
gcc/ada/gnatname.adb
gcc/ada/libgnat/a-caldel.adb
gcc/ada/libgnat/a-calend.adb
gcc/ada/libgnat/a-ngcoty.adb
gcc/ada/libgnat/a-ngelfu.adb
gcc/ada/libgnat/a-ngrear.adb
gcc/ada/libgnat/a-strfix.adb
gcc/ada/libgnat/g-calend.adb
gcc/ada/libgnat/g-catiio.adb
gcc/ada/libgnat/g-comlin.adb
gcc/ada/libgnat/g-debpoo.adb
gcc/ada/libgnat/g-dirope.adb
gcc/ada/libgnat/g-hesorg.adb
gcc/ada/libgnat/g-pehage.adb
gcc/ada/libgnat/g-socket.adb
gcc/ada/libgnat/i-cobol.adb
gcc/ada/libgnat/s-dwalin.adb
gcc/ada/libgnat/s-dwalin.ads
gcc/ada/libgnat/s-fatgen.adb
gcc/ada/libgnat/s-gearop.adb
gcc/ada/libgnat/s-genbig.adb
gcc/ada/libgnat/s-imgrea.adb
gcc/ada/libgnat/s-os_lib.adb
gcc/ada/libgnat/s-rannum.adb
gcc/ada/libgnat/s-regpat.adb
gcc/ada/libgnat/s-trasym__dwarf.adb
gcc/ada/libgnat/s-valrea.adb
gcc/ada/sem_case.adb
gcc/ada/sem_ch13.adb
gcc/ada/sem_ch5.adb
gcc/ada/sem_prag.adb
gcc/ada/sem_util.adb
gcc/ada/uintp.adb
gcc/ada/urealp.adb
gcc/ada/xoscons.adb
gcc/ada/xr_tabls.adb
gcc/ada/xref_lib.adb

index 23246307f34a7e1dc20f460748da4744d584f359..55c1eff716dc8135a94299ecb4ada6ff56b26866 100644 (file)
@@ -771,7 +771,7 @@ package body Bcheck is
       --  Reset when we find a unit that depends on the default and does
       --  not have a local specification of the Optimize_Alignment setting.
 
-      OA_Unit : Unit_Id;
+      OA_Unit : Unit_Id := No_Unit_Id;
       --  Id of unit from which OA_Setting was set
 
       C : Character;
@@ -789,6 +789,7 @@ package body Bcheck is
                null;
 
             else
+               pragma Assert (Present (OA_Unit));
                Error_Msg_Unit_1 := Units.Table (OA_Unit).Uname;
                Error_Msg_Unit_2 := Units.Table (U).Uname;
 
index 5caee491c07c370698258c9e9d0a0ec0d973f59c..abf94973ea2aa56baca3395916baa61c0d9d739a 100644 (file)
@@ -1056,6 +1056,8 @@ package body Binde is
       --  becomes zero, then add to no-predecessor list.
 
       S := UNR.Table (Chosen).Successors;
+      pragma Annotate (CodePeer, Modified, S);
+
       while S /= No_Successor loop
          U := Succ.Table (S).After;
          UNR.Table (U).Num_Pred := UNR.Table (U).Num_Pred - 1;
@@ -2390,6 +2392,8 @@ package body Binde is
    begin
       if ST.Reason in Elab_All .. Elab_All_Desirable then
          L := ST.Elab_All_Link;
+         pragma Annotate (CodePeer, Modified, L);
+
          while L /= No_Elab_All_Link loop
             Nam := Elab_All_Entries.Table (L).Needed_By;
             Error_Msg_Unit_1 := Nam;
index 6f19ac0961a244c24a331c2ebe9fa17918c0b53b..934e9a693367f77ff5fe6e0f422bf8c0c4db10b3 100644 (file)
@@ -343,7 +343,7 @@ package body Bindo.Diagnostics is
                                  (G     => Lib_Graph,
                                   Cycle => Cycle);
 
-      Current_Edge : Library_Graph_Edge_Id;
+      Current_Edge : Library_Graph_Edge_Id := No_Library_Graph_Edge;
       First_Edge   : Library_Graph_Edge_Id;
       Iter         : Edges_Of_Cycle_Iterator;
       Next_Edge    : Library_Graph_Edge_Id;
index 51ef6c078a3c72872d630409dbc1dbbd0936addb..6c597648039aeba6b9d7b40256c5ccb1c761785a 100644 (file)
@@ -8740,8 +8740,7 @@ package body Checks is
 
             else
                declare
-                  Rtype    : Entity_Id;
-                  pragma Warnings (Off, Rtype);
+                  Rtype    : Entity_Id := Empty;
                   New_Alts : List_Id;
                   New_Exp  : Node_Id;
 
@@ -8771,6 +8770,7 @@ package body Checks is
                       Expression   => Expression (N),
                       Alternatives => New_Alts));
 
+                  pragma Assert (Present (Rtype));
                   Reanalyze (Rtype, Suppress => True);
                end;
             end if;
index 60ad4d6297ef973e34c3fbb48ce19d82f88c8b42..f4b959516d761de44c1974beaecd59b8f9d1d0bf 100644 (file)
@@ -5239,7 +5239,7 @@ package body Exp_Aggr is
       --  specifically optimized for the target.
 
       function Aggr_Assignment_OK_For_Backend (N : Node_Id) return Boolean is
-         Csiz      : Uint;
+         Csiz      : Uint := No_Uint;
          Ctyp      : Entity_Id;
          Expr      : Node_Id;
          High      : Node_Id;
@@ -5336,6 +5336,8 @@ package body Exp_Aggr is
          --  Scalar types are OK if their size is a multiple of Storage_Unit
 
          elsif Is_Scalar_Type (Ctyp) then
+            pragma Assert (Csiz /= No_Uint);
+
             if Csiz mod System_Storage_Unit /= 0 then
                return False;
             end if;
index 82a58b788bf4289914936c50f6071e51400fb52c..15d468be6c1c8285f2ca9d479224212e67f41369 100644 (file)
@@ -5579,7 +5579,7 @@ package body Exp_Ch3 is
          declare
             Comp  : Entity_Id;
             First : Boolean;
-            M_Id  : Entity_Id;
+            M_Id  : Entity_Id := Empty;
             Typ   : Entity_Id;
 
          begin
@@ -5612,6 +5612,7 @@ package body Exp_Ch3 is
                   --  Reuse the same master to service any additional types
 
                   else
+                     pragma Assert (Present (M_Id));
                      Set_Master_Id (Typ, M_Id);
                   end if;
                end if;
index 28d48ab7f8b98ce05a14d73a795d168d8cafded8..77857763b1eb2f54ceed03ddbad0f9ff24e8a614 100644 (file)
@@ -2814,7 +2814,7 @@ package body Exp_Ch4 is
       --  to just do a Copy_Node to get an appropriate copy. The extra zeroth
       --  entry always is set to zero. The length is of type Artyp.
 
-      Low_Bound : Node_Id;
+      Low_Bound : Node_Id := Empty;
       --  A tree node representing the low bound of the result (of type Ityp).
       --  This is either an integer literal node, or an identifier reference to
       --  a constant entity initialized to the appropriate value.
@@ -2834,7 +2834,7 @@ package body Exp_Ch4 is
       High_Bound : Node_Id := Empty;
       --  A tree node representing the high bound of the result (of type Ityp)
 
-      Result : Node_Id;
+      Result : Node_Id := Empty;
       --  Result of the concatenation (of type Ityp)
 
       Actions : constant List_Id := New_List;
@@ -3365,6 +3365,8 @@ package body Exp_Ch4 is
          end;
       end if;
 
+      pragma Assert (Present (Low_Bound));
+
       --  Now we can safely compute the upper bound, normally
       --  Low_Bound + Length - 1.
 
@@ -3621,6 +3623,7 @@ package body Exp_Ch4 is
       Result := New_Occurrence_Of (Ent, Loc);
 
    <<Done>>
+      pragma Assert (Present (Result));
       Rewrite (Cnode, Result);
       Analyze_And_Resolve (Cnode, Atyp);
 
@@ -4369,8 +4372,7 @@ package body Exp_Ch4 is
          declare
             Idx : Node_Id := First_Index (E);
             Len : Node_Id;
-            Res : Node_Id;
-            pragma Warnings (Off, Res);
+            Res : Node_Id := Empty;
 
          begin
             for J in 1 .. Number_Dimensions (E) loop
@@ -4443,6 +4445,7 @@ package body Exp_Ch4 is
                   Res := Len;
 
                else
+                  pragma Assert (Present (Res));
                   Res :=
                     Make_Op_Multiply (Loc,
                       Left_Opnd  => Res,
index 125eba6353102cb5b2d17fa137b2fe59febfc573..d4c8b99ef8d599e443ca350c904e5cf2083b5a1e 100644 (file)
@@ -909,7 +909,7 @@ package body Exp_Ch7 is
       elsif Is_Protected_Body then
          declare
             Spec      : constant Node_Id := Parent (Corresponding_Spec (N));
-            Conc_Typ  : Entity_Id;
+            Conc_Typ  : Entity_Id := Empty;
             Param     : Node_Id;
             Param_Typ : Entity_Id;
 
@@ -929,6 +929,7 @@ package body Exp_Ch7 is
             end loop;
 
             pragma Assert (Present (Param));
+            pragma Assert (Present (Conc_Typ));
 
             --  Historical note: In earlier versions of GNAT, there was code
             --  at this point to generate stuff to service entry queues. It is
@@ -5720,8 +5721,8 @@ package body Exp_Ch7 is
          Blk_Decl  : Node_Id := Empty;
          Blk_Decls : List_Id := No_List;
          Blk_Ins   : Node_Id;
-         Blk_Stmts : List_Id;
-         Loc       : Source_Ptr;
+         Blk_Stmts : List_Id := No_List;
+         Loc       : Source_Ptr := No_Location;
          Obj_Decl  : Node_Id;
 
       --  Start of processing for Process_Transients_In_Scope
@@ -5854,6 +5855,7 @@ package body Exp_Ch7 is
                --  Construct all necessary circuitry to hook and finalize a
                --  single transient object.
 
+               pragma Assert (Present (Blk_Stmts));
                Process_Transient_In_Scope
                  (Obj_Decl  => Obj_Decl,
                   Blk_Data  => Blk_Data,
@@ -5875,6 +5877,9 @@ package body Exp_Ch7 is
 
          if Present (Blk_Decl) then
 
+            pragma Assert (Present (Blk_Stmts));
+            pragma Assert (Loc /= No_Location);
+
             --  Note that this Abort_Undefer does not require a extra block or
             --  an AT_END handler because each finalization exception is caught
             --  in its own corresponding finalization block. As a result, the
index 392a221e18fe0e782ef79da084307cc2ca0e01b7..a2afa2ec71d57d6f015caa4ad3e831a4abc6f3eb 100644 (file)
@@ -2546,7 +2546,7 @@ package body Exp_Ch9 is
       Lo    : Node_Id;
       Hi    : Node_Id;
       Decls : List_Id := New_List;
-      Ret   : Node_Id;
+      Ret   : Node_Id := Empty;
       Spec  : Node_Id;
       Siz   : Node_Id := Empty;
 
@@ -2692,16 +2692,21 @@ package body Exp_Ch9 is
               Make_Simple_Return_Statement (Loc,
                 Expression => Make_Integer_Literal (Loc, 1));
 
-         elsif Nkind (Ret) = N_If_Statement then
+         else
+            pragma Assert (Present (Ret));
 
-            --  Ranges are in increasing order, so last one doesn't need guard
+            if Nkind (Ret) = N_If_Statement then
 
-            declare
-               Nod : constant Node_Id := Last (Elsif_Parts (Ret));
-            begin
-               Remove (Nod);
-               Set_Else_Statements (Ret, Then_Statements (Nod));
-            end;
+               --  Ranges are in increasing order, so last one doesn't need
+               --  guard.
+
+               declare
+                  Nod : constant Node_Id := Last (Elsif_Parts (Ret));
+               begin
+                  Remove (Nod);
+                  Set_Else_Statements (Ret, Then_Statements (Nod));
+               end;
+            end if;
          end if;
       end if;
 
@@ -10209,8 +10214,7 @@ package body Exp_Ch9 is
 
          declare
             Elmt : Elmt_Id;
-            Op   : Entity_Id;
-            pragma Warnings (Off, Op);
+            Op   : Entity_Id := Empty;
 
          begin
             Elmt := First_Elmt (Primitive_Operations (Etype (Conc_Typ)));
@@ -10220,6 +10224,8 @@ package body Exp_Ch9 is
                Next_Elmt (Elmt);
             end loop;
 
+            pragma Assert (Present (Op));
+
             return
               Make_Procedure_Call_Statement (Loc,
                 Name                   => New_Occurrence_Of (Op, Loc),
@@ -10630,7 +10636,7 @@ package body Exp_Ch9 is
       Num_Alts       : Nat;
       Num_Accept     : Nat := 0;
       Proc           : Node_Id;
-      Time_Type      : Entity_Id;
+      Time_Type      : Entity_Id := Empty;
       Select_Call    : Node_Id;
 
       Qnam : constant Entity_Id :=
@@ -11251,6 +11257,8 @@ package body Exp_Ch9 is
          Delay_Min :=
            Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
 
+         pragma Assert (Present (Time_Type));
+
          Append_To (Decls,
            Make_Object_Declaration (Loc,
              Defining_Identifier => Delay_Val,
index cefc2766286930a7bb45e4771dff5e2958519a79..4d500cef59aac722e59fbbc02a250cdae52b65a4 100644 (file)
@@ -681,6 +681,8 @@ procedure Gnatname is
                                              Sources.Last
                               loop
                                  Current_Source := Sources.Table (Index);
+                                 pragma Annotate
+                                   (CodePeer, Modified, Current_Source);
 
                                  if Opt.Verbose_Mode then
                                     if Current_Source.Spec then
index b7cfefcf536824ca5044ee339aa4774c4ba2f9c2..924442508621cfe1d78be6a0da08d49e1c1bb43a 100644 (file)
@@ -103,6 +103,8 @@ begin
    --  this soft link, or this will be overridden during the elaboration of
    --  System.Tasking.Initialization
 
+   pragma Annotate (CodePeer, Modified, SSL.Timed_Delay);
+
    if SSL.Timed_Delay = null then
       SSL.Timed_Delay := Timed_Delay_NT'Access;
    end if;
index 4cbfeff80779467a6ad07a80c5b4dd9f6b7c8fa6..219fd9aaabdd6a33c63c63d2b70d4b0fc8543d84 100644 (file)
@@ -435,18 +435,14 @@ is
       if End_T < Leap_Second_Times (1) then
          Elapsed_Leaps := 0;
          Next_Leap     := Leap_Second_Times (1);
-         return;
 
       elsif Start_T > Leap_Second_Times (Leap_Seconds_Count) then
          Elapsed_Leaps := 0;
          Next_Leap     := End_Of_Time;
-         return;
-      end if;
-
-      --  Perform the calculations only if the start date is within the leap
-      --  second occurrences table.
 
-      if Start_T <= Leap_Second_Times (Leap_Seconds_Count) then
+      else
+         --  Perform the calculations only if the start date is within the leap
+         --  second occurrences table.
 
          --    1    2                  N - 1   N
          --  +----+----+--  . . .  --+-------+---+
@@ -480,9 +476,6 @@ is
          end if;
 
          Elapsed_Leaps := End_Index - Start_Index;
-
-      else
-         Elapsed_Leaps := 0;
       end if;
    end Cumulative_Leap_Seconds;
 
@@ -763,6 +756,7 @@ is
         (Secs_T'Unchecked_Access,
          Flag'Unchecked_Access,
          Offset'Unchecked_Access);
+      pragma Annotate (CodePeer, Modified, Offset);
 
       return Long_Integer (Offset);
    end UTC_Time_Offset;
index bece703a2499580d42f036716dc051587e9e1461..deb200b204af0291138c7fc7a5bc47fd04e5778f 100644 (file)
@@ -66,11 +66,19 @@ package body Ada.Numerics.Generic_Complex_Types is
          --  return false, the test can only be written thus.
 
          if not (abs (X) <= R'Last) then
+            pragma Annotate
+              (CodePeer, Intentional,
+               "test always false", "test for infinity");
+
             X := Scale**2 * ((Left.Re / Scale) * (Right.Re / Scale) -
                              (Left.Im / Scale) * (Right.Im / Scale));
          end if;
 
          if not (abs (Y) <= R'Last) then
+            pragma Annotate
+              (CodePeer, Intentional,
+               "test always false", "test for infinity");
+
             Y := Scale**2 * ((Left.Re / Scale) * (Right.Im / Scale)
                            + (Left.Im / Scale) * (Right.Re / Scale));
          end if;
@@ -588,6 +596,7 @@ package body Ada.Numerics.Generic_Complex_Types is
 
       exception
          when Constraint_Error =>
+            pragma Assert (X.Re /= 0.0);
             return R (Double (abs (X.Re))
               * Sqrt (1.0 + (Double (X.Im) / Double (X.Re)) ** 2));
       end;
@@ -602,6 +611,7 @@ package body Ada.Numerics.Generic_Complex_Types is
 
       exception
          when Constraint_Error =>
+            pragma Assert (X.Im /= 0.0);
             return R (Double (abs (X.Im))
               * Sqrt (1.0 + (Double (X.Re) / Double (X.Im)) ** 2));
       end;
index 71cd47b3f1376879e3a2198af13da13feaa543c8..3d494042c2416943bb5ab14a659aa29b06195ce2 100644 (file)
@@ -680,6 +680,8 @@ is
       Z := G * G;
       P := G * ((P2 * Z + P1) * Z + P0);
       Q := ((Q3 * Z + Q2) * Z + Q1) * Z + Q0;
+
+      pragma Assert (Q /= P);
       R := 0.5 + P / (Q - P);
 
       R := Float_Type'Base'Scaling (R, Integer (XN) + 1);
index 8418ec1cc943f4fefb9c78a525f899187658ecda..8348cb7fde65d5321f221153fb6fdca817108a94 100644 (file)
@@ -560,6 +560,8 @@ package body Ada.Numerics.Generic_Real_Arrays is
       function Compute_Tan (P, H : Real) return Real is
          (if Is_Tiny (P, Compared_To => H) then P / H
           else Compute_Tan (Theta => H / (2.0 * P)));
+      pragma Annotate
+        (CodePeer, False_Positive, "divide by zero", "H, P /= 0");
 
       function Sum_Strict_Upper (M : Square_Matrix) return Real;
       --  Return the sum of all elements in the strict upper triangle of M
index b8b5f42dcb13f12dfe138f929ac48411a615109a..1f94b864833d4e1065845bb2c4c9a0bb3ad7a11b 100644 (file)
@@ -192,6 +192,10 @@ package body Ada.Strings.Fixed is
       elsif From not in Source'Range
         or else Through > Source'Last
       then
+         pragma Annotate
+           (CodePeer, False_Positive,
+            "test always false", "self fullfilling prophecy");
+
          --  In most cases this raises an exception, but the case of deleting
          --  a null string at the end of the current one is a special-case, and
          --  reflects the equivalence with Replace_String (RM A.4.3 (86/3)).
index d1d4b552845acc97b16d96023d9eb0f5ce5a9ab4..ab5bab3574fc86ef3a9df059a5a4ded1c2d67c61 100644 (file)
@@ -352,6 +352,9 @@ package body GNAT.Calendar is
 
    begin
       timeval_to_duration (T, sec'Access, usec'Access);
+      pragma Annotate (CodePeer, Modified, sec);
+      pragma Annotate (CodePeer, Modified, usec);
+
       return Duration (sec) + Duration (usec) / Micro;
    end To_Duration;
 
index dc2fa40656af0b7a26169ae45ce78910eb0df946..cc860abcf89d8f19e21d477773930c223a9f6d4b 100644 (file)
@@ -950,6 +950,8 @@ package body GNAT.Calendar.Time_IO is
       when End_Of_Source_Reached
          | Wrong_Syntax
       =>
+         Time :=
+           Time_Of (Year_Number'First, Month_Number'First, Day_Number'First);
          Success := False;
    end Parse_ISO_8861_UTC;
 
index ec057a9d94ff67f7ae256d744e3109a8b6a5a551..bb553e972437f7e2d59c7195353cdb0d3c9c427e 100644 (file)
@@ -537,6 +537,7 @@ package body GNAT.Command_Line is
       P      : Switch_Parameter_Type;
 
    begin
+      Param             := Parameter_None;
       Index_In_Switches := 0;
       Switch_Length     := 0;
 
index 52c0c508b327e276a1d47ceae1be427c7e0139c4..ae2fb1ce157245d5691bb82c9023f4cc90506a9e 100644 (file)
@@ -1420,6 +1420,7 @@ package body GNAT.Debug_Pools is
 
    begin
       Valid := Is_Valid (Storage_Address);
+      Size_In_Storage_Elements := Storage_Count'First;
 
       if Is_Valid (Storage_Address) then
          declare
index 9153c7055f93bc01fe4e15b1ecb3cfe94ba41f4c..0fd7a24d2ac5765299afcfd68851adb819f2c184 100644 (file)
@@ -352,6 +352,8 @@ package body GNAT.Directory_Operations is
       begin
          K := K + 1;
 
+         pragma Annotate (CodePeer, Modified, P);
+
          if P = '%' or else Path (K) = '{' then
 
             --  Set terminator character
index fec6e9c441d06521ddf2d81496aa840e44d5b73a..bf5487420b4ef901ff708d4e3dbf0ccc8c516114 100644 (file)
@@ -45,6 +45,8 @@ package body GNAT.Heap_Sort_G is
    --  from 2NlogN to NlogN.
 
    procedure Sort (N : Natural) is
+      pragma Annotate (CodePeer, Skip_Analysis);
+      --  CodePeer is sometimes getting confused on this procedure
 
       Max : Natural := N;
       --  Current Max index in tree being sifted
index 9b8825624f1ffbd7ff0603ddc2f33ff5e8bba53f..a65dc853c17e40979dd7d07cb489471a70b5737f 100644 (file)
@@ -622,6 +622,7 @@ package body GNAT.Perfect_Hash_Generators is
             E := Get_Edges (J);
 
             if Get_Graph (E.Y) = -1 then
+               pragma Assert (NK /= 0);
                Set_Graph (E.Y, (E.Key - Get_Graph (X)) mod NK);
                Assign (E.Y);
             end if;
@@ -2201,6 +2202,8 @@ package body GNAT.Perfect_Hash_Generators is
          --  in the position selection.
 
          for J in S'Range loop
+            pragma Annotate (CodePeer, Modified, S (J));
+
             if S (J).First = S (J).Last then
                F := S (J).First;
                L := S (J).Last;
@@ -2359,6 +2362,10 @@ package body GNAT.Perfect_Hash_Generators is
 
             for P in 1 .. Last_Sel_Pos - 1 loop
                if Max_Diff_Sel_Pos < Sel_Position (P) then
+                  pragma Annotate
+                    (CodePeer, False_Positive,
+                     "test always false", "false positive?");
+
                   Sel_Position (P + 1 .. Last_Sel_Pos) :=
                     Sel_Position (P .. Last_Sel_Pos - 1);
                   Sel_Position (P) := Max_Diff_Sel_Pos;
@@ -2525,6 +2532,7 @@ package body GNAT.Perfect_Hash_Generators is
             for J in 0 .. T1_Len - 1 loop
                exit when Word (J + 1) = ASCII.NUL;
                R := Get_Table (Table, J, Get_Used_Char (Word (J + 1)));
+               pragma Assert (NV /= 0);
                S := (S + R) mod NV;
             end loop;
 
@@ -2532,6 +2540,7 @@ package body GNAT.Perfect_Hash_Generators is
             for J in 0 .. T1_Len - 1 loop
                exit when Word (J + 1) = ASCII.NUL;
                R := Get_Table (Table, J, 0);
+               pragma Assert (NV /= 0);
                S := (S + R * Character'Pos (Word (J + 1))) mod NV;
             end loop;
       end case;
index 6c65424df6303874d4e66b016958dced0b1526c3..8f8c9d8179fd2e248172dec553825650f384c079 100644 (file)
@@ -836,6 +836,7 @@ package body GNAT.Sockets is
       --  the waiting task to resume its execution.
 
       Res := Signalling_Fds.Create (Two_Fds'Access);
+      pragma Annotate (CodePeer, Modified, Two_Fds);
 
       if Res = Failure then
          Raise_Socket_Error (Socket_Errno);
@@ -886,6 +887,7 @@ package body GNAT.Sockets is
         ((if Family = Family_Unspec then Default_Socket_Pair_Family
           else Families (Family)),
          Modes (Mode), Levels (Level), Pair'Access);
+      pragma Annotate (CodePeer, Modified, Pair);
 
       if Res = Failure then
          Raise_Socket_Error (Socket_Errno);
@@ -957,8 +959,12 @@ package body GNAT.Sockets is
       if Item.Last /= No_Socket then
          Get_Socket_From_Set
            (Item.Set'Access, Last => L'Access, Socket => S'Access);
+         pragma Annotate (CodePeer, Modified, L);
+         pragma Annotate (CodePeer, Modified, S);
+
          Item.Last := Socket_Type (L);
          Socket    := Socket_Type (S);
+
       else
          Socket := No_Socket;
       end if;
@@ -2921,8 +2927,7 @@ package body GNAT.Sockets is
    -- To_Int --
    ------------
 
-   function To_Int (F : Request_Flag_Type) return C.int
-   is
+   function To_Int (F : Request_Flag_Type) return C.int is
       Current : Request_Flag_Type := F;
       Result  : C.int := 0;
 
@@ -2932,6 +2937,10 @@ package body GNAT.Sockets is
 
          if Current mod 2 /= 0 then
             if Flags (J) = -1 then
+               pragma Annotate
+                 (CodePeer, False_Positive,
+                  "test always false", "self fulfilling prophecy");
+
                Raise_Socket_Error (SOSC.EOPNOTSUPP);
             end if;
 
index 807a3a1ef640afe21298f688b4d766fa2ed59f7c..6caa35145a8e97bb2145de60a4b0ba9f9a2b955a 100644 (file)
@@ -240,11 +240,6 @@ package body Interfaces.COBOL is
                            (COBOL_Character'Pos (K) -
                              COBOL_Character'Pos (COBOL_Digits'First));
 
-            elsif K in COBOL_Plus_Digits then
-               Result := Result * 10 +
-                           (COBOL_Character'Pos (K) -
-                             COBOL_Character'Pos (COBOL_Plus_Digits'First));
-
             elsif K in COBOL_Minus_Digits then
                Result := Result * 10 +
                            (COBOL_Character'Pos (K) -
index 5307eae2603cce5b7535b287f71060385e6c8ffe..674595338ef65efab1f5934e312029878f1db863 100644 (file)
@@ -440,6 +440,10 @@ package body System.Dwarf_Lines is
         or else Info_Sec = Null_Section
         or else Aranges_Sec = Null_Section
       then
+         pragma Annotate
+           (CodePeer, False_Positive,
+            "test always true", "codepeer got confused");
+
          C.Has_Debug := False;
          return;
       end if;
@@ -883,6 +887,7 @@ package body System.Dwarf_Lines is
       Success     :    out Boolean)
    is
    begin
+      Info_Offset := 0;
       Seek (C.Aranges, 0);
 
       while Tell (C.Aranges) < Length (C.Aranges) loop
@@ -905,6 +910,7 @@ package body System.Dwarf_Lines is
             end;
          end loop;
       end loop;
+
       Success := False;
    end Aranges_Lookup;
 
@@ -1028,6 +1034,7 @@ package body System.Dwarf_Lines is
       Has_Child     : uint8;
       pragma Unreferenced (Has_Child);
    begin
+      Line_Offset := 0;
       Success := False;
 
       Seek (C.Info, Info_Offset);
@@ -1119,7 +1126,8 @@ package body System.Dwarf_Lines is
       Version     : uint16;
       Sz          : uint8;
    begin
-      Success := False;
+      Success     := False;
+      Info_Offset := 0;
 
       Read_Initial_Length (C.Aranges, Unit_Length, Is64);
 
@@ -1407,6 +1415,7 @@ package body System.Dwarf_Lines is
       Success      : Boolean;
       Done         : Boolean;
       S            : Object_Symbol;
+
    begin
       --  Initialize result
       Dir_Name    := null;
@@ -1422,6 +1431,8 @@ package body System.Dwarf_Lines is
          begin
             First := C.Cache'First;
             Last  := C.Cache'Last;
+            Mid   := First;
+
             while First <= Last loop
                Mid := First + (Last - First) / 2;
                if Addr_Off < C.Cache (Mid).First then
@@ -1432,6 +1443,7 @@ package body System.Dwarf_Lines is
                   exit;
                end if;
             end loop;
+
             if Addr_Off >= C.Cache (Mid).First
               and then Addr_Off < C.Cache (Mid).First + C.Cache (Mid).Size
             then
@@ -1474,6 +1486,7 @@ package body System.Dwarf_Lines is
       C.Next_Prologue := 0;
       Initialize_State_Machine (C);
       Parse_Prologue (C);
+      Previous_Row.Line := 0;
 
       --  Advance to the first entry
 
@@ -1535,7 +1548,7 @@ package body System.Dwarf_Lines is
      (Cin          :        Dwarf_Context;
       Traceback    :        AET.Tracebacks_Array;
       Suppress_Hex :        Boolean;
-      Symbol_Found : in out Boolean;
+      Symbol_Found :    out Boolean;
       Res          : in out System.Bounded_Strings.Bounded_String)
    is
       use Ada.Characters.Handling;
index 297fd8e071702c517db3dd74d5d2d0e628834ef1..cfde1c64fc65978618c6dd5ab44da6441b19cf36 100644 (file)
@@ -93,7 +93,7 @@ package System.Dwarf_Lines is
      (Cin          :        Dwarf_Context;
       Traceback    :        AET.Tracebacks_Array;
       Suppress_Hex :        Boolean;
-      Symbol_Found : in out Boolean;
+      Symbol_Found :    out Boolean;
       Res          : in out System.Bounded_Strings.Bounded_String);
    --  Generate a string for a traceback suitable for displaying to the user.
    --  If one or more symbols are found, Symbol_Found is set to True. This
index 93237fbf59efdbf93080fe117a08b06eab0dee2c..481d672a2cdc7197c4bfb0c2b0f1889e975e1db3 100644 (file)
@@ -219,6 +219,10 @@ package body System.Fat_Gen is
                   Ax := Ax * R_Power (Expbits'Last);
                   Ex := Ex - Log_Power (Expbits'Last);
                end loop;
+               pragma Annotate
+                 (CodePeer, Intentional,
+                  "test always false",
+                  "expected for some instantiations");
 
                --  Rad ** -64 <= Ax < 1
 
index 406457138b58d9c4918b75fe5b5ed11cdb09ca6b..166b04ba7c1f3ca20914c889a8f98ef9afa48d51 100644 (file)
@@ -240,6 +240,8 @@ package body System.Generic_Array_Operations is
          for J in N'Range (2) loop
             N (Row - M'First (1) + N'First (1), J) :=
               N (Row - M'First (1) + N'First (1), J) / Scale;
+            pragma Annotate
+              (CodePeer, False_Positive, "divide by zero", "Scale /= 0");
          end loop;
       end Divide_Row;
 
@@ -602,6 +604,9 @@ package body System.Generic_Array_Operations is
          end if;
 
       elsif X > Real'Base'Last then
+         pragma Annotate
+           (CodePeer, Intentional,
+            "test always false", "test for infinity");
 
          --  X is infinity, which is its own square root
 
@@ -627,6 +632,8 @@ package body System.Generic_Array_Operations is
       --  of precision.
 
       for J in 1 .. 8 loop
+         pragma Assert (Root /= 0.0);
+
          Next := (Root + X / Root) / 2.0;
          exit when Root = Next;
          Root := Next;
index 0a92dfb3126e2c871a711c91194b1fde45218464..69d284fd1626f93a144d63ab13864da607b941f4 100644 (file)
@@ -733,6 +733,7 @@ package body System.Generic_Bignums is
             ND := 0;
             for J in 1 .. X.Len loop
                ND := Base * ND + DD (X.D (J));
+               pragma Assert (Div /= 0);
                Result (J) := SD (ND / Div);
                ND := ND rem Div;
             end loop;
index 467c482759d30eb10d6063f2de38043acf623f74..46cacd0ec0c043f1e8aabdb6cd5bfd761cf3fd9c 100644 (file)
@@ -289,6 +289,8 @@ package body System.Img_Real is
             --  What we are looking for is a power of ten to divide X by
             --  so that the result lies within the required range.
 
+            pragma Assert (Powten (Maxpow) /= 0.0);
+
             loop
                XP := X / Powten (Maxpow);
                exit when XP < Powten (S) or else Scale > Maxscaling;
@@ -490,6 +492,9 @@ package body System.Img_Real is
          --  an infinite value, so we print Inf.
 
          if V > Long_Long_Float'Last then
+            pragma Annotate
+              (CodePeer, Intentional, "test always true", "test for infinity");
+
             Set ('+');
             Set ('I');
             Set ('n');
index 258cd64d312ca6a043f0903ba1bb1cb46dcd66db..28fbbf3106440e5cc6e6693f6f00e113ebea020e 100644 (file)
@@ -574,14 +574,15 @@ package body System.OS_Lib is
                --  touch destination file at all.
 
                From := Open_Read (Name, Binary);
-               if From /= Invalid_FD then
+
+               if From = Invalid_FD then
+                  Success := False;
+               else
                   To := Open_Read_Write (Pathname, Binary);
+                  Lseek (To, 0, Seek_End);
+                  Copy (From, To);
                end if;
 
-               Lseek (To, 0, Seek_End);
-
-               Copy (From, To);
-
             --  Appending to directory, not allowed
 
             elsif Is_Directory (Pathname) then
@@ -1999,6 +2000,8 @@ package body System.OS_Lib is
 
                   --  If the string ends with \, double it
 
+                  pragma Annotate (CodePeer, Modified, Res (J - 1));
+
                   if Res (J - 1) = '\' then
                      Res (J) := '\';
                      J := J + 1;
index 05903135f346434b5b8490a0e6828af61f2755b5..1aa755c0144476beb4fb94a558d18b333e712d05 100644 (file)
@@ -295,6 +295,7 @@ is
             K      : Bit_Count;       --  Next decrement to exponent
 
          begin
+            K := 0;
             Mantissa := Random (Gen) / 2**Extra_Bits;
             R := Unsigned_32 (Mantissa mod 2**Extra_Bits);
             R_Bits := Extra_Bits;
index ae69f4782799bdba61dffacd447237298a49bd22..69fe1503f5993954fd94710af48d9e151d194901 100644 (file)
@@ -1460,19 +1460,9 @@ package body System.Regpat is
                  and then Expression (Parse_Pos + 1) /= ']'
                then
                   Parse_Pos := Parse_Pos + 1;
-
-                  --  Do we have a range like '\d-a' and '[:space:]-a'
-                  --  which is not a real range
-
-                  if Named_Class /= ANYOF_NONE then
-                     Set_In_Class (Bitmap, '-');
-                  else
-                     In_Range := True;
-                  end if;
-
+                  In_Range := True;
                else
                   Set_In_Class (Bitmap, Value);
-
                end if;
 
             --  Else in a character range
@@ -3275,13 +3265,13 @@ package body System.Regpat is
         (IP  : Pointer;
          Max : Natural := Natural'Last) return Natural
       is
-         Scan  : Natural := Input_Pos;
-         Last  : Natural;
-         Op    : constant Opcode := Opcode'Val (Character'Pos (Program (IP)));
-         Count : Natural;
-         C     : Character;
-         Is_First : Boolean := True;
-         Bitmap   : Character_Class;
+         Scan   : Natural := Input_Pos;
+         Last   : Natural;
+         Op     : constant Opcode :=
+           Opcode'Val (Character'Pos (Program (IP)));
+         Count  : Natural;
+         C      : Character;
+         Bitmap : Character_Class;
 
       begin
          if Max = Natural'Last or else Scan + Max - 1 > Last_In_Data then
@@ -3324,10 +3314,7 @@ package body System.Regpat is
                end loop;
 
             when ANYOF =>
-               if Is_First then
-                  Bitmap_Operand (Program, IP, Bitmap);
-                  Is_First := False;
-               end if;
+               Bitmap_Operand (Program, IP, Bitmap);
 
                while Scan <= Last
                  and then Get_From_Class (Bitmap, Data (Scan))
index b116a108ac43d96e4b695ce1b7c690b0a273d7b2..9f962757392f9d0bfc71e5737163b54b78d63363 100644 (file)
@@ -438,7 +438,7 @@ package body System.Traceback.Symbolic is
       Suppress_Hex :        Boolean;
       Res          : in out Bounded_String)
    is
-      Success : Boolean := False;
+      Success : Boolean;
    begin
       if Symbolic.Module_Name.Is_Supported then
          Append (Res, '[');
index 424ccd05f4e7ebe52571ea5a67d5cb42aef58027..2ecc99b29f9d4e260022a0698a5a8656b8474435 100644 (file)
@@ -92,8 +92,7 @@ package body System.Val_Real is
    -- As_Digit --
    --------------
 
-   function As_Digit (C : Character) return Char_As_Digit
-   is
+   function As_Digit (C : Character) return Char_As_Digit is
    begin
       case C is
          when '0' .. '9' =>
@@ -133,7 +132,9 @@ package body System.Val_Real is
 
       Trailing_Zeros : Natural := 0;
       --  Number of trailing zeros at a given point.
+
    begin
+      pragma Assert (Base in 2 .. 16);
 
       --  If initial Scale is not 0 then it means that Precision_Limit was
       --  reached during integral part scanning.
@@ -217,7 +218,6 @@ package body System.Val_Real is
             end if;
          end if;
       end loop;
-
    end Scan_Decimal_Digits;
 
    --------------------------
@@ -268,6 +268,8 @@ package body System.Val_Real is
             --  Precision limit has been reached so just update the exponent
             Scale := Scale + 1;
          else
+            pragma Assert (Base /= 0);
+
             if Value > (Precision_Limit - Digit) / Base then
                --  Updating Value will overflow so ignore this digit and any
                --  following ones. Only update the scale
@@ -369,6 +371,10 @@ package body System.Val_Real is
 
       --  First character can be either a decimal digit or a dot.
       if Str (Index) in '0' .. '9' then
+         pragma Annotate
+           (CodePeer, Intentional,
+            "test always true", "defensive code below");
+
          --  If this is a digit it can indicates either the float decimal
          --  part or the base to use
          Scan_Integral_Digits
index 8617ea7a930dc1950949a5d958c603da1d48dbd1..5536e6d66c1dfba0d81dda6cc1c3d63dac2513bd 100644 (file)
@@ -458,8 +458,7 @@ package body Sem_Case is
          Choice      : Node_Id;
          Choice_Hi   : Uint;
          Choice_Lo   : Uint;
-         Prev_Choice : Node_Id;
-         pragma Warnings (Off, Prev_Choice);
+         Prev_Choice : Node_Id := Empty;
          Prev_Hi     : Uint;
 
       begin
@@ -485,6 +484,8 @@ package body Sem_Case is
                   end if;
                end loop;
 
+               pragma Assert (Present (Prev_Choice));
+
                if Sloc (Prev_Choice) <= Sloc (Choice) then
                   Error_Msg_Sloc := Sloc (Prev_Choice);
                   Dup_Choice (Choice_Lo, UI_Min (Choice_Hi, Prev_Hi), Choice);
index 6287434426eb626acbe7a78ca71891f2a4d5ff52..38943935e51b12a963bffcaab2bc0eb3d7729d81 100644 (file)
@@ -1580,7 +1580,7 @@ package body Sem_Ch13 is
       --  Local variables
 
       Aspect : Node_Id;
-      Aitem  : Node_Id;
+      Aitem  : Node_Id := Empty;
       Ent    : Node_Id;
 
       L : constant List_Id := Aspect_Specifications (N);
@@ -10136,8 +10136,8 @@ package body Sem_Ch13 is
       Rectype : Entity_Id;
       Fent    : Entity_Id;
       CC      : Node_Id;
-      Fbit    : Uint;
-      Lbit    : Uint;
+      Fbit    : Uint := No_Uint;
+      Lbit    : Uint := No_Uint;
       Hbit    : Uint := Uint_0;
       Comp    : Entity_Id;
       Pcomp   : Entity_Id;
@@ -10485,6 +10485,7 @@ package body Sem_Ch13 is
                Nbit := Sbit;
                for J in 1 .. Ncomps loop
                   CEnt := Comps (J);
+                  pragma Annotate (CodePeer, Modified, CEnt);
 
                   declare
                      CBO : constant Uint := Component_Bit_Offset (CEnt);
index 2342c544b32e0b46fccf54abe99d44a6b8629605..3f859c2b08fcc932313c333a6b8720aefb1313fe 100644 (file)
@@ -1847,7 +1847,7 @@ package body Sem_Ch5 is
       Save_Unblocked_Exit_Count : constant Nat := Unblocked_Exit_Count;
       --  Recursively save value of this global, will be restored on exit
 
-      Save_In_Deleted_Code : Boolean;
+      Save_In_Deleted_Code : Boolean := In_Deleted_Code;
 
       Del : Boolean := False;
       --  This flag gets set True if a True condition has been found, which
index 77cd051bfe91fd86635a0d751dbe7d693857ce7d..7aa48b5a8764d2ca6c07f4fd2496887cfb69eb61 100644 (file)
@@ -30079,7 +30079,7 @@ package body Sem_Prag is
       --  explicit contract.
 
       Prags        : constant Node_Id := Contract (Parent_Subp);
-      In_Spec_Expr : Boolean;
+      In_Spec_Expr : Boolean := In_Spec_Expression;
       Installed    : Boolean;
       Prag         : Node_Id;
       New_Prag     : Node_Id;
index c1b1d9ef233363702fd9df012da8d5d34c7bd59c..814d5039867cdd39fb7237e7cf1c9ca0d113824e 100644 (file)
@@ -2759,7 +2759,7 @@ package body Sem_Util is
                   declare
                      Count_Components   : Uint := Uint_0;
                      Num_Components     : Uint;
-                     Others_Assoc       : Node_Id;
+                     Others_Assoc       : Node_Id := Empty;
                      Others_Choice      : Node_Id := Empty;
                      Others_Box_Present : Boolean := False;
 
@@ -2844,6 +2844,8 @@ package body Sem_Util is
                            --  minimum decoration required to collect the
                            --  identifiers.
 
+                           pragma Assert (Present (Others_Assoc));
+
                            if not Expander_Active then
                               Comp_Expr := Expression (Others_Assoc);
                            else
@@ -13269,7 +13271,7 @@ package body Sem_Util is
    procedure Insert_Explicit_Dereference (N : Node_Id) is
       New_Prefix : constant Node_Id := Relocate_Node (N);
       Ent        : Entity_Id := Empty;
-      Pref       : Node_Id;
+      Pref       : Node_Id := Empty;
       I          : Interp_Index;
       It         : Interp;
       T          : Entity_Id;
index 61e9f3d1be454c502ef13b9f84047abe6b14903b..bfdcb29f7dfef914c21246d55f044d73b61f4bd5 100644 (file)
@@ -1294,6 +1294,7 @@ package body Uintp is
                   Discard_Int : Int;
                   pragma Warnings (Off, Discard_Int);
                begin
+                  pragma Assert (D /= Int'(0));
                   UI_Div_Vector
                     (Dividend (Dividend'Last - R_Length + 1 .. Dividend'Last),
                      D,
index cf79c07d54d423556d5d895b3e187b31833ed6a8..de31a065143f7fce8068f33c35ac6c7f632d4a3a 100644 (file)
@@ -568,6 +568,9 @@ package body Urealp is
       Num  : Uint;
 
    begin
+      pragma Annotate (CodePeer, Modified, Lval);
+      pragma Annotate (CodePeer, Modified, Rval);
+
       --  Note, in the temporary Ureal_Entry values used in this procedure,
       --  we store the sign as the sign of the numerator (i.e. xxx.Num may
       --  be negative, even though in stored entries this can never be so)
@@ -685,6 +688,8 @@ package body Urealp is
       Rneg : constant Boolean     := Rval.Negative xor Lval.Negative;
 
    begin
+      pragma Annotate (CodePeer, Modified, Lval);
+      pragma Annotate (CodePeer, Modified, Rval);
       pragma Assert (Rval.Num /= Uint_0);
 
       if Lval.Rbase = 0 then
index 7c72e4e299b7168eb1b2e2633efc48374df8e44b..68784f2a3d88ef3a8b7ef4e01821e8de740aa994 100644 (file)
@@ -494,6 +494,9 @@ procedure XOSCons is
       Value1 := Get_Value (Slice (Sline, 2));
       Value2 := Get_Value (Slice (Sline, 4));
 
+      pragma Annotate (CodePeer, Modified, Value1);
+      pragma Annotate (CodePeer, Modified, Value2);
+
       if Slice (Sline, 3) = ">" then
          Res := Cond and (Value1 > Value2);
 
@@ -619,7 +622,7 @@ procedure XOSCons is
    Current_Line : Integer;
    Current_Info : Integer;
    In_Comment   : Boolean;
-   In_Template  : Boolean;
+   In_Template  : Boolean := False;
 
 --  Start of processing for XOSCons
 
index a3c962329e23db334c309c1b1d8b8c62097faae9..604e97932e91f2008b9a57c325dfa1d5bfdfdfb6 100644 (file)
@@ -1015,12 +1015,12 @@ package body Xr_Tabls is
       Decl         : Declaration_Reference := Entities_HTable.Get_First;
       Arr          : Reference_Array_Access;
       Index        : Natural;
-      End_Index    : Natural;
+      End_Index    : Natural := 0;
       Current_File : File_Reference;
       Current_Line : Cst_String_Access;
       Buffer       : GNAT.OS_Lib.String_Access;
       Ref          : Reference;
-      Line         : Natural;
+      Line         : Natural := Natural'Last;
 
    begin
       --  Create a temporary array, where all references will be
index eabf8b450e8cd403d06c9c51b28fc692e4b1bc03..ca988ddbaad0e547764d4698be3bff9f7bf936b8 100644 (file)
@@ -23,6 +23,8 @@
 --                                                                          --
 ------------------------------------------------------------------------------
 
+pragma Ada_2012;
+
 with Osint;
 with Output; use Output;
 with Types;  use Types;
@@ -767,13 +769,14 @@ package body Xref_Lib is
 
       E_Line   : Natural;   --  Line number of current entity
       E_Col    : Natural;   --  Column number of current entity
-      E_Type   : Character; --  Type of current entity
       E_Name   : Positive;  --  Pointer to begin of entity name
       E_Global : Boolean;   --  True iff entity is global
+      E_Type   : Character; --  Type of current entity
 
       R_Line   : Natural;   --  Line number of current reference
       R_Col    : Natural;   --  Column number of current reference
-      R_Type   : Character; --  Type of current reference
+
+      R_Type   : Character := ASCII.NUL; --  Type of current reference
 
       Decl_Ref : Declaration_Reference;
       File_Ref : File_Reference := Current_Xref_File (File);
@@ -876,18 +879,19 @@ package body Xref_Lib is
       if Ali (Ptr) > ' ' then
          E_Type := Ali (Ptr);
          Ptr := Ptr + 1;
-      end if;
 
-      --  Ignore some of the entities (labels,...)
+         --  Ignore some of the entities (labels,...)
 
-      case E_Type is
-         when 'l' | 'L' | 'q' =>
+         if E_Type in 'l' | 'L' | 'q' then
             Parse_EOL (Ali, Ptr, Skip_Continuation_Line => True);
             return;
+         end if;
+      else
+         --  Unexpected contents, skip line and return
 
-         when others =>
-            null;
-      end case;
+         Parse_EOL (Ali, Ptr, Skip_Continuation_Line => True);
+         return;
+      end if;
 
       Parse_Number (Ali, Ptr, E_Col);
 
@@ -966,7 +970,7 @@ package body Xref_Lib is
             Parse_Derived_Info : declare
                P_Line   : Natural;          --  parent entity line
                P_Column : Natural;          --  parent entity column
-               P_Eun    : Positive;         --  parent entity file number
+               P_Eun    : Natural := 0;     --  parent entity file number
 
             begin
                Parse_Number (Ali, Ptr, P_Line);
@@ -1010,6 +1014,8 @@ package body Xref_Lib is
                --  on or if we want to output the type hierarchy
 
                if Der_Info or else Type_Tree then
+                  pragma Assert (P_Eun /= 0);
+
                   declare
                      Symbol : constant String :=
                                 Get_Symbol_Name (P_Eun, P_Line, P_Column);
@@ -1126,8 +1132,8 @@ package body Xref_Lib is
             --    5U14*Foo2 5>20 6b<c,myfoo2>22   # Imported entity
             --    5U14*Foo2 5>20 6i<c,myfoo2>22   # Exported entity
 
-            if (R_Type = 'b' or else R_Type = 'i')
-              and then Ali (Ptr) = '<'
+            if Ali (Ptr) = '<'
+              and then (R_Type = 'b' or else R_Type = 'i')
             then
                while Ptr <= Ali'Last
                  and then Ali (Ptr) /= '>'
@@ -1139,6 +1145,8 @@ package body Xref_Lib is
 
             Parse_Number (Ali, Ptr, R_Col);
 
+            pragma Assert (R_Type /= ASCII.NUL);
+
             --  Insert the reference or body in the table
 
             Add_Reference