aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorSteve Baird <baird@adacore.com>2024-03-18 14:35:33 -0700
committerMarc Poulhiès <poulhies@adacore.com>2024-05-20 09:47:03 +0200
commitcaaf20e2678117861a7a4d1da712be91a94596b1 (patch)
tree0494f6647de1f4d340511fcc75c2aa0a480d9de3 /gcc/ada
parenteef3025547ce55cbf6a9018b495ef5c9a562047a (diff)
downloadgcc-caaf20e2678117861a7a4d1da712be91a94596b1.zip
gcc-caaf20e2678117861a7a4d1da712be91a94596b1.tar.gz
gcc-caaf20e2678117861a7a4d1da712be91a94596b1.tar.bz2
ada: Reject too-strict alignment specifications.
For a discrete (or fixed-point) type T, GNAT requires that T'Object_Size shall be a multiple of T'Alignment * 8 . GNAT also requires that T'Object_Size shall be no larger than Standard'Max_Integer_Size. For a sufficiently-large alignment specification, these requirements can conflict. The conflict is resolved by rejecting such alignment specifications (which were previously accepted in some cases). gcc/ada/ * freeze.adb (Adjust_Esize_For_Alignment): Assert that a valid Alignment specification cannot result in adjusting the given type's Esize to be larger than System_Max_Integer_Size. * sem_ch13.adb (Analyze_Attribute_Definition_Clause): In analyzing an Alignment specification, enforce the rule that a specified Alignment value for a discrete or fixed-point type shall not be larger than System_Max_Integer_Size / 8 . gcc/testsuite/ChangeLog: * gnat.dg/specs/alignment2.ads: Adjust. * gnat.dg/specs/alignment2_bis.ads: New test.
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/freeze.adb8
-rw-r--r--gcc/ada/sem_ch13.adb15
2 files changed, 21 insertions, 2 deletions
diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index a980c7e..26e9d01 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -303,8 +303,12 @@ package body Freeze is
if Known_Esize (Typ) and then Known_Alignment (Typ) then
Align := Alignment_In_Bits (Typ);
- if Align > Esize (Typ) and then Align <= System_Max_Integer_Size then
- Set_Esize (Typ, Align);
+ if Align > Esize (Typ) then
+ if Align > System_Max_Integer_Size then
+ pragma Assert (Serious_Errors_Detected > 0);
+ else
+ Set_Esize (Typ, Align);
+ end if;
end if;
end if;
end Adjust_Esize_For_Alignment;
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 13bf93c..59c8002 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -6573,6 +6573,21 @@ package body Sem_Ch13 is
("alignment for & set to Maximum_Aligment??", Nam);
Set_Alignment (U_Ent, Max_Align);
+ -- Because Object_Size must be multiple of Alignment (in bits),
+ -- System_Max_Integer_Size limit for discrete and fixed point
+ -- types implies a limit on alignment for such types.
+
+ elsif (Is_Discrete_Type (U_Ent)
+ or else Is_Fixed_Point_Type (U_Ent))
+ and then Align > System_Max_Integer_Size / System_Storage_Unit
+ then
+ Error_Msg_N
+ ("specified alignment too large for discrete or fixed " &
+ "point type", Expr);
+ Set_Alignment
+ (U_Ent, UI_From_Int (System_Max_Integer_Size /
+ System_Storage_Unit));
+
-- All other cases
else