diff options
author | Andre Vehreschild <vehre@gcc.gnu.org> | 2017-02-05 16:43:03 +0100 |
---|---|---|
committer | Andre Vehreschild <vehre@gcc.gnu.org> | 2017-02-05 16:43:03 +0100 |
commit | 139d4065e80d9141a23cf84d8b31fc9ee7c5d8c3 (patch) | |
tree | c07eb1799927d7474a9ed1151941fa320a1276ef /gcc/fortran/trans-stmt.c | |
parent | ea06c7b0c4299833959a6a62a7a57533e60c8418 (diff) | |
download | gcc-139d4065e80d9141a23cf84d8b31fc9ee7c5d8c3.zip gcc-139d4065e80d9141a23cf84d8b31fc9ee7c5d8c3.tar.gz gcc-139d4065e80d9141a23cf84d8b31fc9ee7c5d8c3.tar.bz2 |
re PR fortran/79344 (segmentation faults and run-time errors)
gcc/fortran/ChangeLog:
2017-02-05 Andre Vehreschild <vehre@gcc.gnu.org>
PR fortran/79344
* trans-stmt.c (gfc_trans_allocate): Only deallocate the components of
the temporary, when a new object was created for the temporary. Not
when it is just an alias to an existing object.
gcc/testsuite/ChangeLog:
2017-02-04 Andre Vehreschild <vehre@gcc.gnu.org>
PR fortran/79344
* gfortran.dg/allocate_with_source_24.f90: New test.
From-SVN: r245194
Diffstat (limited to 'gcc/fortran/trans-stmt.c')
-rw-r--r-- | gcc/fortran/trans-stmt.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 61e597f..773ca70 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -5572,7 +5572,8 @@ gfc_trans_allocate (gfc_code * code) expression. */ if (code->expr3) { - bool vtab_needed = false, temp_var_needed = false; + bool vtab_needed = false, temp_var_needed = false, + temp_obj_created = false; is_coarray = gfc_is_coarray (code->expr3); @@ -5645,7 +5646,7 @@ gfc_trans_allocate (gfc_code * code) code->expr3->ts, false, true, false, false); - temp_var_needed = !VAR_P (se.expr); + temp_obj_created = temp_var_needed = !VAR_P (se.expr); } gfc_add_block_to_block (&block, &se.pre); gfc_add_block_to_block (&post, &se.post); @@ -5714,11 +5715,12 @@ gfc_trans_allocate (gfc_code * code) } /* Deallocate any allocatable components in expressions that use a - temporary, i.e. are not of expr-type EXPR_VARIABLE or force the - use of a temporary, after the assignment of expr3 is completed. */ + temporary object, i.e. are not a simple alias of to an EXPR_VARIABLE. + E.g. temporaries of a function call need freeing of their components + here. */ if ((code->expr3->ts.type == BT_DERIVED || code->expr3->ts.type == BT_CLASS) - && (code->expr3->expr_type != EXPR_VARIABLE || temp_var_needed) + && (code->expr3->expr_type != EXPR_VARIABLE || temp_obj_created) && code->expr3->ts.u.derived->attr.alloc_comp) { tmp = gfc_deallocate_alloc_comp (code->expr3->ts.u.derived, |