From 567a6e1cdb3cae09ae74bdd528fd31c0b4956ad2 Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Sat, 13 Jan 2018 13:52:34 +0000 Subject: [PATCH] re PR fortran/52162 (Bogus -fcheck=bounds with realloc on assignment to unallocated LHS) 2018-01-13 Paul Thomas PR fortran/52162 * trans-expr.c (gfc_trans_scalar_assign): Flag is_alloc_lhs if the rhs expression is neither an elemental nor a conversion function. PR fortran/83622 * trans-array.c (is_pointer_array): Remove unconditional return of false for -fopenmp. 2018-01-13 Paul Thomas PR fortran/52162 * gfortran.dg/bounds_check_19.f90 : New test. From-SVN: r256607 --- gcc/fortran/ChangeLog | 11 +++++++++ gcc/fortran/trans-array.c | 3 --- gcc/fortran/trans-expr.c | 7 ++++-- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gfortran.dg/bounds_check_19.f90 | 24 +++++++++++++++++++ 5 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/bounds_check_19.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 8f32e07babf..1e421d9027d 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,14 @@ +2018-01-13 Paul Thomas + + PR fortran/52162 + * trans-expr.c (gfc_trans_scalar_assign): Flag is_alloc_lhs if + the rhs expression is neither an elemental nor a conversion + function. + + PR fortran/83622 + * trans-array.c (is_pointer_array): Remove unconditional return + of false for -fopenmp. + 2018-01-13 Thomas Koenig diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index e35e0c9195f..0cf1831802b 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -786,9 +786,6 @@ gfc_add_ss_to_loop (gfc_loopinfo * loop, gfc_ss * head) static bool is_pointer_array (tree expr) { - if (flag_openmp) - return false; - if (expr == NULL_TREE || !GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (expr)) || GFC_CLASS_TYPE_P (TREE_TYPE (expr))) diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index add0d699153..e90036f4306 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -9924,9 +9924,12 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag, /* Walk the lhs. */ lss = gfc_walk_expr (expr1); if (gfc_is_reallocatable_lhs (expr1) - && !(expr2->expr_type == EXPR_FUNCTION - && expr2->value.function.isym != NULL)) + && !(expr2->expr_type == EXPR_FUNCTION + && expr2->value.function.isym != NULL + && !(expr2->value.function.isym->elemental + || expr2->value.function.isym->conversion))) lss->is_alloc_lhs = 1; + rss = NULL; if ((expr1->ts.type == BT_DERIVED) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4463b9b39d0..04c613fea6e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-01-13 Paul Thomas + + PR fortran/52162 + * gfortran.dg/bounds_check_19.f90 : New test. + 2018-01-12 Jakub Jelinek * gcc.target/powerpc/float128-hw7.c: Use scan-assembler-times diff --git a/gcc/testsuite/gfortran.dg/bounds_check_19.f90 b/gcc/testsuite/gfortran.dg/bounds_check_19.f90 new file mode 100644 index 00000000000..21651f1fa6b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/bounds_check_19.f90 @@ -0,0 +1,24 @@ +! { dg-do run } +! { dg-options "-fbounds-check" } +! +! Test the fix for PR52162 in which the elemental and conversion +! intrinsics in lines 14 and 19 would cause the bounds check to fail. +! +! Contributed by Dominique d'Humieres +! + integer(4), allocatable :: a(:) + integer(8), allocatable :: b(:) + real, allocatable :: c(:) + allocate (b(7:11), source = [7_8,8_8,9_8,10_8,11_8]) + + a = b ! Implicit conversion + + if (lbound (a, 1) .ne. lbound(b, 1)) call abort + if (ubound (a, 1) .ne. ubound(b, 1)) call abort + + c = sin(real(b(9:11))/100_8) ! Elemental intrinsic + + if ((ubound(c, 1) - lbound(c, 1)) .ne. 2) call abort + if (any (nint(asin(c)*100.0) .ne. b(9:11))) call abort + deallocate (a, b, c) + end -- 2.30.2