[Ada] Ada2020: Special handling of types derived from runtime

gcc/ada/

	* einfo.ads (Is_Ada_2022_Only): Adding documentation.
	* gen_il-fields.ads (Is_Ada_2022_Only): New flag.
	* gen_il-gen-gen_entities.adb (Is_Ada_2022_Only): New flag.
	* itypes.adb (Create_Null_Excluding_Itype): Inherit
	Is_Ada_2022_Only.
	* sem_ch3.adb (Check_Abstract_Overriding): Skip reporting error
	on Ada 2022 only subprograms that require overriding if we are
	not in Ada 2022 mode.
	(Derive_Subprogram): Inherit Is_Ada_2022_Only.
	* sem_ch6.adb (Check_Overriding_Indicator): Inherit
	Is_Ada_2022_Only.
	(New_Overloaded_Entity): Inherit Is_Ada_2022_Only.
	* sem_ch7.adb (Declare_Inherited_Private_Subprograms): Inherit
	Is_Ada_2022_Only.
	(Preserve_Full_Attributes): Inherit Is_Ada_2022_Only.
	* sem_disp.adb (Find_Hidden_Overridden_Primitive): Inherit
	Is_Ada_2022_Only.
	(Override_Dispatching_Operation): Inherit Is_Ada_2022_Only.
	* sem_prag.adb (Analyze_Pragma): Allow form with argument for
	Ada 2022.
	* sem_type.adb: (Disambiguate): Deal with Is_Ada_2022_Only
	* lib-xref.adb (Generate_Reference): Error on static and
	dispatching calls to Ada 2022 subprograms that require
	overriding if we are not in Ada 2022 mode; warn on other
	references to Ada 2022 entities when not in Ada 2022 mode.
	* sem_ch13.adb (Inherit_Aspects_At_Freeze_Point): Inherit
	Ada_2020_Only.
	* libgnat/a-cdlili.ads (Empty): Adding pragma Ada_2022.
	* libgnat/a-cidlli.ads (Empty): Adding pragma Ada_2022.
	* libgnat/a-ciorma.ads (Empty): Adding pragma Ada_2022.
	* libgnat/a-cobove.ads (Empty): Adding pragma Ada_2022.
	* libgnat/a-coorma.ads (Empty): Adding pragma Ada_2022.
	(New_Vector): Adding pragma Ada_2022.
	(Insert_Vector): Adding pragma Ada_2022.
	(Prepend_Vector): Adding pragma Ada_2022.
	(Append_Vector): Adding pragma Ada_2022.
This commit is contained in:
Javier Miranda 2021-03-13 14:47:59 -05:00 committed by Pierre-Marie de Rodat
parent 64b5da8f97
commit 07537fe632
17 changed files with 168 additions and 18 deletions

View File

@ -2317,6 +2317,13 @@ package Einfo is
-- the entity is part of a unit compiled with the normal no-argument form
-- of pragma Ada_12 or Ada_2012.
-- Is_Ada_2022_Only
-- Defined in all entities, true if a valid pragma Ada_2022 applies to
-- the entity which specifically names the entity, indicating that the
-- entity is Ada 2022 only. Note that this flag is not set if the entity
-- is part of a unit compiled with the normal no-argument form of pragma
-- Ada_2022.
-- Is_Aliased
-- Defined in all entities. Set for objects and types whose declarations
-- carry the keyword aliased, and on record components that have the
@ -4871,6 +4878,7 @@ package Einfo is
-- In_Private_Part
-- Is_Ada_2005_Only
-- Is_Ada_2012_Only
-- Is_Ada_2022_Only
-- Is_Bit_Packed_Array (base type only)
-- Is_Aliased
-- Is_Character_Type

View File

@ -669,6 +669,7 @@ package Gen_IL.Fields is
Is_Actual_Subtype,
Is_Ada_2005_Only,
Is_Ada_2012_Only,
Is_Ada_2022_Only,
Is_Aliased,
Is_Asynchronous,
Is_Atomic,

View File

@ -119,6 +119,7 @@ begin -- Gen_IL.Gen.Gen_Entities
Sm (In_Use, Flag),
Sm (Is_Ada_2005_Only, Flag),
Sm (Is_Ada_2012_Only, Flag),
Sm (Is_Ada_2022_Only, Flag),
Sm (Is_Aliased, Flag),
Sm (Is_Atomic, Flag),
Sm (Is_Bit_Packed_Array, Flag, Impl_Base_Type_Only),

View File

@ -111,6 +111,7 @@ package body Itypes is
Set_Is_Atomic (I_Typ, Is_Atomic (T));
Set_Is_Ada_2005_Only (I_Typ, Is_Ada_2005_Only (T));
Set_Is_Ada_2012_Only (I_Typ, Is_Ada_2012_Only (T));
Set_Is_Ada_2022_Only (I_Typ, Is_Ada_2022_Only (T));
Set_Can_Never_Be_Null (I_Typ);
return I_Typ;

View File

@ -703,6 +703,37 @@ package body Lib.Xref is
Error_Msg_NE ("& is only defined in Ada 2012?y?", N, E);
end if;
-- Warn if reference to Ada 2022 entity not in Ada 2022 mode. We only
-- detect real explicit references (modifications and references).
if Comes_From_Source (N)
and then Is_Ada_2022_Only (E)
and then not Is_Subprogram (E)
and then Ada_Version < Ada_2022
and then Warn_On_Ada_2022_Compatibility
and then (Typ = 'm' or else Typ = 'r')
then
Error_Msg_NE ("& is only defined in Ada 2022?y?", N, E);
-- Error on static and dispatching calls to Ada 2022 subprograms that
-- require overriding if we are not in Ada 2022 mode (since overriding
-- was skipped); warn if the subprogram does not require overriding.
elsif Comes_From_Source (N)
and then Is_Ada_2022_Only (E)
and then Ada_Version < Ada_2022
and then Is_Subprogram (E)
and then (Typ = 'r' or else Typ = 's' or else Typ = 'R')
then
if Requires_Overriding (E) then
Error_Msg_NE
("& is only defined in Ada 2022 and requires overriding", N, E);
elsif Warn_On_Ada_2022_Compatibility then
Error_Msg_NE ("& is only defined in Ada 2022?y?", N, E);
end if;
end if;
-- Do not generate references if we are within a postcondition sub-
-- program, because the reference does not comes from source, and the
-- preanalysis of the aspect has already created an entry for the ALI

View File

@ -66,7 +66,9 @@ is
pragma Preelaborable_Initialization (Cursor);
Empty_List : constant List;
function Empty return List;
pragma Ada_2022 (Empty);
No_Element : constant Cursor;

View File

@ -65,7 +65,9 @@ is
pragma Preelaborable_Initialization (Cursor);
Empty_List : constant List;
function Empty return List;
pragma Ada_2022 (Empty);
No_Element : constant Cursor;

View File

@ -70,6 +70,7 @@ is
Empty_Map : constant Map;
function Empty return Map;
pragma Ada_2022 (Empty);
No_Element : constant Cursor;
function Has_Element (Position : Cursor) return Boolean;

View File

@ -80,12 +80,14 @@ package Ada.Containers.Bounded_Vectors is
Ada.Iterator_Interfaces (Cursor, Has_Element);
function Empty (Capacity : Count_Type := 10) return Vector;
pragma Ada_2022 (Empty);
overriding function "=" (Left, Right : Vector) return Boolean;
function New_Vector (First, Last : Index_Type) return Vector
with Pre => First = Index_Type'First;
-- Ada 2022 aggregate operation.
pragma Ada_2022 (New_Vector);
function To_Vector (Length : Count_Type) return Vector;
@ -194,6 +196,7 @@ package Ada.Containers.Bounded_Vectors is
(Container : in out Vector;
Before : Extended_Index;
New_Item : Vector);
pragma Ada_2022 (Insert_Vector);
procedure Insert
(Container : in out Vector;
@ -205,6 +208,7 @@ package Ada.Containers.Bounded_Vectors is
(Container : in out Vector;
Before : Cursor;
New_Item : Vector);
pragma Ada_2022 (Insert_Vector);
procedure Insert
(Container : in out Vector;
@ -217,6 +221,7 @@ package Ada.Containers.Bounded_Vectors is
Before : Cursor;
New_Item : Vector;
Position : out Cursor);
pragma Ada_2022 (Insert_Vector);
procedure Insert
(Container : in out Vector;
@ -258,6 +263,7 @@ package Ada.Containers.Bounded_Vectors is
procedure Prepend_Vector
(Container : in out Vector;
New_Item : Vector);
pragma Ada_2022 (Prepend_Vector);
procedure Prepend
(Container : in out Vector;
@ -272,6 +278,7 @@ package Ada.Containers.Bounded_Vectors is
procedure Append_Vector
(Container : in out Vector;
New_Item : Vector);
pragma Ada_2022 (Append_Vector);
procedure Append
(Container : in out Vector;

View File

@ -67,7 +67,9 @@ is
pragma Preelaborable_Initialization (Cursor);
Empty_Map : constant Map;
function Empty return Map;
pragma Ada_2022 (Empty);
No_Element : constant Cursor;

View File

@ -13399,6 +13399,16 @@ package body Sem_Ch13 is
Set_Is_Ada_2012_Only (Typ);
end if;
-- Ada_2022
if not Has_Rep_Item (Typ, Name_Ada_2022, False)
and then Has_Rep_Item (Typ, Name_Ada_2022)
and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
(Get_Rep_Item (Typ, Name_Ada_2022))
then
Set_Is_Ada_2022_Only (Typ);
end if;
-- Atomic/Shared
if not Has_Rep_Item (Typ, Name_Atomic, Name_Shared, False)

View File

@ -10967,6 +10967,15 @@ package body Sem_Ch3 is
then
null;
-- Skip reporting the error on Ada 2022 only subprograms
-- that require overriding if we are not in Ada 2022 mode.
elsif Ada_Version < Ada_2022
and then Requires_Overriding (Subp)
and then Is_Ada_2022_Only (Ultimate_Alias (Subp))
then
null;
else
Error_Msg_NE
("type must be declared abstract or & overridden",
@ -16061,6 +16070,8 @@ package body Sem_Ch3 is
then
Set_Has_Yield_Aspect (New_Subp, Has_Yield_Aspect (Alias (New_Subp)));
end if;
Set_Is_Ada_2022_Only (New_Subp, Is_Ada_2022_Only (Parent_Subp));
end Derive_Subprogram;
------------------------

View File

@ -7271,10 +7271,14 @@ package body Sem_Ch6 is
then
Set_Overridden_Operation (Subp, Alias (Overridden_Subp));
Inherit_Subprogram_Contract (Subp, Alias (Overridden_Subp));
Set_Is_Ada_2022_Only (Subp,
Is_Ada_2022_Only (Alias (Overridden_Subp)));
else
Set_Overridden_Operation (Subp, Overridden_Subp);
Inherit_Subprogram_Contract (Subp, Overridden_Subp);
Set_Is_Ada_2022_Only (Subp,
Is_Ada_2022_Only (Overridden_Subp));
end if;
end if;
end if;
@ -11888,10 +11892,13 @@ package body Sem_Ch6 is
if Present (Alias (S)) then
Set_Overridden_Operation (E, Alias (S));
Inherit_Subprogram_Contract (E, Alias (S));
Set_Is_Ada_2022_Only (E,
Is_Ada_2022_Only (Alias (S)));
else
Set_Overridden_Operation (E, S);
Inherit_Subprogram_Contract (E, S);
Set_Is_Ada_2022_Only (E, Is_Ada_2022_Only (S));
end if;
-- When a dispatching operation overrides an inherited
@ -12058,6 +12065,8 @@ package body Sem_Ch6 is
then
Set_Overridden_Operation (S, Alias (E));
Inherit_Subprogram_Contract (S, Alias (E));
Set_Is_Ada_2022_Only (S,
Is_Ada_2022_Only (Alias (E)));
-- Normal case of setting entity as overridden
@ -12071,6 +12080,7 @@ package body Sem_Ch6 is
elsif not Is_Init_Proc (S) then
Set_Overridden_Operation (S, E);
Inherit_Subprogram_Contract (S, E);
Set_Is_Ada_2022_Only (S, Is_Ada_2022_Only (E));
end if;
Check_Overriding_Indicator (S, E, Is_Primitive => True);
@ -12099,6 +12109,8 @@ package body Sem_Ch6 is
if Present (Alias (E)) then
Set_Overridden_Operation (S, Alias (E));
Inherit_Subprogram_Contract (S, Alias (E));
Set_Is_Ada_2022_Only (S,
Is_Ada_2022_Only (Alias (E)));
end if;
end if;

View File

@ -2061,6 +2061,8 @@ package body Sem_Ch7 is
Replace_Elmt (Op_Elmt, New_Op);
Remove_Elmt (Op_List, Op_Elmt_2);
Set_Overridden_Operation (New_Op, Parent_Subp);
Set_Is_Ada_2022_Only (New_Op,
Is_Ada_2022_Only (Parent_Subp));
-- We don't need to inherit its dispatching slot.
-- Set_All_DT_Position has previously ensured that
@ -2725,6 +2727,7 @@ package body Sem_Ch7 is
Set_Is_Atomic (Priv, Is_Atomic (Full));
Set_Is_Ada_2005_Only (Priv, Is_Ada_2005_Only (Full));
Set_Is_Ada_2012_Only (Priv, Is_Ada_2012_Only (Full));
Set_Is_Ada_2022_Only (Priv, Is_Ada_2022_Only (Full));
Set_Has_Pragma_Unmodified (Priv, Has_Pragma_Unmodified (Full));
Set_Has_Pragma_Unreferenced (Priv, Has_Pragma_Unreferenced (Full));
Set_Has_Pragma_Unreferenced_Objects

View File

@ -2199,6 +2199,8 @@ package body Sem_Disp is
while Present (Elmt) loop
if Node (Elmt) = Orig_Prim then
Set_Overridden_Operation (S, Prim);
Set_Is_Ada_2022_Only (S,
Is_Ada_2022_Only (Prim));
Set_Alias (Prim, Orig_Prim);
return Prim;
end if;
@ -2761,6 +2763,7 @@ package body Sem_Disp is
Set_Alias (Prev_Op, New_Op);
Set_DTC_Entity (Prev_Op, Empty);
Set_Has_Controlling_Result (New_Op, Has_Controlling_Result (Prev_Op));
Set_Is_Ada_2022_Only (New_Op, Is_Ada_2022_Only (Prev_Op));
end if;
end Override_Dispatching_Operation;

View File

@ -12542,22 +12542,61 @@ package body Sem_Prag is
--------------
-- pragma Ada_2022;
-- pragma Ada_2022 (LOCAL_NAME):
-- Note: this pragma also has some specific processing in Par.Prag
-- because we want to set the Ada 2022 version mode during parsing.
-- The one argument form is used for managing the transition from Ada
-- 2012 to Ada 2022 in the run-time library. If an entity is marked
-- as Ada_2022 only, then referencing the entity in any pre-Ada_2022
-- mode will generate a warning;for calls to Ada_2022 only primitives
-- that require overriding an error will be reported. In addition, in
-- any pre-Ada_2022 mode, a preference rule is established which does
-- not choose such an entity unless it is unambiguously specified.
-- This avoids extra subprograms marked this way from generating
-- ambiguities in otherwise legal pre-Ada 2022 programs. The one
-- argument form is intended for exclusive use in the GNAT run-time
-- library.
when Pragma_Ada_2022 =>
declare
E_Id : Node_Id;
begin
GNAT_Pragma;
Check_Arg_Count (0);
if Arg_Count = 1 then
Check_Arg_Is_Local_Name (Arg1);
E_Id := Get_Pragma_Arg (Arg1);
Check_Valid_Configuration_Pragma;
if Etype (E_Id) = Any_Type then
return;
end if;
-- Now set appropriate Ada mode
Set_Is_Ada_2022_Only (Entity (E_Id));
Record_Rep_Item (Entity (E_Id), N);
Ada_Version := Ada_2022;
Ada_Version_Explicit := Ada_2022;
Ada_Version_Pragma := N;
else
Check_Arg_Count (0);
-- For Ada_2022 we unconditionally enforce the documented
-- configuration pragma placement, since we do not want to
-- tolerate mixed modes in a unit involving Ada 2022. That
-- would cause real difficulties for those cases where there
-- are incompatibilities between Ada 2012 and Ada 2022. We
-- could allow mixing of Ada 2012 and Ada 2022 but it's not
-- worth it.
Check_Valid_Configuration_Pragma;
-- Now set appropriate Ada mode
Ada_Version := Ada_2022;
Ada_Version_Explicit := Ada_2022;
Ada_Version_Pragma := N;
end if;
end;
-------------------------------------
-- Aggregate_Individually_Assign --

View File

@ -1810,26 +1810,42 @@ package body Sem_Type is
It2 := It;
Nam2 := It.Nam;
-- Check whether one of the entities is an Ada 2005/2012 and we are
-- operating in an earlier mode, in which case we discard the Ada
-- 2005/2012 entity, so that we get proper Ada 95 overload resolution.
-- Check whether one of the entities is an Ada 2005/2012/2022 and we
-- are operating in an earlier mode, in which case we discard the Ada
-- 2005/2012/2022 entity, so that we get proper Ada 95 overload
-- resolution.
if Ada_Version < Ada_2005 then
if Is_Ada_2005_Only (Nam1) or else Is_Ada_2012_Only (Nam1) then
if Is_Ada_2005_Only (Nam1)
or else Is_Ada_2012_Only (Nam1)
or else Is_Ada_2022_Only (Nam1)
then
return It2;
elsif Is_Ada_2005_Only (Nam2) or else Is_Ada_2012_Only (Nam1) then
elsif Is_Ada_2005_Only (Nam2)
or else Is_Ada_2012_Only (Nam2)
or else Is_Ada_2022_Only (Nam2)
then
return It1;
end if;
end if;
-- Check whether one of the entities is an Ada 2012 entity and we are
-- operating in Ada 2005 mode, in which case we discard the Ada 2012
-- entity, so that we get proper Ada 2005 overload resolution.
-- Check whether one of the entities is an Ada 2012/2022 entity and we
-- are operating in Ada 2005 mode, in which case we discard the Ada 2012
-- Ada 2022 entity, so that we get proper Ada 2005 overload resolution.
if Ada_Version = Ada_2005 then
if Is_Ada_2012_Only (Nam1) then
elsif Ada_Version = Ada_2005 then
if Is_Ada_2012_Only (Nam1) or else Is_Ada_2022_Only (Nam1) then
return It2;
elsif Is_Ada_2012_Only (Nam2) then
elsif Is_Ada_2012_Only (Nam2) or else Is_Ada_2022_Only (Nam2) then
return It1;
end if;
-- Ditto for Ada 2012 vs Ada 2022.
elsif Ada_Version = Ada_2012 then
if Is_Ada_2022_Only (Nam1) then
return It2;
elsif Is_Ada_2022_Only (Nam2) then
return It1;
end if;
end if;