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] fix in handling of null procs


Tested on i686-linux, committed on trunk.

In Ada 2005, null procedures can be used as primitive operations of
interfaces and tagged types, but not as protected operations.
The following must be rejected with the message:
--
prot_err.ads:3:06: protected operation cannot be a null procedure
--
package Prot_Err is
   protected type Prot is
      procedure Log (X : integer) is null;
   end Prot;
end;

The cross-reference information for a child subprogram contains a
reference to the parent unit. This information is now also available
for generic child subprograms.
--
test case:
--
gcc -c base-gproc.adb
grep k9 base-gproc.ali
--
Output:
--
3u16*gproc 1|1k9 2|3>23 3|1b16 4t4
--
package base is
   type T is new integer;
end base;
--
generic
   type T is private;
procedure base.gproc (x : integer);
--
procedure base.gproc (x : integer) is
begin
   if x = 0 then null; end if;
end;

Add semantic analysis of Ada 2005 limited returns. (AI-318)

Also add semantic analysis for AI-423.

Ditto for AI-231:
This patch introduces additional checks for legal usage of null
exclusions. The following test should produce the errors listed below:
--
package Test is
   type T is private;
   type Acc_T is access T;
   type Rec is null record;
   type Acc_Rec_Without_Null is not null access Rec;
   type Acc_Rec_With_Null is access Rec;
   subtype Acc_Rec_Sub_Without_Null is Acc_Rec_Without_Null;
   subtype Acc_Rec_Sub_With_Null is Acc_Rec_With_Null;
   procedure P_1 (Obj : not null T);                             --  ERROR
   procedure P_2 (Obj : not null access T);                      --  OK
   procedure P_3 (Obj : not null Acc_T);                         --  OK
   procedure P_4 (Obj : not null Rec);                           --  ERROR
   procedure P_5 (Obj : not null Acc_Rec_Without_Null);          --  ERROR
   procedure P_6 (Obj : not null Acc_Rec_With_Null);             --  OK
   procedure P_7 (Obj : not null Acc_Rec_Sub_Without_Null);      --  ERROR
   procedure P_8 (Obj : not null Acc_Rec_Sub_With_Null);         --  OK
private
   type Hidden is null record;
   type T is access Hidden;
end Test;
--
Compilation:
   gcc -c -gnat05 -gnatc test.ads
--
Output:
t.ads:9:19: null exclusion must be applied to an access type
test.ads:12:19: null exclusion must be applied to an access type
test.ads:13:19: null exclusion cannot be applied to a null excluding type (RM 3.10 (14))
test.ads:15:19: null exclusion cannot be applied to a null excluding type (RM 3.10 (14))

Finally, abstract interface types can have only abstract or null subprograms.
The static check associated with this rule was not complete because
access to interface formals were allowed. After this patch the
following test generates the correct error message.
--
package Intface is
   type Interface_Type is interface;
--
   procedure Proc  (I : access Interface_Type);
end Intface;
--
Command: gcc -c -gnat05 intface.ads
intface.ads:4:04: (Ada 2005) interface subprogram "Proc" must be abstract or null

2006-10-31  Ed Schonberg  <schonberg@adacore.com>
	    Hristian Kirtchev  <kirtchev@adacore.com>
	    Bob Duff  <duff@adacore.com>
        
	* sem_ch6.ads, sem_ch6.adb (Analyze_Subprogram_Declaration): A null
	procedure cannot be a protected operation (it is a basic_declaration,
	not a subprogram_declaration).
	(Check_Overriding_Indicator): Rename formal Does_Override to Overridden_
	Subp. Add logic for entry processing.
	(Check_Synchronized_Overriding): New procedure in New_Overloaded_Entity.
	Determine whether an entry or subprogram of a protected or task type
	override an inherited primitive of an implemented interface.
	(New_Overloaded_Entity): Add calls to Check_Synchronized_Overriding.
	Update the actual used in calls to Check_Overriding_Indicator.
	(Analyze_Generic_Subprogram_Body): If the subprogram is a child unit,
	generate the proper reference to the parent unit, for cross-reference.
	(Analyze_Subprogram_Declaration): Protect Is_Controlling_Formal with
	Is_Formal.
	Add -gnatd.l --Use Ada 95 semantics for limited function returns,
	(Add_Extra_Formal): Revise procedure to allow passing in associated
	entity, scope, and name suffix, and handle setting of the new
	Extra_Formals field.
	(Create_Extra_Formals): Change existing calls to Add_Extra_Formal to
	pass new parameters. Add support for adding the new extra access formal
	for functions whose calls are treated as build-in-place.
	(Analyze_A_Return_Statement): Correct casing in error message.
	Move Pop_Scope to after Analyze_Function_Return, because an extended
	return statement really is a full-fledged scope. Otherwise, visibility
	doesn't work right. Correct use of "\" for continuation messages.
	(Analyze_Function_Return): Call Analyze on the Obj_Decl, rather than
	evilly trying to call Analyze_Object_Declaration directly. Otherwise,
	the node doesn't get properly marked as analyzed.
	(Analyze_Subprogram_Body): If subprogram is a function that returns
	an anonymous access type that denotes a task, build a Master Entity
	for it.
	(Analyze_Return_Type): Add call to Null_Exclusion_Static_Checks. Verify
	proper usage of null exclusion in a result definition.
	(Process_Formals): Code cleanup and new error message.
	(Process_Formals): Detect incorrect application of null exclusion to
	non-access types.
	(Conforming_Types): Handle conformance between [sub]types and itypes
	 generated for entities that have null exclusions applied to them.
	(Maybe_Primitive_Operation): Add an additional type retrieval when the
	 base type is an access subtype. This case arrises with null exclusions.
	(New_Overloaded_Entity): Do not remove the overriden entity from the
	homonym chain if it corresponds with an abstract interface primitive.
	(Process_Formals): Replace membership test agains Incomplete_Kind with a
	call to the synthesized predicate Is_Incomplete_Type.
	(Analyze_Subprogram_Body): Check wrong placement of abstract interface
	primitives.
	(Analyze_Subprogram_Declaration): Check that abstract interface
	primitives are abstract or null.
	(Analyze_Subprogram_Specification): Remove previous check for abstract
	interfaces because it was not complete.
	(Has_Interface_Formals): Removed.

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]