aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/einfo-utils.adb
diff options
context:
space:
mode:
authorBob Duff <duff@adacore.com>2021-06-15 09:12:36 -0400
committerPierre-Marie de Rodat <derodat@adacore.com>2021-07-12 12:50:57 +0000
commit0c8ff35eb982a49882ed71b1b85e8436675adf88 (patch)
tree71b6ac19dfcaef9f49b23a1221eac331546922cb /gcc/ada/einfo-utils.adb
parent5cb3843bca9a28c28dbc1fafd88c144a43e141df (diff)
downloadgcc-0c8ff35eb982a49882ed71b1b85e8436675adf88.zip
gcc-0c8ff35eb982a49882ed71b1b85e8436675adf88.tar.gz
gcc-0c8ff35eb982a49882ed71b1b85e8436675adf88.tar.bz2
[Ada] Clean up Uint fields
gcc/ada/ * uintp.ads, types.h: New subtypes of Uint: Valid_Uint, Unat, Upos, Nonzero_Uint with predicates. These correspond to new field types in Gen_IL. * gen_il-types.ads (Valid_Uint, Unat, Upos, Nonzero_Uint): New field types. * einfo-utils.ads, einfo-utils.adb, fe.h (Known_Alignment, Init_Alignment): Use the initial zero value to represent "unknown". This will ensure that if Alignment is called before Set_Alignment, the compiler will blow up (if assertions are enabled). * atree.ads, atree.adb, atree.h, gen_il-gen.adb (Get_Valid_32_Bit_Field): New generic low-level getter for subtypes of Uint. (Copy_Alignment): New procedure to copy Alignment field even when Unknown. (Init_Object_Size_Align, Init_Size_Align): Do not bypass the Init_ procedures. * exp_pakd.adb, freeze.adb, layout.adb, repinfo.adb, sem_util.adb: Protect calls to Alignment with Known_Alignment. Use Copy_Alignment when it might be unknown. * gen_il-gen-gen_entities.adb (Alignment, String_Literal_Length): Use type Unat instead of Uint, to ensure that the field is always Set_ before we get it, and that it is set to a nonnegative value. (Enumeration_Pos): Unat. (Enumeration_Rep): Valid_Uint. Can be negative, but must be valid before fetching. (Discriminant_Number): Upos. (Renaming_Map): Remove. * gen_il-gen-gen_nodes.adb (Char_Literal_Value, Reason): Unat. (Intval, Corresponding_Integer_Value): Valid_Uint. * gen_il-internals.ads: New functions for dealing with special defaults and new subtypes of Uint. * scans.ads: Correct comments. * scn.adb (Post_Scan): Do not set Intval to No_Uint; that is no longer allowed. * sem_ch13.adb (Analyze_Enumeration_Representation_Clause): Do not set Enumeration_Rep to No_Uint; that is no longer allowed. (Offset_Value): Protect calls to Alignment with Known_Alignment. * sem_prag.adb (Set_Atomic_VFA): Do not use Uint_0 to mean "unknown"; call Init_Alignment instead. * sinfo.ads: Minor comment fix. * treepr.adb: Deal with printing of new field types. * einfo.ads, gen_il-fields.ads (Renaming_Map): Remove. * gcc-interface/decl.c (gnat_to_gnu_entity): Use Known_Alignment before calling Alignment. This preserve some probably buggy behavior: if the alignment is not set, it previously defaulted to Uint_0; we now make that explicit. Use Copy_Alignment, because "Set_Alignment (Y, Alignment (X));" no longer works when the Alignment of X has not yet been set. * gcc-interface/trans.c (process_freeze_entity): Use Copy_Alignment.
Diffstat (limited to 'gcc/ada/einfo-utils.adb')
-rw-r--r--gcc/ada/einfo-utils.adb25
1 files changed, 17 insertions, 8 deletions
diff --git a/gcc/ada/einfo-utils.adb b/gcc/ada/einfo-utils.adb
index 21d7bfb..4690c8f 100644
--- a/gcc/ada/einfo-utils.adb
+++ b/gcc/ada/einfo-utils.adb
@@ -364,7 +364,7 @@ package body Einfo.Utils is
procedure Init_Alignment (Id : E) is
begin
- Set_Alignment (Id, Uint_0);
+ Reinit_Field_To_Zero (Id, F_Alignment);
end Init_Alignment;
procedure Init_Alignment (Id : E; V : Int) is
@@ -452,6 +452,15 @@ package body Einfo.Utils is
Set_RM_Size (Id, UI_From_Int (V));
end Init_RM_Size;
+ procedure Copy_Alignment (To, From : E) is
+ begin
+ if Known_Alignment (From) then
+ Set_Alignment (To, Alignment (From));
+ else
+ Init_Alignment (To);
+ end if;
+ end Copy_Alignment;
+
-----------------------------
-- Init_Component_Location --
-----------------------------
@@ -471,8 +480,8 @@ package body Einfo.Utils is
procedure Init_Object_Size_Align (Id : E) is
begin
- Set_Esize (Id, Uint_0);
- Set_Alignment (Id, Uint_0);
+ Init_Esize (Id);
+ Init_Alignment (Id);
end Init_Object_Size_Align;
---------------
@@ -499,9 +508,9 @@ package body Einfo.Utils is
procedure Init_Size_Align (Id : E) is
begin
pragma Assert (Ekind (Id) in Type_Kind | E_Void);
- Set_Esize (Id, Uint_0);
- Set_RM_Size (Id, Uint_0);
- Set_Alignment (Id, Uint_0);
+ Init_Esize (Id);
+ Init_RM_Size (Id);
+ Init_Alignment (Id);
end Init_Size_Align;
----------------------------------------------
@@ -509,9 +518,9 @@ package body Einfo.Utils is
----------------------------------------------
function Known_Alignment (E : Entity_Id) return B is
+ Result : constant B := not Field_Is_Initial_Zero (E, F_Alignment);
begin
- return Alignment (E) /= Uint_0
- and then Alignment (E) /= No_Uint;
+ return Result;
end Known_Alignment;
function Known_Component_Bit_Offset (E : Entity_Id) return B is