On Tue, 5 Nov 2019, Jakub Jelinek wrote:

> Hi!
> 
> As the testcase shows, ARRAY_REF on an array with variable length element
> doesn't have INTEGER_CST TYPE_SIZE_UNIT which the code was assuming.
> The following patch punts in that case.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Richard.

> 2019-11-05  Jakub Jelinek  <ja...@redhat.com>
> 
>       PR tree-optimization/91945
>       * builtins.c (compute_objsize): For ARRAY_REF, only multiply off
>       by tpsize if it is both non-NULL and INTEGER_CST, otherwise punt.
>       Formatting fix.
> 
>       * gfortran.dg/pr91945.f90: New test.
> 
> --- gcc/builtins.c.jj 2019-10-10 01:33:20.000000000 +0200
> +++ gcc/builtins.c    2019-11-04 10:09:21.200301352 +0100
> @@ -3626,7 +3626,7 @@ compute_objsize (tree dest, int ostype,
>               }
>           }
>         else if (TREE_CODE (off) == SSA_NAME
> -           && INTEGRAL_TYPE_P (TREE_TYPE (off)))
> +                && INTEGRAL_TYPE_P (TREE_TYPE (off)))
>           {
>             wide_int min, max;
>             enum value_range_kind rng = get_range_info (off, &min, &max);
> @@ -3680,7 +3680,8 @@ compute_objsize (tree dest, int ostype,
>         if (TREE_CODE (dest) == ARRAY_REF)
>           {
>             tree eltype = TREE_TYPE (dest);
> -           if (tree tpsize = TYPE_SIZE_UNIT (eltype))
> +           tree tpsize = TYPE_SIZE_UNIT (eltype);
> +           if (tpsize && TREE_CODE (tpsize) == INTEGER_CST)
>               off = fold_build2 (MULT_EXPR, size_type_node, off, tpsize);
>             else
>               return NULL_TREE;
> --- gcc/testsuite/gfortran.dg/pr91945.f90.jj  2019-11-04 10:13:40.392378534 
> +0100
> +++ gcc/testsuite/gfortran.dg/pr91945.f90     2019-11-04 10:13:21.272667903 
> +0100
> @@ -0,0 +1,5 @@
> +! PR tree-optimization/91945
> +! { dg-do compile }
> +! { dg-options "-O3 -fstack-arrays -fno-guess-branch-probability" }
> +
> +include 'result_in_spec_1.f90'
> 
>       Jakub
> 
> 

-- 
Richard Biener <rguent...@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)

Reply via email to