]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Don't generate function that violates No_Dynamic_Sized_Objects restriction
authorSteve Baird <baird@adacore.com>
Thu, 30 Oct 2025 21:40:06 +0000 (14:40 -0700)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 18 Nov 2025 15:05:09 +0000 (16:05 +0100)
In some cases, the compiler implicitly generates a hash function for an
enumeration type. If a No_Dynamic_Sized_Objects restriction is in effect then
that hash function violates the restriction, resulting in a compilation
failure. Therefore, do not generate the hash function in that case.

gcc/ada/ChangeLog:

* exp_imgv.adb (Build_Enumeration_Image_Tables): If a
No_Dynamic_Sized_Objects restriction is in effect, then choose a large
value for Threshold so that no Lit_Hash function is generated.

gcc/ada/exp_imgv.adb

index 3fef6fabe64e9606de799cef9ccd74b93f71b828..ea7b18582179cf6df9ae4874afb0d477c4ee49b5 100644 (file)
@@ -112,13 +112,18 @@ package body Exp_Imgv is
       --  exactly spent on all possible paths from this point.
 
       Threshold : constant Nat :=
-        (if Is_Library_Level_Entity (E)
+        (if Restriction_Active (No_Dynamic_Sized_Objects)
+         then Nat'Last
+         elsif Is_Library_Level_Entity (E)
            or else not Always_Compatible_Rep_On_Target
          then 3
          else Nat'Last);
       --  Threshold above which we want to generate the hash function in the
       --  default case. We avoid doing it if this would cause a trampoline to
       --  be generated because the type is local and descriptors are not used.
+      --  We also avoid doing it if a No_Dynamic_Sized_Objects restriction is
+      --  in effect because the hash function will violate the restriction
+      --  by declaring an array subtype with dynamic bounds.
 
       Threshold_For_Size : constant Nat := Nat'Max (Threshold, 9);
       --  But the function and its tables take a bit of space so the threshold