This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
When expanding a limited aggregate into individual assignments, we create a transient scope if the type of a component requires it. This must not be done if the context is an initialization procedure, because the target of the assignment must be visible outside of the block, and stack cleanup will happen on return from the initialization call. Otherwise this may result in dangling stack references in the back-end, which produce garbled results when compiled at higher optimization levels. Executing the following: gnatmake -q -O2 cutdown cutdown must yield: 0.00000E+00 --- with Text_IO; use Text_IO; procedure Cutdown is type Angle_Object_T is tagged record M_Value : Float := 0.0; end record; Zero : constant Angle_Object_T := (M_Value => 0.0); type Platform_T is record M_Roll : Angle_Object_T := Zero; end record; package Observable_Nongeneric is type Writer_T is tagged limited record M_Value : Platform_T; end record; function Init (Value : in Platform_T) return Writer_T; end Observable_Nongeneric; package body Observable_Nongeneric is -------------------------------------------------------------------------- function Init (Value : in Platform_T) return Writer_T is begin return (M_Value => Value); end Init; -------------------------------------------------------------------------- end Observable_Nongeneric; type Object_T is tagged limited record M_Platform : aliased Observable_Nongeneric.Writer_T := Observable_Nongeneric.Init (Platform_T'(others => <>)); end record; Data : Object_T; begin Put_Line (Data.M_Platform.M_Value.M_Roll.M_Value'Img); if Data.M_Platform.M_Value.M_Roll.M_Value /= 0.0 then raise Program_Error; end if; end Cutdown; Tested on x86_64-pc-linux-gnu, committed on trunk 2014-10-20 Ed Schonberg <schonberg@adacore.com> * exp_aggr.adb (Convert_To_Assignments): Do not create a transient scope for a component whose type requires it, if the context is an initialization procedure, because the target of the assignment must be visible outside of the block.
Attachment:
difs
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |