This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[Ada] Fix warnings about uninitialized variables


Bootstrapped/regtested on GNU Linux/x86.

2001-10-30  Geert Bosch <bosch@gnat.com>

	* ali-util.adb (Initialize_Checksum): Use out-mode instead of in out. 
	Found due to GCC 3.0 warning of using uninitialized value.
	
	* layout.adb:
	(Get_Max_Size): Use variant record for tracking value/expression.
	 Makes logic clearer and prevents warnings for uninitialized variables.
	(Layout_Array_Type): Use variant record for tracking value/expression.
	 Makes logic clearer and prevents warnings for uninitialized variables.

*** ali-util.adb	2001/09/29 03:23:46	1.9
--- ali-util.adb	2001/10/26 22:10:00	1.10
***************
*** 50,56 ****
     --  generate code, so it is not necessary to worry about making the right
     --  sequence of calls in any error situation.
  
!    procedure Initialize_Checksum (Csum : in out Word);
     --  Sets initial value of Csum before any calls to Accumulate_Checksum
  
     -------------------------
--- 50,56 ----
     --  generate code, so it is not necessary to worry about making the right
     --  sequence of calls in any error situation.
  
!    procedure Initialize_Checksum (Csum : out Word);
     --  Sets initial value of Csum before any calls to Accumulate_Checksum
  
     -------------------------
***************
*** 286,292 ****
     -- Initialize_Checksum --
     -------------------------
  
!    procedure Initialize_Checksum (Csum : in out Word) is
     begin
        System.CRC32.Initialize (System.CRC32.CRC32 (Csum));
     end Initialize_Checksum;
--- 286,292 ----
     -- Initialize_Checksum --
     -------------------------
  
!    procedure Initialize_Checksum (Csum : out Word) is
     begin
        System.CRC32.Initialize (System.CRC32.CRC32 (Csum));
     end Initialize_Checksum;

*** layout.adb	2001/10/18 00:41:15	1.34
--- layout.adb	2001/10/30 20:19:35	1.35
***************
*** 579,599 ****
        Len  : Node_Id;
  
        type Val_Status_Type is (Const, Dynamic);
        --  Shows the status of the value so far. Const means that the value
!       --  is constant, and Sval is the current constant value. Dynamic means
!       --  that the value is dynamic, and in this case Snod is the Node_Id of
        --  the expression to compute the value.
- 
-       Val_Status : Val_Status_Type;
-       --  Indicate status of value so far
  
!       Sval : Uint := Uint_0;
!       --  Calculated value so far if Val_Status = Const
!       --  (initialized to prevent junk warning)
  
-       Snod : Node_Id;
-       --  Expression value so far if Val_Status = Dynamic
- 
        SU_Convert_Required : Boolean := False;
        --  This is set to True if the final result must be converted from
        --  bits to storage units (rounding up to a storage unit boundary).
--- 578,600 ----
        Len  : Node_Id;
  
        type Val_Status_Type is (Const, Dynamic);
+ 
+       type Val_Type (Status : Val_Status_Type := Const) is
+          record
+             case Status is
+                when Const   => Val : Uint;
+                when Dynamic => Nod : Node_Id;
+             end case;
+          end record;
        --  Shows the status of the value so far. Const means that the value
!       --  is constant, and Val is the current constant value. Dynamic means
!       --  that the value is dynamic, and in this case Nod is the Node_Id of
        --  the expression to compute the value.
  
!       Size : Val_Type;
!       --  Calculated value so far if Size.Status = Const,
!       --  or expression value so far if Size.Status = Dynamic.
  
        SU_Convert_Required : Boolean := False;
        --  This is set to True if the final result must be converted from
        --  bits to storage units (rounding up to a storage unit boundary).
***************
*** 644,655 ****
        --  Initialize status from component size
  
        if Known_Static_Component_Size (E) then
!          Val_Status := Const;
!          Sval := Component_Size (E);
  
        else
!          Val_Status := Dynamic;
!          Snod := Expr_From_SO_Ref (Loc, Component_Size (E));
        end if;
  
        --  Loop through indices
--- 645,654 ----
        --  Initialize status from component size
  
        if Known_Static_Component_Size (E) then
!          Size := (Const, Component_Size (E));
  
        else
!          Size := (Dynamic, Expr_From_SO_Ref (Loc, Component_Size (E)));
        end if;
  
        --  Loop through indices
***************
*** 678,685 ****
  
              --  Current value is constant, evolve value
  
!             if Val_Status = Const then
!                Sval := Sval * S;
  
              --  Current value is dynamic
  
--- 677,684 ----
  
              --  Current value is constant, evolve value
  
!             if Size.Status = Const then
!                Size.Val := Size.Val * S;
  
              --  Current value is dynamic
  
***************
*** 695,703 ****
                    SU_Convert_Required := False;
                 end if;
  
!                Snod :=
                   Assoc_Multiply (Loc,
!                    Left_Opnd  => Snod,
                     Right_Opnd =>
                       Make_Integer_Literal (Loc, Intval => S));
              end if;
--- 694,702 ----
                    SU_Convert_Required := False;
                 end if;
  
!                Size.Nod :=
                   Assoc_Multiply (Loc,
!                    Left_Opnd  => Size.Nod,
                     Right_Opnd =>
                       Make_Integer_Literal (Loc, Intval => S));
              end if;
***************
*** 712,727 ****
              --  we want to do the SU conversion after computing the size in
              --  this case.
  
!             if Val_Status = Const then
!                Val_Status := Dynamic;
  
                 --  If the current value is a multiple of the storage unit,
                 --  then most certainly we can do the conversion now, simply
                 --  by dividing the current value by the storage unit value.
                 --  If this works, we set SU_Convert_Required to False.
  
!                if Sval mod SSU = 0 then
!                   Snod := Make_Integer_Literal (Loc, Sval / SSU);
                    SU_Convert_Required := False;
  
                 --  Otherwise, we go ahead and convert the value in bits,
--- 711,727 ----
              --  we want to do the SU conversion after computing the size in
              --  this case.
  
!             if Size.Status = Const then
  
                 --  If the current value is a multiple of the storage unit,
                 --  then most certainly we can do the conversion now, simply
                 --  by dividing the current value by the storage unit value.
                 --  If this works, we set SU_Convert_Required to False.
+ 
+                if Size.Val mod SSU = 0 then
  
!                   Size :=
!                     (Dynamic, Make_Integer_Literal (Loc, Size.Val / SSU));
                    SU_Convert_Required := False;
  
                 --  Otherwise, we go ahead and convert the value in bits,
***************
*** 729,735 ****
                 --  final value is indeed properly converted.
  
                 else
!                   Snod := Make_Integer_Literal (Loc, Sval);
                    SU_Convert_Required := True;
                 end if;
              end if;
--- 729,735 ----
                 --  final value is indeed properly converted.
  
                 else
!                   Size := (Dynamic, Make_Integer_Literal (Loc, Size.Val));
                    SU_Convert_Required := True;
                 end if;
              end if;
***************
*** 771,778 ****
        --  Here after processing all bounds to set sizes. If the value is
        --  a constant, then it is bits, and we just return the value.
  
!       if Val_Status = Const then
!          return Make_Integer_Literal (Loc, Sval);
  
        --  Case where the value is dynamic
  
--- 771,778 ----
        --  Here after processing all bounds to set sizes. If the value is
        --  a constant, then it is bits, and we just return the value.
  
!       if Size.Status = Const then
!          return Make_Integer_Literal (Loc, Size.Val);
  
        --  Case where the value is dynamic
  
***************
*** 781,798 ****
  
           if SU_Convert_Required then
  
!             --  The expression required is (Snod + SU - 1) / SU
  
!             Snod :=
                Make_Op_Divide (Loc,
                  Left_Opnd =>
                    Make_Op_Add (Loc,
!                     Left_Opnd  => Snod,
                      Right_Opnd => Make_Integer_Literal (Loc, SSU - 1)),
                  Right_Opnd => Make_Integer_Literal (Loc, SSU));
           end if;
  
!          return Snod;
        end if;
     end Get_Max_Size;
  
--- 781,798 ----
  
           if SU_Convert_Required then
  
!             --  The expression required is (Size.Nod + SU - 1) / SU
  
!             Size.Nod :=
                Make_Op_Divide (Loc,
                  Left_Opnd =>
                    Make_Op_Add (Loc,
!                     Left_Opnd  => Size.Nod,
                      Right_Opnd => Make_Integer_Literal (Loc, SSU - 1)),
                  Right_Opnd => Make_Integer_Literal (Loc, SSU));
           end if;
  
!          return Size.Nod;
        end if;
     end Get_Max_Size;
  
***************
*** 838,870 ****
        --  question, and whose body is the expression.
  
        type Val_Status_Type is (Const, Dynamic, Discrim);
!       --  Shows the status of the value so far. Const means that the value
!       --  is constant, and Sval is the current constant value. Dynamic means
!       --  that the value is dynamic, and in this case Snod is the Node_Id of
!       --  the expression to compute the value, and Discrim means that at least
!       --  one bound is a discriminant, in which case Snod is the expression so
!       --  far (which will be the body of the function).
! 
!       Val_Status : Val_Status_Type;
!       --  Indicate status of value so far
! 
!       Sval : Uint := Uint_0;
!       --  Calculated value so far if Val_Status = Const
!       --  Initialized to prevent junk warning
! 
!       Snod : Node_Id;
!       --  Expression value so far if Val_Status /= Const
! 
!       Vtyp : Entity_Id;
!       --  Variant record type for the formal parameter of the discriminant
!       --  function V if Val_Status = Discrim.
  
        SU_Convert_Required : Boolean := False;
        --  This is set to True if the final result must be converted from
        --  bits to storage units (rounding up to a storage unit boundary).
  
        procedure Discrimify (N : in out Node_Id);
!       --  If N represents a discriminant, then the Val_Status is set to
        --  Discrim, and Vtyp is set. The parameter N is replaced with the
        --  proper expression to extract the discriminant value from V.
  
--- 838,877 ----
        --  question, and whose body is the expression.
  
        type Val_Status_Type is (Const, Dynamic, Discrim);
! 
!       type Val_Type (Status : Val_Status_Type := Const) is
!          record
!             case Status is
!                when Const =>
!                   Val : Uint;
!                   --  Calculated value so far if Val_Status = Const
! 
!                when Dynamic | Discrim =>
!                   Nod : Node_Id;
!                   --  Expression value so far if Val_Status /= Const
! 
!             end case;
!          end record;
!       --  Records the value or expression computed so far. Const means that
!       --  the value is constant, and Val is the current constant value.
!       --  Dynamic means that the value is dynamic, and in this case Nod is
!       --  the Node_Id of the expression to compute the value, and Discrim
!       --  means that at least one bound is a discriminant, in which case Nod
!       --  is the expression so far (which will be the body of the function).
! 
!       Size : Val_Type;
!       --  Value of size computed so far. See comments above.
! 
!       Vtyp : Entity_Id := Empty;
!       --  Variant record type for the formal parameter of the
!       --  discriminant function V if Status = Discrim.
  
        SU_Convert_Required : Boolean := False;
        --  This is set to True if the final result must be converted from
        --  bits to storage units (rounding up to a storage unit boundary).
  
        procedure Discrimify (N : in out Node_Id);
!       --  If N represents a discriminant, then the Size.Status is set to
        --  Discrim, and Vtyp is set. The parameter N is replaced with the
        --  proper expression to extract the discriminant value from V.
  
***************
*** 882,890 ****
           then
              Set_Size_Depends_On_Discriminant (E);
  
!             if Val_Status /= Discrim then
!                Val_Status := Discrim;
                 Decl := Parent (Parent (Entity (N)));
                 Vtyp := Defining_Identifier (Decl);
              end if;
  
--- 889,897 ----
           then
              Set_Size_Depends_On_Discriminant (E);
  
!             if Size.Status /= Discrim then
                 Decl := Parent (Parent (Entity (N)));
+                Size := (Discrim, Size.Nod);
                 Vtyp := Defining_Identifier (Decl);
              end if;
  
***************
*** 945,956 ****
        --  Initialize status from component size
  
        if Known_Static_Component_Size (E) then
!          Val_Status := Const;
!          Sval := Component_Size (E);
  
        else
!          Val_Status := Dynamic;
!          Snod := Expr_From_SO_Ref (Loc, Component_Size (E));
        end if;
  
        --  Loop to process array indices
--- 952,961 ----
        --  Initialize status from component size
  
        if Known_Static_Component_Size (E) then
!          Size := (Const, Component_Size (E));
  
        else
!          Size := (Dynamic, Expr_From_SO_Ref (Loc, Component_Size (E)));
        end if;
  
        --  Loop to process array indices
***************
*** 978,985 ****
  
              --  If constant, evolve value
  
!             if Val_Status = Const then
!                Sval := Sval * S;
  
              --  Current value is dynamic
  
--- 983,990 ----
  
              --  If constant, evolve value
  
!             if Size.Status = Const then
!                Size.Val := Size.Val * S;
  
              --  Current value is dynamic
  
***************
*** 997,1005 ****
  
                 --  Now go ahead and evolve the expression
  
!                Snod :=
                   Assoc_Multiply (Loc,
!                    Left_Opnd  => Snod,
                     Right_Opnd =>
                       Make_Integer_Literal (Loc, Intval => S));
              end if;
--- 1002,1010 ----
  
                 --  Now go ahead and evolve the expression
  
!                Size.Nod :=
                   Assoc_Multiply (Loc,
!                    Left_Opnd  => Size.Nod,
                     Right_Opnd =>
                       Make_Integer_Literal (Loc, Intval => S));
              end if;
***************
*** 1014,1029 ****
              --  we want to do the SU conversion after computing the size in
              --  this case.
  
!             if Val_Status = Const then
!                Val_Status := Dynamic;
  
                 --  If the current value is a multiple of the storage unit,
                 --  then most certainly we can do the conversion now, simply
                 --  by dividing the current value by the storage unit value.
                 --  If this works, we set SU_Convert_Required to False.
  
!                if Sval mod SSU = 0 then
!                   Snod := Make_Integer_Literal (Loc, Sval / SSU);
                    SU_Convert_Required := False;
  
                 --  Otherwise, we go ahead and convert the value in bits,
--- 1019,1034 ----
              --  we want to do the SU conversion after computing the size in
              --  this case.
  
!             if Size.Status = Const then
  
                 --  If the current value is a multiple of the storage unit,
                 --  then most certainly we can do the conversion now, simply
                 --  by dividing the current value by the storage unit value.
                 --  If this works, we set SU_Convert_Required to False.
  
!                if Size.Val mod SSU = 0 then
!                   Size :=
!                     (Dynamic, Make_Integer_Literal (Loc, Size.Val / SSU));
                    SU_Convert_Required := False;
  
                 --  Otherwise, we go ahead and convert the value in bits,
***************
*** 1031,1037 ****
                 --  final value is indeed properly converted.
  
                 else
!                   Snod := Make_Integer_Literal (Loc, Sval);
                    SU_Convert_Required := True;
                 end if;
              end if;
--- 1036,1042 ----
                 --  final value is indeed properly converted.
  
                 else
!                   Size := (Dynamic, Make_Integer_Literal (Loc, Size.Val));
                    SU_Convert_Required := True;
                 end if;
              end if;
***************
*** 1079,1087 ****
  
              --  At this stage, Len has the expression for the length
  
!             Snod :=
                Assoc_Multiply (Loc,
!                 Left_Opnd  => Snod,
                  Right_Opnd => Len);
           end if;
  
--- 1084,1092 ----
  
              --  At this stage, Len has the expression for the length
  
!             Size.Nod :=
                Assoc_Multiply (Loc,
!                 Left_Opnd  => Size.Nod,
                  Right_Opnd => Len);
           end if;
  
***************
*** 1092,1099 ****
        --  a constant, then it is bits, and the only thing we need to do
        --  is to check against explicit given size and do alignment adjust.
  
!       if Val_Status = Const then
!          Set_And_Check_Static_Size (E, Sval, Sval);
           Adjust_Esize_Alignment (E);
  
        --  Case where the value is dynamic
--- 1097,1104 ----
        --  a constant, then it is bits, and the only thing we need to do
        --  is to check against explicit given size and do alignment adjust.
  
!       if Size.Status = Const then
!          Set_And_Check_Static_Size (E, Size.Val, Size.Val);
           Adjust_Esize_Alignment (E);
  
        --  Case where the value is dynamic
***************
*** 1103,1123 ****
  
           if SU_Convert_Required then
  
!             --  The expression required is (Snod + SU - 1) / SU
  
!             Snod :=
                Make_Op_Divide (Loc,
                  Left_Opnd =>
                    Make_Op_Add (Loc,
!                     Left_Opnd  => Snod,
                      Right_Opnd => Make_Integer_Literal (Loc, SSU - 1)),
                  Right_Opnd => Make_Integer_Literal (Loc, SSU));
           end if;
  
           --  Now set the dynamic size (the Value_Size is always the same
           --  as the Object_Size for arrays whose length is dynamic).
  
!          Set_Esize (E, SO_Ref_From_Expr (Snod, Insert_Typ, Vtyp));
           Set_RM_Size (E, Esize (E));
        end if;
     end Layout_Array_Type;
--- 1108,1132 ----
  
           if SU_Convert_Required then
  
!             --  The expression required is (Size.Nod + SU - 1) / SU
  
!             Size.Nod :=
                Make_Op_Divide (Loc,
                  Left_Opnd =>
                    Make_Op_Add (Loc,
!                     Left_Opnd  => Size.Nod,
                      Right_Opnd => Make_Integer_Literal (Loc, SSU - 1)),
                  Right_Opnd => Make_Integer_Literal (Loc, SSU));
           end if;
  
           --  Now set the dynamic size (the Value_Size is always the same
           --  as the Object_Size for arrays whose length is dynamic).
+ 
+          --  ??? If Size.Status = Dynamic, Vtyp will not have been set.
+          --  The added initialization sets it to Empty now, but is this
+          --  correct?
  
!          Set_Esize (E, SO_Ref_From_Expr (Size.Nod, Insert_Typ, Vtyp));
           Set_RM_Size (E, Esize (E));
        end if;
     end Layout_Array_Type;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]