From: Javier Miranda Date: Tue, 19 Sep 2023 13:54:28 +0000 (+0000) Subject: ada: Crash processing pragmas Compile_Time_Error and Compile_Time_Warning X-Git-Tag: basepoints/gcc-15~5610 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85a0ce9086f92ad406bc7093a4a652929bbeb83d;p=thirdparty%2Fgcc.git ada: Crash processing pragmas Compile_Time_Error and Compile_Time_Warning 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. --- diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index d03761b1e30e..3eba3a29362a 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -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;