Commit 3f1ede06 by Robert Dewar Committed by Arnaud Charlet

freeze.adb: Add handling of Last_Assignment field

2006-10-31  Robert Dewar  <dewar@adacore.com>
	    Ed Schonberg  <schonberg@adacore.com>

	* freeze.adb: Add handling of Last_Assignment field
	(Warn_Overlay): Supply missing continuation marks in error msgs
	(Freeze_Entity): Add check for Preelaborable_Initialization

	* g-comlin.adb: Add Warnings (Off) to prevent new warning

	* g-expect.adb: Add Warnings (Off) to prevent new warning

	* lib-xref.adb: Add handling of Last_Assignment field
	(Generate_Reference): Centralize handling of pragma Obsolescent here
	(Generate_Reference): Accept an implicit reference generated for a
	default in an instance.
	(Generate_Reference): Accept a reference for a node that is not in the
	main unit, if it is the generic body corresponding to an subprogram
	instantiation.

	* xref_lib.adb: Add pragma Warnings (Off) to avoid new warnings

        * sem_warn.ads, sem_warn.adb (Set_Warning_Switch): Add processing for
	-gnatwq/Q.
	(Warn_On_Useless_Assignment): Suppress warning if enclosing inner
	exception handler.
	(Output_Obsolescent_Entity_Warnings): Rewrite to avoid any messages on
	use clauses, to avoid messages on packages used to qualify, and also
	to avoid messages from obsolescent units.
	(Warn_On_Useless_Assignments): Don't generate messages for imported
	and exported variables.
	(Warn_On_Useless_Assignments): New procedure
	(Output_Obsolescent_Entity_Warnings): New procedure
	(Check_Code_Statement): New procedure

        * einfo.ads, einfo.adb (Has_Static_Discriminants): New flag
	Change name Is_Ada_2005 to Is_Ada_2005_Only
	(Last_Assignment): New field for useless assignment warning

From-SVN: r118271
parent ac3b962e
...@@ -887,31 +887,12 @@ package body Freeze is ...@@ -887,31 +887,12 @@ package body Freeze is
(T : Entity_Id) return Boolean (T : Entity_Id) return Boolean
is is
Constraint : Elmt_Id; Constraint : Elmt_Id;
Discr : Entity_Id;
begin begin
if Has_Discriminants (T) if Has_Discriminants (T)
and then Present (Discriminant_Constraint (T)) and then Present (Discriminant_Constraint (T))
and then Present (First_Component (T)) and then Present (First_Component (T))
then then
Discr := First_Discriminant (T);
if Is_Access_Type (Etype (Discr)) then
null;
-- If the bounds of the discriminant are not compile-time known,
-- treat this as non-static, even if the value of the discriminant
-- is compile-time known, because the back-end treats aggregates
-- of such a subtype as having unknown size.
elsif not
(Compile_Time_Known_Value (Type_Low_Bound (Etype (Discr)))
and then
Compile_Time_Known_Value (Type_High_Bound (Etype (Discr))))
then
return False;
end if;
Constraint := First_Elmt (Discriminant_Constraint (T)); Constraint := First_Elmt (Discriminant_Constraint (T));
while Present (Constraint) loop while Present (Constraint) loop
if not Compile_Time_Known_Value (Node (Constraint)) then if not Compile_Time_Known_Value (Node (Constraint)) then
...@@ -2453,6 +2434,16 @@ package body Freeze is ...@@ -2453,6 +2434,16 @@ package body Freeze is
-- Case of a type or subtype being frozen -- Case of a type or subtype being frozen
else else
-- Check preelaborable initialization for full type completing a
-- private type for which pragma Preelaborable_Initialization given.
if Must_Have_Preelab_Init (E)
and then not Has_Preelaborable_Initialization (E)
then
Error_Msg_N
("full view of & does not have preelaborable initialization", E);
end if;
-- The type may be defined in a generic unit. This can occur when -- The type may be defined in a generic unit. This can occur when
-- freezing a generic function that returns the type (which is -- freezing a generic function that returns the type (which is
-- defined in a parent unit). It is clearly meaningless to freeze -- defined in a parent unit). It is clearly meaningless to freeze
...@@ -3014,7 +3005,7 @@ package body Freeze is ...@@ -3014,7 +3005,7 @@ package body Freeze is
Freeze_Subprogram (E); Freeze_Subprogram (E);
-- AI-326: Check wrong use of tag incomplete type -- Ada 2005 (AI-326): Check wrong use of tag incomplete type
-- --
-- type T is tagged; -- type T is tagged;
-- type Acc is access function (X : T) return T; -- ERROR -- type Acc is access function (X : T) return T; -- ERROR
...@@ -4503,11 +4494,15 @@ package body Freeze is ...@@ -4503,11 +4494,15 @@ package body Freeze is
-- Reset True_Constant flag, since something strange is going on with -- Reset True_Constant flag, since something strange is going on with
-- the scoping here, and our simple value tracing may not be sufficient -- the scoping here, and our simple value tracing may not be sufficient
-- for this indication to be reliable. We kill the Constant_Value -- for this indication to be reliable. We kill the Constant_Value
-- indication for the same reason. -- and Last_Assignment indications for the same reason.
Set_Is_True_Constant (E, False); Set_Is_True_Constant (E, False);
Set_Current_Value (E, Empty); Set_Current_Value (E, Empty);
if Ekind (E) = E_Variable then
Set_Last_Assignment (E, Empty);
end if;
exception exception
when Cannot_Be_Static => when Cannot_Be_Static =>
...@@ -5091,7 +5086,8 @@ package body Freeze is ...@@ -5091,7 +5086,8 @@ package body Freeze is
and then Present (Packed_Array_Type (Etype (Comp))) and then Present (Packed_Array_Type (Etype (Comp)))
then then
Error_Msg_NE Error_Msg_NE
("packed array component& will be initialized to zero?", ("\packed array component& " &
"will be initialized to zero?",
Nam, Comp); Nam, Comp);
exit; exit;
else else
...@@ -5102,7 +5098,7 @@ package body Freeze is ...@@ -5102,7 +5098,7 @@ package body Freeze is
end if; end if;
Error_Msg_N Error_Msg_N
("use pragma Import for & to " & ("\use pragma Import for & to " &
"suppress initialization ('R'M B.1(24))?", "suppress initialization ('R'M B.1(24))?",
Nam); Nam);
end if; end if;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 1999-2005, Free Software Foundation, Inc. -- -- Copyright (C) 1999-2006, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -683,6 +683,9 @@ package body GNAT.Command_Line is ...@@ -683,6 +683,9 @@ package body GNAT.Command_Line is
Last : Integer; Last : Integer;
Delimiter_Found : Boolean; Delimiter_Found : Boolean;
Discard : Boolean;
pragma Warnings (Off, Discard);
begin begin
Current_Argument := 0; Current_Argument := 0;
Current_Index := 0; Current_Index := 0;
...@@ -732,7 +735,7 @@ package body GNAT.Command_Line is ...@@ -732,7 +735,7 @@ package body GNAT.Command_Line is
end loop; end loop;
end loop; end loop;
Delimiter_Found := Goto_Next_Argument_In_Section; Discard := Goto_Next_Argument_In_Section;
end Initialize_Option_Scan; end Initialize_Option_Scan;
--------------- ---------------
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 2000-2005, AdaCore -- -- Copyright (C) 2000-2006, AdaCore --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -1110,8 +1110,8 @@ package body GNAT.Expect is ...@@ -1110,8 +1110,8 @@ package body GNAT.Expect is
Result : Expect_Match; Result : Expect_Match;
Descriptors : Array_Of_Pd := (1 => Descriptor'Unrestricted_Access); Descriptors : Array_Of_Pd := (1 => Descriptor'Unrestricted_Access);
Dummy : Natural; Discard : Natural;
pragma Unreferenced (Dummy); pragma Warnings (Off, Discard);
begin begin
if Empty_Buffer then if Empty_Buffer then
...@@ -1135,7 +1135,7 @@ package body GNAT.Expect is ...@@ -1135,7 +1135,7 @@ package body GNAT.Expect is
Call_Filters (Descriptor, Full_Str (Full_Str'First .. Last), Input); Call_Filters (Descriptor, Full_Str (Full_Str'First .. Last), Input);
Dummy := Discard :=
Write (Descriptor.Input_Fd, Write (Descriptor.Input_Fd,
Full_Str'Address, Full_Str'Address,
Last - Full_Str'First + 1); Last - Full_Str'First + 1);
...@@ -1275,7 +1275,6 @@ package body GNAT.Expect is ...@@ -1275,7 +1275,6 @@ package body GNAT.Expect is
Pipe3 : in out Pipe_Type) Pipe3 : in out Pipe_Type)
is is
pragma Warnings (Off, Pid); pragma Warnings (Off, Pid);
begin begin
Close (Pipe1.Input); Close (Pipe1.Input);
Close (Pipe2.Output); Close (Pipe2.Output);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- S p e c -- -- S p e c --
-- -- -- --
-- Copyright (C) 1999-2005, Free Software Foundation, Inc. -- -- Copyright (C) 1999-2006, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -98,6 +98,11 @@ package Sem_Warn is ...@@ -98,6 +98,11 @@ package Sem_Warn is
-- Output Routines -- -- Output Routines --
--------------------- ---------------------
procedure Output_Obsolescent_Entity_Warnings (N : Node_Id; E : Entity_Id);
-- N is a reference to obsolescent entity E, for which appropriate warning
-- messages are to be generated (caller has already checked that warnings
-- are active and appropriate for this entity).
procedure Output_Unreferenced_Messages; procedure Output_Unreferenced_Messages;
-- Warnings about unreferenced entities are collected till the end of -- Warnings about unreferenced entities are collected till the end of
-- the compilation process (see Check_Unset_Reference for further -- the compilation process (see Check_Unset_Reference for further
...@@ -107,6 +112,9 @@ package Sem_Warn is ...@@ -107,6 +112,9 @@ package Sem_Warn is
-- Other Warning Routines -- -- Other Warning Routines --
---------------------------- ----------------------------
procedure Check_Code_Statement (N : Node_Id);
-- Peform warning checks on a code statement node
procedure Warn_On_Known_Condition (C : Node_Id); procedure Warn_On_Known_Condition (C : Node_Id);
-- C is a node for a boolean expression resluting from a relational -- C is a node for a boolean expression resluting from a relational
-- or membership operation. If the expression has a compile time known -- or membership operation. If the expression has a compile time known
...@@ -132,4 +140,29 @@ package Sem_Warn is ...@@ -132,4 +140,29 @@ package Sem_Warn is
-- If all these conditions are met, the warning is issued noting that -- If all these conditions are met, the warning is issued noting that
-- the result of the test is always false or always true as appropriate. -- the result of the test is always false or always true as appropriate.
procedure Warn_On_Suspicious_Index (Name : Entity_Id; X : Node_Id);
-- This is called after resolving an indexed component or a slice. Name
-- is the entity for the name of the indexed array, and X is the subscript
-- for the indexed component case, or one of the bounds in the slice case.
-- If Name is an unconstrained parameter of a standard string type, and
-- the index is of the form of a literal or Name'Length [- literal], then
-- a warning is generated that the subscripting operation is possibly
-- incorrectly assuming a lower bound of 1.
procedure Warn_On_Useless_Assignment
(Ent : Entity_Id;
Loc : Source_Ptr := No_Location);
-- Called to check if we have a case of a useless assignment to the given
-- entity Ent, as indicated by a non-empty Last_Assignment field. This call
-- should only be made if Warn_On_Modified_Unread is True, and if Ent is in
-- the extended main source unit. Loc is No_Location for the end of block
-- call (warning msg says value unreferenced), or the it is the location of
-- an overwriting assignment (warning msg points to this assignment).
procedure Warn_On_Useless_Assignments (E : Entity_Id);
pragma Inline (Warn_On_Useless_Assignments);
-- Called at the end of a block or subprogram. Scans the entities of the
-- block or subprogram to see if there are any variables for which useless
-- assignments were made (assignments whose values were never read).
end Sem_Warn; end Sem_Warn;
...@@ -141,7 +141,9 @@ package body Xref_Lib is ...@@ -141,7 +141,9 @@ package body Xref_Lib is
Col_Start : Natural; Col_Start : Natural;
Line_Num : Natural := 0; Line_Num : Natural := 0;
Col_Num : Natural := 0; Col_Num : Natural := 0;
File_Ref : File_Reference := Empty_File; File_Ref : File_Reference := Empty_File;
pragma Warnings (Off, File_Ref);
begin begin
-- Find the end of the first item in Entity (pattern or file?) -- Find the end of the first item in Entity (pattern or file?)
...@@ -275,7 +277,9 @@ package body Xref_Lib is ...@@ -275,7 +277,9 @@ package body Xref_Lib is
Add_To_Xref_File Add_To_Xref_File
(Entity (File_Start .. Line_Start - 1), Visited => True); (Entity (File_Start .. Line_Start - 1), Visited => True);
Pattern.File_Ref := File_Ref; Pattern.File_Ref := File_Ref;
Add_Line (Pattern.File_Ref, Line_Num, Col_Num); Add_Line (Pattern.File_Ref, Line_Num, Col_Num);
File_Ref := File_Ref :=
Add_To_Xref_File Add_To_Xref_File
(ALI_File_Name (Entity (File_Start .. Line_Start - 1)), (ALI_File_Name (Entity (File_Start .. Line_Start - 1)),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment