From: Eric Botcazou Date: Sat, 23 Feb 2019 10:04:41 +0000 (+0000) Subject: re PR ada/89349 (segfault when building GCC 7 & 8 branch with GCC master) X-Git-Tag: releases/gcc-7.5.0~576 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c47a0a6e1acecb765de369745a0cf8dd94f28d7;p=thirdparty%2Fgcc.git re PR ada/89349 (segfault when building GCC 7 & 8 branch with GCC master) PR ada/89349 Backport from mainline 2018-05-25 Arnaud Charlet * osint.ads (Unknown_Attributes): No longer pretend this is a constant. (No_File_Info_Cache): Initialize separately. * osint.adb (No_File_Info_Cache): Update initializer. From-SVN: r269154 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 11a9ff15fe16..ee33d9fb21e6 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,13 @@ +2019-02-23 Eric Botcazou + + PR ada/89349 + Backport from mainline + 2018-05-25 Arnaud Charlet + + * osint.ads (Unknown_Attributes): No longer pretend this is a constant. + (No_File_Info_Cache): Initialize separately. + * osint.adb (No_File_Info_Cache): Update initializer. + 2019-02-08 Eric Botcazou * gcc-interface/trans.c (Loop_Statement_to_gnu): Replace tests on diff --git a/gcc/ada/osint.adb b/gcc/ada/osint.adb index 8c6c22b9d145..1ede04ff5646 100644 --- a/gcc/ada/osint.adb +++ b/gcc/ada/osint.adb @@ -250,8 +250,7 @@ package body Osint is Attr : aliased File_Attributes; end record; - No_File_Info_Cache : constant File_Info_Cache := - (No_File, Unknown_Attributes); + No_File_Info_Cache : constant File_Info_Cache := (No_File, (others => 0)); package File_Name_Hash_Table is new GNAT.HTable.Simple_HTable ( Header_Num => File_Hash_Num, diff --git a/gcc/ada/osint.ads b/gcc/ada/osint.ads index a96e83ea8e78..893ff7b07389 100644 --- a/gcc/ada/osint.ads +++ b/gcc/ada/osint.ads @@ -273,10 +273,26 @@ package Osint is -- from the disk and then cached in the File_Attributes parameter (possibly -- along with other values). - type File_Attributes is private; - Unknown_Attributes : constant File_Attributes; + File_Attributes_Size : constant Natural := 32; + -- This should be big enough to fit a "struct file_attributes" on any + -- system. It doesn't cause any malfunction if it is too big (which avoids + -- the need for either mapping the struct exactly or importing the sizeof + -- from C, which would result in dynamic code). However, it does waste + -- space (e.g. when a component of this type appears in a record, if it is + -- unnecessarily large). Note: for runtime units, use System.OS_Constants. + -- SIZEOF_struct_file_attributes instead, which has the exact value. + + type File_Attributes is + array (1 .. File_Attributes_Size) + of System.Storage_Elements.Storage_Element; + for File_Attributes'Alignment use Standard'Maximum_Alignment; + + Unknown_Attributes : File_Attributes; -- A cache for various attributes for a file (length, accessibility,...) - -- This must be initialized to Unknown_Attributes prior to the first call. + -- Will be initialized properly at elaboration (for efficiency later on, + -- avoid function calls every time we want to reset the attributes) prior + -- to the first usage. We cannot make it constant since the compiler may + -- put it in a read-only section. function Is_Directory (Name : C_File_Name; @@ -769,22 +785,4 @@ private -- detected, the file being written is deleted, and a fatal error is -- signalled. - File_Attributes_Size : constant Natural := 32; - -- This should be big enough to fit a "struct file_attributes" on any - -- system. It doesn't cause any malfunction if it is too big (which avoids - -- the need for either mapping the struct exactly or importing the sizeof - -- from C, which would result in dynamic code). However, it does waste - -- space (e.g. when a component of this type appears in a record, if it is - -- unnecessarily large). Note: for runtime units, use System.OS_Constants. - -- SIZEOF_struct_file_attributes instead, which has the exact value. - - type File_Attributes is - array (1 .. File_Attributes_Size) - of System.Storage_Elements.Storage_Element; - for File_Attributes'Alignment use Standard'Maximum_Alignment; - - Unknown_Attributes : constant File_Attributes := (others => 0); - -- Will be initialized properly at elaboration (for efficiency later on, - -- avoid function calls every time we want to reset the attributes). - end Osint;