aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/expr.c
diff options
context:
space:
mode:
authorAndre Vehreschild <vehre@gcc.gnu.org>2016-11-06 17:10:22 +0100
committerAndre Vehreschild <vehre@gcc.gnu.org>2016-11-06 17:10:22 +0100
commitcc03bf7a7bf6bb0a11f7fa90ead51eec7d770af9 (patch)
tree9ac441670f08e2dbbef73cdcca9444907c806f9e /gcc/fortran/expr.c
parent18bb8b8a2a67091517d60b7192e454ed11e9280d (diff)
downloadgcc-cc03bf7a7bf6bb0a11f7fa90ead51eec7d770af9.zip
gcc-cc03bf7a7bf6bb0a11f7fa90ead51eec7d770af9.tar.gz
gcc-cc03bf7a7bf6bb0a11f7fa90ead51eec7d770af9.tar.bz2
allocate_with_source_14.f03: Fixed number mallocs occuring.
gcc/testsuite/ChangeLog: 2016-11-06 Andre Vehreschild <vehre@gcc.gnu.org> * gfortran.dg/allocate_with_source_14.f03: Fixed number mallocs occuring. gcc/fortran/ChangeLog: 2016-11-06 Andre Vehreschild <vehre@gcc.gnu.org> * expr.c (is_non_empty_structure_constructor): New function to detect non-empty structure constructor. (gfc_has_default_initializer): Analyse initializers. * resolve.c (cond_init): Removed. (resolve_allocate_expr): Removed dead code. Moved invariant code out of the loop over all objects to allocate. (resolve_allocate_deallocate): Added the invariant code remove from resolve_allocate_expr. * trans-array.c (gfc_array_allocate): Removed nullify of structure components in favour of doing this in gfc_trans_allocate for both scalars and arrays in the same place. * trans-expr.c (gfc_trans_init_assign): Always using _vptr->copy for class objects. * trans-stmt.c (allocate_get_initializer): Get the initializer expression for object allocated. (gfc_trans_allocate): Nullify a derived type only, when no SOURCE= or MOLD= is present preventing duplicate work. Moved the creation of the init-expression here to prevent code for conditions that can not occur on freshly allocated object, like checking for the need to free allocatable components. From-SVN: r241885
Diffstat (limited to 'gcc/fortran/expr.c')
-rw-r--r--gcc/fortran/expr.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index bb183d4..0e94ae8 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -4131,6 +4131,26 @@ gfc_apply_init (gfc_typespec *ts, symbol_attribute *attr, gfc_expr *init)
}
+/* Check whether an expression is a structure constructor and whether it has
+ other values than NULL. */
+
+bool
+is_non_empty_structure_constructor (gfc_expr * e)
+{
+ if (e->expr_type != EXPR_STRUCTURE)
+ return false;
+
+ gfc_constructor *cons = gfc_constructor_first (e->value.constructor);
+ while (cons)
+ {
+ if (!cons->expr || cons->expr->expr_type != EXPR_NULL)
+ return true;
+ cons = gfc_constructor_next (cons);
+ }
+ return false;
+}
+
+
/* Check for default initializer; sym->value is not enough
as it is also set for EXPR_NULL of allocatables. */
@@ -4145,7 +4165,9 @@ gfc_has_default_initializer (gfc_symbol *der)
{
if (!c->attr.pointer && !c->attr.proc_pointer
&& !(c->attr.allocatable && der == c->ts.u.derived)
- && gfc_has_default_initializer (c->ts.u.derived))
+ && ((c->initializer
+ && is_non_empty_structure_constructor (c->initializer))
+ || gfc_has_default_initializer (c->ts.u.derived)))
return true;
if (c->attr.pointer && c->initializer)
return true;