From: Thomas Koenig Date: Sun, 3 Feb 2019 19:38:25 +0000 (+0000) Subject: re PR fortran/67679 (-Wunitialized reports on compiler-generated variables) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6090f915917f433509168b20c2ea9c3b4096c024;p=gcc.git re PR fortran/67679 (-Wunitialized reports on compiler-generated variables) 2019-02-03 Thomas Koenig PR fortran/67679 * trans-array.c (gfc_array_allocate): For setting the bounds on the new array, add a condition for a not previously allocated variable. 2019-02-03 Thomas Koenig PR fortran/67679 * gfortran.dg/warn_undefined_1.f90: New test. * gfortran.dg/coarray_lock_7.f90: Fix patterns in test. From-SVN: r268502 --- diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index b885fe6187d..2527950aacb 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -5736,6 +5736,7 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree status, tree errmsg, tree var_overflow = NULL_TREE; tree cond; tree set_descriptor; + tree not_prev_allocated = NULL_TREE; tree element_size = NULL_TREE; stmtblock_t set_descriptor_block; stmtblock_t elseblock; @@ -5882,8 +5883,6 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree status, tree errmsg, } } - gfc_start_block (&elseblock); - /* Allocate memory to store the data. */ if (POINTER_TYPE_P (TREE_TYPE (se->expr))) se->expr = build_fold_indirect_ref_loc (input_location, se->expr); @@ -5899,6 +5898,19 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree status, tree errmsg, pointer = gfc_conv_descriptor_data_get (se->expr); STRIP_NOPS (pointer); + if (allocatable) + { + not_prev_allocated = gfc_create_var (logical_type_node, + "not_prev_allocated"); + tmp = fold_build2_loc (input_location, EQ_EXPR, + logical_type_node, pointer, + build_int_cst (TREE_TYPE (pointer), 0)); + + gfc_add_modify (&se->pre, not_prev_allocated, tmp); + } + + gfc_start_block (&elseblock); + /* The allocatable variant takes the old pointer as first argument. */ if (allocatable) gfc_allocate_allocatable (&elseblock, pointer, size, token, @@ -5939,6 +5951,11 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree status, tree errmsg, cond = fold_build2_loc (input_location, EQ_EXPR, logical_type_node, status, build_int_cst (TREE_TYPE (status), 0)); + + if (not_prev_allocated != NULL_TREE) + cond = fold_build2_loc (input_location, TRUTH_OR_EXPR, + logical_type_node, cond, not_prev_allocated); + gfc_add_expr_to_block (&se->pre, fold_build3_loc (input_location, COND_EXPR, void_type_node, cond, diff --git a/gcc/testsuite/gfortran.dg/coarray_lock_7.f90 b/gcc/testsuite/gfortran.dg/coarray_lock_7.f90 index 1d8eb7cf928..aedb2267413 100644 --- a/gcc/testsuite/gfortran.dg/coarray_lock_7.f90 +++ b/gcc/testsuite/gfortran.dg/coarray_lock_7.f90 @@ -35,8 +35,8 @@ end ! { dg-final { scan-tree-dump-times "_gfortran_caf_lock \\(caf_token.., 0, 0, 0B, 0B, 0B, 0\\);" 1 "original" } } ! { dg-final { scan-tree-dump-times "_gfortran_caf_unlock \\(caf_token.., 0, 0, 0B, 0B, 0\\);" 1 "original" } } -! { dg-final { scan-tree-dump-times "_gfortran_caf_lock \\(caf_token.., .*\\(\\(3 - parm...dim\\\[0\\\].lbound\\) \\+ \\(MAX_EXPR \\+ 1\\) \\* \\(3 - parm...dim\\\[1\\\].lbound\\)\\), 0, 0B, &ii, 0B, 0\\);|_gfortran_caf_lock \\(caf_token.1, \\(3 - parm...dim\\\[0\\\].lbound\\) \\+ \\(MAX_EXPR \\+ 1\\) \\* \\(3 - parm...dim\\\[1\\\].lbound\\), 0, 0B, &ii, 0B, 0\\);" 1 "original" } } -! { dg-final { scan-tree-dump-times "_gfortran_caf_unlock \\(caf_token.., .*\\(\\(2 - parm...dim\\\[0\\\].lbound\\) \\+ \\(MAX_EXPR \\+ 1\\) \\* \\(3 - parm...dim\\\[1\\\].lbound\\)\\), 0, &ii, 0B, 0\\);|_gfortran_caf_unlock \\(caf_token.., \\(2 - parm...dim\\\[0\\\].lbound\\) \\+ \\(MAX_EXPR \\+ 1\\) \\* \\(3 - parm...dim\\\[1\\\].lbound\\), 0, &ii, 0B, 0\\);" 1 "original" } } +! { dg-final { scan-tree-dump-times "_gfortran_caf_lock \\(caf_token.., .*\\(\\(3 - parm....dim\\\[0\\\].lbound\\) \\+ \\(MAX_EXPR \\+ 1\\) \\* \\(3 - parm....dim\\\[1\\\].lbound\\)\\), 0, 0B, &ii, 0B, 0\\);|_gfortran_caf_lock \\(caf_token.1, \\(3 - parm....dim\\\[0\\\].lbound\\) \\+ \\(MAX_EXPR \\+ 1\\) \\* \\(3 - parm....dim\\\[1\\\].lbound\\), 0, 0B, &ii, 0B, 0\\);" 1 "original" } } +! { dg-final { scan-tree-dump-times "_gfortran_caf_unlock \\(caf_token.., .*\\(\\(2 - parm....dim\\\[0\\\].lbound\\) \\+ \\(MAX_EXPR \\+ 1\\) \\* \\(3 - parm....dim\\\[1\\\].lbound\\)\\), 0, &ii, 0B, 0\\);|_gfortran_caf_unlock \\(caf_token.., \\(2 - parm....dim\\\[0\\\].lbound\\) \\+ \\(MAX_EXPR \\+ 1\\) \\* \\(3 - parm....dim\\\[1\\\].lbound\\), 0, &ii, 0B, 0\\);" 1 "original" } } ! { dg-final { scan-tree-dump-times "_gfortran_caf_lock \\(three.token, 0, \\(integer\\(kind=4\\)\\) \\(5 - three.dim\\\[0\\\].lbound\\), &acquired.\[0-9\]+, 0B, 0B, 0\\);|_gfortran_caf_lock \\(three.token, 0, 5 - three.dim\\\[0\\\].lbound, &acquired.\[0-9\]+, 0B, 0B, 0\\);" 1 "original" } } ! { dg-final { scan-tree-dump-times "_gfortran_caf_unlock \\(three.token, 0, \\(integer\\(kind=4\\)\\) \\(8 - three.dim\\\[0\\\].lbound\\), &ii, 0B, 0\\);|_gfortran_caf_unlock \\(three.token, 0, 8 - three.dim\\\[0\\\].lbound, &ii, 0B, 0\\);" 1 "original" } }