From: Thomas Koenig Date: Tue, 26 Dec 2017 23:29:20 +0000 (+0000) Subject: re PR fortran/83540 (Invalid code with MATMUL, -fno-realloc-lhs -ffrontend-optimize) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=62227a69b33b515058c929ac0dfe75ece9809ece;p=gcc.git re PR fortran/83540 (Invalid code with MATMUL, -fno-realloc-lhs -ffrontend-optimize) 2017-12-26 Thomas Koenig PR fortran/83540 * frontend-passes.c (create_var): If an array to be created has unknown size and -fno-realloc-lhs is in effect, return NULL. 2017-12-26 Thomas Koenig PR fortran/83540 * gfortran.dg/inline_matmul_20.f90: New test. From-SVN: r256003 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index d0cbc37bf93..c28f4fee6f3 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2017-12-26 Thomas Koenig + + PR fortran/83540 + * frontend-passes.c (create_var): If an array to be created + has unknown size and -fno-realloc-lhs is in effect, + return NULL. + 2017-12-22 Bernhard Reutner-Fischer Eric Botcazou diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c index 33820585c86..7c515f63b19 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -720,6 +720,11 @@ create_var (gfc_expr * e, const char *vname) if (e->expr_type == EXPR_CONSTANT || is_fe_temp (e)) return gfc_copy_expr (e); + /* Creation of an array of unknown size requires realloc on assignment. + If that is not possible, just return NULL. */ + if (flag_realloc_lhs == 0 && e->rank > 0 && e->shape == NULL) + return NULL; + ns = insert_block (); if (vname) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e43e9ed1797..14e8e3f0370 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-12-26 Thomas Koenig + + PR fortran/83540 + * gfortran.dg/inline_matmul_20.f90: New test. + 2017-12-26 Tom de Vries * c-c++-common/unroll-5.c: Use relative line number. diff --git a/gcc/testsuite/gfortran.dg/inline_matmul_20.f90 b/gcc/testsuite/gfortran.dg/inline_matmul_20.f90 new file mode 100644 index 00000000000..0f8728ab1dc --- /dev/null +++ b/gcc/testsuite/gfortran.dg/inline_matmul_20.f90 @@ -0,0 +1,14 @@ +! { dg-do run } +! { dg-additional-options "-fno-realloc-lhs -ffrontend-optimize" } +! This used to segfault at runtime. +! Original test case by Harald Anlauf. +program gfcbug142 + implicit none + real, allocatable :: b(:,:) + integer :: n = 5 + character(len=20) :: line + allocate (b(n,n)) + call random_number (b) + write (unit=line,fmt='(2I5)') shape (matmul (b, transpose (b))) + if (line /= ' 5 5') call abort +end program gfcbug142