]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Crash processing pragmas Compile_Time_Error and Compile_Time_Warning
authorJavier Miranda <miranda@adacore.com>
Tue, 19 Sep 2023 13:54:28 +0000 (13:54 +0000)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 10 Oct 2023 12:12:28 +0000 (14:12 +0200)
gcc/ada/

* sem_attr.adb (Analyze_Attribute): Protect the frontend against
replacing 'Size by its static value if 'Size is not known at
compile time and we are processing pragmas Compile_Time_Warning or
Compile_Time_Errors.

gcc/ada/sem_attr.adb

index d03761b1e30e3fd71b55072debc4bb3079e54709..3eba3a29362a50f2768c5b31a8c753f699b6b632 100644 (file)
@@ -6457,17 +6457,30 @@ package body Sem_Attr is
                        or else Size_Known_At_Compile_Time (Entity (P)))
          then
             declare
-               Siz : Uint;
+               Prefix_E : Entity_Id := Entity (P);
+               Siz      : Uint;
 
             begin
-               if Known_Static_RM_Size (Entity (P)) then
-                  Siz := RM_Size (Entity (P));
+               --  Handle private and incomplete types
+
+               if Present (Underlying_Type (Prefix_E)) then
+                  Prefix_E := Underlying_Type (Prefix_E);
+               end if;
+
+               if Known_Static_RM_Size (Prefix_E) then
+                  Siz := RM_Size (Prefix_E);
                else
-                  Siz := Esize (Entity (P));
+                  Siz := Esize (Prefix_E);
                end if;
 
-               Rewrite (N, Make_Integer_Literal (Sloc (N), Siz));
-               Analyze (N);
+               --  Protect the frontend against cases where the attribute
+               --  Size_Known_At_Compile_Time is set, but the Esize value
+               --  is not available (see Einfo.ads).
+
+               if Present (Siz) then
+                  Rewrite (N, Make_Integer_Literal (Sloc (N), Siz));
+                  Analyze (N);
+               end if;
             end;
          end if;