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]
Other format: [Raw text]

[Ada] Handling of elaboration warnings


This patch modifies the elaboration warnings produced by the ABE mechanism to
depend on the status of flag Elab_Warnings. The flag is enabled by compilation
switch -gnatwl. This change allows for selective suppression of warnings, as
well as total suppression.

In order to preserve the behaviour of the ABE mmechanism with respect ot the
legacy ABE mechanism, elaboration warnings are now on by default.

-------------
-- Sources --
-------------

--  selective_2.ads

package Selective_2 is
   Var : Integer;

   generic
   procedure Gen;

   procedure Proc;

   task type Tsk is
      entry E;
   end Tsk;

   package Direct is
      procedure Force_Body;
   end Direct;
end Selective_2;

--  selective_2.adb

package body Selective_2 is
   function Elaborator return Boolean is
      pragma Warnings (Off);
      procedure Inst is new Gen;                                     --  OK
      T : Tsk;                                                       --  OK
      pragma Warnings (On);
   begin
      Proc;                                                          --  Warn
      return True;
   end Elaborator;

   package body Direct is
      procedure Force_Body is begin null; end Force_Body;
      pragma Warnings (Off);
      procedure Inst is new Gen;                                     --  OK
      T : Tsk;                                                       --  OK
      pragma Warnings (On);
   begin
      Proc;                                                          --  Warn
   end Direct;

   Indirect : constant Boolean := Elaborator;

   procedure Gen is begin null; end Gen;

   procedure Proc is begin null; end Proc;

   task body Tsk is
   begin
      accept E;
   end Tsk;

   pragma Warnings (Off);
begin
   Var := 1;                                                         --  OK
end Selective_2;

----------------------------
-- Compilation and output --
----------------------------

$ gcc -c selective_2.adb
selective_2.adb:8:07: warning: cannot call "Proc" before body seen
selective_2.adb:8:07: warning: Program_Error may be raised at run time
selective_2.adb:8:07: warning:   body of unit "Selective_2" elaborated
selective_2.adb:8:07: warning:   function "Elaborator" called at line 22
selective_2.adb:8:07: warning:   procedure "Proc" called at line 8
selective_2.adb:19:07: warning: cannot call "Proc" before body seen
selective_2.adb:19:07: warning: Program_Error will be raised at run time

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-11-16  Hristian Kirtchev  <kirtchev@adacore.com>

	* opt.ads: Elaboration warnings are now on by default. Add a comment
	explaining why this is needed.
	* sem_ch9.adb (Analyze_Requeue): Preserve the status of elaboration
	warnings.
	* sem_ch12.adb (Analyze_Package_Instantiation): Preserve the status of
	elaboration warnings.
	(Analyze_Subprogram_Instantiation): Preserve the status of elaboration
	warnings.
	* sem_elab.adb: Update the structure of Call_Attributes and
	Instantiation_Attributes.
	(Build_Call_Marker): Propagate the status of elaboration warnings from
	the call to the marker.
	(Extract_Call_Attributes): Extract the status of elaboration warnings.
	(Extract_Instantiation_Attributes): Extract the status of elaboration
	warnings.
	(Process_Conditional_ABE_Activation_Impl): Elaboration diagnostics are
	now dependent on the status of elaboration warnings.
	(Process_Conditional_ABE_Call_Ada): Elaboration diagnostics are now
	dependent on the status of elaboration warnings.
	(Process_Conditional_ABE_Instantiation_Ada): Elaboration diagnostics
	are now dependent on the status of elaboration warnings.
	(Process_Guaranteed_ABE_Activation_Impl): Remove pragma Unreferenced
	for formal Call_Attrs. Elaboration diagnostics are now dependent on the
	status of elaboration warnings.
	(Process_Guaranteed_ABE_Call): Elaboration diagnostics are now
	dependent on the status of elaboration warnings.
	(Process_Guaranteed_ABE_Instantiation): Elaboration diagnostics are now
	dependent on the status of elaboration warnings.
	* sem_prag.adb (Analyze_Pragma): Remove the unjustified warning
	concerning pragma Elaborate.
	* sem_res.adb (Resolve_Call): Preserve the status of elaboration
	warnings.
	(Resolve_Entry_Call): Propagate flag Is_Elaboration_Warnings_OK_Node
	from the procedure call to the entry call.
	* sem_util.adb (Mark_Elaboration_Attributes): Add formal parameter
	Warnings.
	(Mark_Elaboration_Attributes_Node): Preserve the status of elaboration
	warnings
	* sem_util.ads (Mark_Elaboration_Attributes): Add formal parameter
	Warnings. Update the comment on usage.
	* sinfo.adb (Is_Dispatching_Call): Update to use Flag6.
	(Is_Elaboration_Warnings_OK_Node): New routine.
	(Set_Is_Dispatching_Call): Update to use Flag6.
	(Set_Is_Elaboration_Warnings_OK_Node): New routine.
	* sinfo.ads: Attribute Is_Dispatching_Call now uses Flag6. Add new
	attribute Is_Elaboration_Warnings_OK_Node along with occurrences
	in nodes.
	(Is_Elaboration_Warnings_OK_Node): New routine along with pragma
	Inline.
	(Set_Is_Elaboration_Warnings_OK_Node): New routine along with pragma
	Inline.
	* doc/gnat_ugn/elaboration_order_handling_in_gnat.rst: Update various
	sections to indicate how to suppress elaboration warnings.  Document
	switches -gnatwl and -gnatwL.
	* gnat_ugn.texi: Regenerate.

Attachment: difs
Description: Text document


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