Re: [Patch, fortran, pr65548, 2nd take, v5] [5/6 Regression] gfc_conv_procedure_call
Hi Mikael, when I got you right on IRC, then you proposed this change about the pointer attribute: diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 6d565ae..545f778 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -5361,6 +5361,7 @@ gfc_trans_allocate (gfc_code * code) /* Mark the symbol referenced or gfc_trans_assignment will bug. */ newsym-n.sym-attr.referenced = 1; + newsym-n.sym-attr.pointer = 1; e3rhs-expr_type = EXPR_VARIABLE; /* Set the symbols type, upto it was BT_UNKNOWN. */ newsym-n.sym-ts = e3rhs-ts; @@ -5374,7 +5375,6 @@ gfc_trans_allocate (gfc_code * code) /* Set the dimension and pointer attribute for arrays to be on the safe side. */ newsym-n.sym-attr.dimension = 1; - newsym-n.sym-attr.pointer = 1; newsym-n.sym-as = arr; gfc_add_full_array_ref (e3rhs, arr); } Unfortunately does this lead to numerous regressions in the testsuite. For example: ./gfortran.sh -g allocate_alloc_opt_6.f90 -o allocate_alloc_opt_6 Fortraning using ***DEVelopment*** version... allocate_alloc_opt_6.f90:26:0: allocate(t, source=mytype(1.0,2)) ^ internal compiler error: Segmentation fault 0xe09a08 crash_signal /home/vehre/Projekte/c_gcc_fortran2003_enhancements_cmbant_freelancer//gcc/gcc/toplev.c:380 0xa9cbe1 useless_type_conversion_p(tree_node*, tree_node*) /home/vehre/Projekte/c_gcc_fortran2003_enhancements_cmbant_freelancer//gcc/gcc/gimple-expr.c:83 0x10622ae tree_ssa_useless_type_conversion(tree_node*) /home/vehre/Projekte/c_gcc_fortran2003_enhancements_cmbant_freelancer//gcc/gcc/tree-ssa.c:1178 0x10622fe tree_ssa_strip_useless_type_conversions(tree_node*) /home/vehre/Projekte/c_gcc_fortran2003_enhancements_cmbant_freelancer//gcc/gcc/tree-ssa.c:1190 0xb6c4ae gimplify_expr(tree_node**, gimple_statement_base**, gimple_statement_base**, bool (*)(tree_node*), int) /home/vehre/Projekte/c_gcc_fortran2003_enhancements_cmbant_freelancer//gcc/gcc/gimplify.c:7815 0xb5e883 gimplify_modify_expr /home/vehre/Projekte/c_gcc_fortran2003_enhancements_cmbant_freelancer//gcc/gcc/gimplify.c:4644 I therefore came to a more elaborate change (revert the above one before testing this): diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 6d565ae..7b466de 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -5378,6 +5378,10 @@ gfc_trans_allocate (gfc_code * code) newsym-n.sym-as = arr; gfc_add_full_array_ref (e3rhs, arr); } + else if (POINTER_TYPE_P (TREE_TYPE (expr3))) + newsym-n.sym-attr.pointer = 1; + else + newsym-n.sym-attr.value = 1; /* The string length is known to. Set it for char arrays. */ if (e3rhs-ts.type == BT_CHARACTER) newsym-n.sym-ts.u.cl-backend_decl = expr3_len; This patch bootstraps and regtests fine again. Ok to commit? Regards, Andre On Tue, 19 May 2015 16:02:18 +0200 Mikael Morin mikael.mo...@sfr.fr wrote: Le 19/05/2015 10:50, Andre Vehreschild a écrit : Hi all, find attached latest version to fix 65548. Bootstraps and regtests ok on x86_64-linux-gnu/f21. OK. Thanks. Mikael -- Andre Vehreschild * Email: vehre ad gmx dot de
Re: [Patch, fortran, pr65548, 2nd take, v5] [5/6 Regression] gfc_conv_procedure_call
Le 20/05/2015 10:24, Andre Vehreschild a écrit : Hi Mikael, when I got you right on IRC, then you proposed this change about the pointer attribute: diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 6d565ae..545f778 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -5361,6 +5361,7 @@ gfc_trans_allocate (gfc_code * code) /* Mark the symbol referenced or gfc_trans_assignment will bug. */ newsym-n.sym-attr.referenced = 1; + newsym-n.sym-attr.pointer = 1; e3rhs-expr_type = EXPR_VARIABLE; /* Set the symbols type, upto it was BT_UNKNOWN. */ newsym-n.sym-ts = e3rhs-ts; @@ -5374,7 +5375,6 @@ gfc_trans_allocate (gfc_code * code) /* Set the dimension and pointer attribute for arrays to be on the safe side. */ newsym-n.sym-attr.dimension = 1; - newsym-n.sym-attr.pointer = 1; newsym-n.sym-as = arr; gfc_add_full_array_ref (e3rhs, arr); } Unfortunately does this lead to numerous regressions in the testsuite. For example: ./gfortran.sh -g allocate_alloc_opt_6.f90 -o allocate_alloc_opt_6 Fortraning using ***DEVelopment*** version... allocate_alloc_opt_6.f90:26:0: allocate(t, source=mytype(1.0,2)) ^ internal compiler error: Segmentation fault 0xe09a08 crash_signal /home/vehre/Projekte/c_gcc_fortran2003_enhancements_cmbant_freelancer//gcc/gcc/toplev.c:380 0xa9cbe1 useless_type_conversion_p(tree_node*, tree_node*) /home/vehre/Projekte/c_gcc_fortran2003_enhancements_cmbant_freelancer//gcc/gcc/gimple-expr.c:83 0x10622ae tree_ssa_useless_type_conversion(tree_node*) /home/vehre/Projekte/c_gcc_fortran2003_enhancements_cmbant_freelancer//gcc/gcc/tree-ssa.c:1178 0x10622fe tree_ssa_strip_useless_type_conversions(tree_node*) /home/vehre/Projekte/c_gcc_fortran2003_enhancements_cmbant_freelancer//gcc/gcc/tree-ssa.c:1190 0xb6c4ae gimplify_expr(tree_node**, gimple_statement_base**, gimple_statement_base**, bool (*)(tree_node*), int) /home/vehre/Projekte/c_gcc_fortran2003_enhancements_cmbant_freelancer//gcc/gcc/gimplify.c:7815 0xb5e883 gimplify_modify_expr /home/vehre/Projekte/c_gcc_fortran2003_enhancements_cmbant_freelancer//gcc/gcc/gimplify.c:4644 I therefore came to a more elaborate change (revert the above one before testing this): diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 6d565ae..7b466de 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -5378,6 +5378,10 @@ gfc_trans_allocate (gfc_code * code) newsym-n.sym-as = arr; gfc_add_full_array_ref (e3rhs, arr); } + else if (POINTER_TYPE_P (TREE_TYPE (expr3))) + newsym-n.sym-attr.pointer = 1; + else + newsym-n.sym-attr.value = 1; /* The string length is known to. Set it for char arrays. */ if (e3rhs-ts.type == BT_CHARACTER) newsym-n.sym-ts.u.cl-backend_decl = expr3_len; This patch bootstraps and regtests fine again. Ok to commit? You can drop the else branch. OK to commit with that change. Thanks. Mikael
Re: [Patch, fortran, pr65548, 2nd take, v5] [5/6 Regression] gfc_conv_procedure_call
Hi all, Mikael, thanks for the review. Committed as r223445 (without the else-branch). Regards, Andre -- Andre Vehreschild * Email: vehre ad gmx dot de Index: gcc/fortran/ChangeLog === --- gcc/fortran/ChangeLog (Revision 223444) +++ gcc/fortran/ChangeLog (Arbeitskopie) @@ -1,3 +1,13 @@ +2015-05-20 Andre Vehreschild ve...@gmx.de + + PR fortran/65548 + * trans-stmt.c (gfc_trans_allocate): Always retrieve the + descriptor or a reference to a source= expression for + arrays and non-arrays, respectively. Use a temporary + symbol and gfc_trans_assignment for all source= + assignments to allocated objects besides for class and + derived types. + 2015-05-19 Jakub Jelinek ja...@redhat.com PR middle-end/66199 Index: gcc/fortran/trans-stmt.c === --- gcc/fortran/trans-stmt.c (Revision 223444) +++ gcc/fortran/trans-stmt.c (Arbeitskopie) @@ -5088,7 +5088,7 @@ gfc_trans_allocate (gfc_code * code) { gfc_alloc *al; - gfc_expr *expr; + gfc_expr *expr, *e3rhs = NULL; gfc_se se, se_sz; tree tmp; tree parm; @@ -5109,6 +5109,7 @@ stmtblock_t post; tree nelems; bool upoly_expr, tmp_expr3_len_flag = false, al_len_needs_set; + gfc_symtree *newsym = NULL; if (!code-ext.alloc.list) return NULL_TREE; @@ -5148,14 +5149,11 @@ TREE_USED (label_finish) = 0; } - /* When an expr3 is present, try to evaluate it only once. In most - cases expr3 is invariant for all elements of the allocation list. - Only exceptions are arrays. Furthermore the standards prevent a - dependency of expr3 on the objects in the allocate list. Therefore - it is safe to pre-evaluate expr3 for complicated expressions, i.e. - everything not a variable or constant. When an array allocation - is wanted, then the following block nevertheless evaluates the - _vptr, _len and element_size for expr3. */ + /* When an expr3 is present evaluate it only once. The standards prevent a + dependency of expr3 on the objects in the allocate list. An expr3 can + be pre-evaluated in all cases. One just has to make sure, to use the + correct way, i.e., to get the descriptor or to get a reference + expression. */ if (code-expr3) { bool vtab_needed = false; @@ -5168,75 +5166,77 @@ al = al-next) vtab_needed = (al-expr-ts.type == BT_CLASS); - /* A array expr3 needs the scalarizer, therefore do not process it - here. */ - if (code-expr3-expr_type != EXPR_ARRAY - (code-expr3-rank == 0 - || code-expr3-expr_type == EXPR_FUNCTION) - (!code-expr3-symtree - || !code-expr3-symtree-n.sym-as) - !gfc_is_class_array_ref (code-expr3, NULL)) + /* When expr3 is a variable, i.e., a very simple expression, + then convert it once here. */ + if (code-expr3-expr_type == EXPR_VARIABLE + || code-expr3-expr_type == EXPR_ARRAY + || code-expr3-expr_type == EXPR_CONSTANT) { - /* When expr3 is a variable, i.e., a very simple expression, - then convert it once here. */ - if ((code-expr3-expr_type == EXPR_VARIABLE) - || code-expr3-expr_type == EXPR_CONSTANT) + if (!code-expr3-mold + || code-expr3-ts.type == BT_CHARACTER + || vtab_needed) { - if (!code-expr3-mold - || code-expr3-ts.type == BT_CHARACTER - || vtab_needed) - { - /* Convert expr3 to a tree. */ - gfc_init_se (se, NULL); - se.want_pointer = 1; - gfc_conv_expr (se, code-expr3); - if (!code-expr3-mold) - expr3 = se.expr; - else - expr3_tmp = se.expr; - expr3_len = se.string_length; - gfc_add_block_to_block (block, se.pre); - gfc_add_block_to_block (post, se.post); - } - /* else expr3 = NULL_TREE set above. */ - } - else - { - /* In all other cases evaluate the expr3 and create a - temporary. */ + /* Convert expr3 to a tree. */ gfc_init_se (se, NULL); - if (code-expr3-rank != 0 - code-expr3-expr_type == EXPR_FUNCTION - code-expr3-value.function.isym) + /* For all simple expression just get the descriptor or the + reference, respectively, depending on the rank of the expr. */ + if (code-expr3-rank != 0) gfc_conv_expr_descriptor (se, code-expr3); else gfc_conv_expr_reference (se, code-expr3); - if (code-expr3-ts.type == BT_CLASS) - gfc_conv_class_to_class (se, code-expr3, - code-expr3-ts, - false, true, - false, false); + if (!code-expr3-mold) + expr3 = se.expr; + else + expr3_tmp = se.expr; + expr3_len = se.string_length; gfc_add_block_to_block (block, se.pre); gfc_add_block_to_block (post, se.post); - /* Prevent aliasing, i.e., se.expr may be already a + } + /* else expr3 = NULL_TREE set above. */ + } + else + { + /* In all other cases evaluate the expr3 and create a + temporary. */ +
Re: [Patch, fortran, pr65548, 2nd take, v5] [5/6 Regression] gfc_conv_procedure_call
Hi all, find attached latest version to fix 65548. Bootstraps and regtests ok on x86_64-linux-gnu/f21. - Andre -- Andre Vehreschild * Email: vehre ad gmx dot de pr65548_5.clog Description: Binary data diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 814bdde..6d565ae 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -5088,7 +5088,7 @@ tree gfc_trans_allocate (gfc_code * code) { gfc_alloc *al; - gfc_expr *expr; + gfc_expr *expr, *e3rhs = NULL; gfc_se se, se_sz; tree tmp; tree parm; @@ -5109,6 +5109,7 @@ gfc_trans_allocate (gfc_code * code) stmtblock_t post; tree nelems; bool upoly_expr, tmp_expr3_len_flag = false, al_len_needs_set; + gfc_symtree *newsym = NULL; if (!code-ext.alloc.list) return NULL_TREE; @@ -5148,14 +5149,11 @@ gfc_trans_allocate (gfc_code * code) TREE_USED (label_finish) = 0; } - /* When an expr3 is present, try to evaluate it only once. In most - cases expr3 is invariant for all elements of the allocation list. - Only exceptions are arrays. Furthermore the standards prevent a - dependency of expr3 on the objects in the allocate list. Therefore - it is safe to pre-evaluate expr3 for complicated expressions, i.e. - everything not a variable or constant. When an array allocation - is wanted, then the following block nevertheless evaluates the - _vptr, _len and element_size for expr3. */ + /* When an expr3 is present evaluate it only once. The standards prevent a + dependency of expr3 on the objects in the allocate list. An expr3 can + be pre-evaluated in all cases. One just has to make sure, to use the + correct way, i.e., to get the descriptor or to get a reference + expression. */ if (code-expr3) { bool vtab_needed = false; @@ -5168,75 +5166,77 @@ gfc_trans_allocate (gfc_code * code) al = al-next) vtab_needed = (al-expr-ts.type == BT_CLASS); - /* A array expr3 needs the scalarizer, therefore do not process it - here. */ - if (code-expr3-expr_type != EXPR_ARRAY - (code-expr3-rank == 0 - || code-expr3-expr_type == EXPR_FUNCTION) - (!code-expr3-symtree - || !code-expr3-symtree-n.sym-as) - !gfc_is_class_array_ref (code-expr3, NULL)) - { - /* When expr3 is a variable, i.e., a very simple expression, + /* When expr3 is a variable, i.e., a very simple expression, then convert it once here. */ - if ((code-expr3-expr_type == EXPR_VARIABLE) - || code-expr3-expr_type == EXPR_CONSTANT) - { - if (!code-expr3-mold - || code-expr3-ts.type == BT_CHARACTER - || vtab_needed) - { - /* Convert expr3 to a tree. */ - gfc_init_se (se, NULL); - se.want_pointer = 1; - gfc_conv_expr (se, code-expr3); - if (!code-expr3-mold) - expr3 = se.expr; - else - expr3_tmp = se.expr; - expr3_len = se.string_length; - gfc_add_block_to_block (block, se.pre); - gfc_add_block_to_block (post, se.post); - } - /* else expr3 = NULL_TREE set above. */ - } - else + if (code-expr3-expr_type == EXPR_VARIABLE + || code-expr3-expr_type == EXPR_ARRAY + || code-expr3-expr_type == EXPR_CONSTANT) + { + if (!code-expr3-mold + || code-expr3-ts.type == BT_CHARACTER + || vtab_needed) { - /* In all other cases evaluate the expr3 and create a - temporary. */ + /* Convert expr3 to a tree. */ gfc_init_se (se, NULL); - if (code-expr3-rank != 0 - code-expr3-expr_type == EXPR_FUNCTION - code-expr3-value.function.isym) + /* For all simple expression just get the descriptor or the + reference, respectively, depending on the rank of the expr. */ + if (code-expr3-rank != 0) gfc_conv_expr_descriptor (se, code-expr3); else gfc_conv_expr_reference (se, code-expr3); - if (code-expr3-ts.type == BT_CLASS) - gfc_conv_class_to_class (se, code-expr3, - code-expr3-ts, - false, true, - false, false); + if (!code-expr3-mold) + expr3 = se.expr; + else + expr3_tmp = se.expr; + expr3_len = se.string_length; gfc_add_block_to_block (block, se.pre); gfc_add_block_to_block (post, se.post); - /* Prevent aliasing, i.e., se.expr may be already a + } + /* else expr3 = NULL_TREE set above. */ + } + else + { + /* In all other cases evaluate the expr3 and create a + temporary. */ + gfc_init_se (se, NULL); + symbol_attribute attr; + /* Get the descriptor for all arrays, that are not allocatable or + pointer, because the latter are descriptors already. */ + attr = gfc_expr_attr (code-expr3); + if (code-expr3-rank != 0 !attr.allocatable !attr.pointer) + gfc_conv_expr_descriptor (se, code-expr3); + else + gfc_conv_expr_reference (se, code-expr3); + if (code-expr3-ts.type == BT_CLASS) + gfc_conv_class_to_class (se, code-expr3, + code-expr3-ts, + false, true, +
Re: [Patch, fortran, pr65548, 2nd take, v5] [5/6 Regression] gfc_conv_procedure_call
Le 19/05/2015 10:50, Andre Vehreschild a écrit : Hi all, find attached latest version to fix 65548. Bootstraps and regtests ok on x86_64-linux-gnu/f21. OK. Thanks. Mikael