This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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] | |
All,
Currently the '-finit-derived' flag does not handle UNIONs properly.
Specifically, a default initializer may not be appropriately generated
for BT_UNION components, leaving some memory in the middle of the
structure uninitialized even with -finit-derived. This patch ensures
UNION nodes receive a NULL structure constructor with -finit-derived
while simultaneously respecting the first user-given initializers
within the union's MAP nodes, if any. With the NULL structure
constructor the gcc middle-end figures out the full initialization, as
if you were initializing a C union like "u = {0}", and a bit of work
is saved on our end.
The front-end stores an EXPR_NULL node as the UNION's constructor
expression when -finit-derived is given and it has no user-specified
MAP initializers. When the node propagates through the resolution
phase and makes it to trans-expr.c, gfc_trans_subcomponent_assign and
gfc_conv_union_initializer use this to identify whether to generate a
null initializer or use the user-given MAP initializer.
For the attached testcases: dec_init_3.f90 exhibits improper
initialization for unions before this patch, and dec_init_4.f90
verifies that explicit user-given initializers are not regressed with
the implementation.
Since this only touches my own UNION and -finit-derived code I aim to
commit it in a few days if nobody finds anything wrong with the patch.
Bootstraps and regtests on x86_64-redhat-linux.
---
Fritz Reese
2016-10-25 Fritz Reese <fritzoreese@gmail.com>
Fix initialization of UNIONs with -finit-derived.
gcc/fortran/
* expr.c (generate_union_initializer, get_union_initializer): New.
* expr.c (component_initializer): Consider BT_UNION specially.
* resolve.c (resolve_structure_cons): Hack for BT_UNION.
* trans-expr.c (gfc_trans_subcomponent_assign): Ditto.
* trans-expr.c (gfc_conv_union_initializer): New.
* trans-expr.c (gfc_conv_structure): Replace UNION handling code with
new function gfc_conv_union_initializer.
gcc/testsuite/gfortran.dg/
* dec_init_1.f90, dec_init_2.f90: Remove -fdump-tree-original.
* dec_init_3.f90, dec_init_4.f90: New testcases.
Attachment:
init_derived_union.diff
Description: Text document
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |