Hi all!

Proposed patch to Bug 90350 - ubound ICE on assumed size array even

though explicit bound is specified

Patch tested only on x86_64-pc-linux-gnu.

Bumped into the same problem.

Probably a better fix would be to add an extra step to the reference

chain reflecting that array-section are explicit-shape arrays not

whatever that was sectioned. But, although this pattern of problem shows

up in the code in other places, it may be more trouble than it is worth...

Thank you very much.

Best regards,

José Rui

2020-4-19 José Rui Faustino de Sousa <

[hidden email]>

PR fortran/90350

* simplify.c (simplify_bound): In the case of assumed-size arrays check

if the reference is to a full array.

2020-4-19 José Rui Faustino de Sousa <

[hidden email]>

PR fortran/90350

* PR90350.f90: New test.

diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c

index d5703e3..4818368 100644

--- a/gcc/fortran/simplify.c

+++ b/gcc/fortran/simplify.c

@@ -4157,6 +4157,7 @@ simplify_bound (gfc_expr *array, gfc_expr *dim,

gfc_expr *kind, int upper)

{

gfc_ref *ref;

gfc_array_spec *as;

+ ar_type type = AR_UNKNOWN;

int d;

if (array->ts.type == BT_CLASS)

@@ -4180,6 +4181,7 @@ simplify_bound (gfc_expr *array, gfc_expr *dim,

gfc_expr *kind, int upper)

switch (ref->type)

{

case REF_ARRAY:

+ type = ref->u.ar.type;

switch (ref->u.ar.type)

{

case AR_ELEMENT:

@@ -4233,7 +4235,10 @@ simplify_bound (gfc_expr *array, gfc_expr *dim,

gfc_expr *kind, int upper)

int k;

/* UBOUND(ARRAY) is not valid for an assumed-size array. */

- if (upper && as && as->type == AS_ASSUMED_SIZE)

+ if (upper

+ && type == AR_FULL

+ && as

+ && as->type == AS_ASSUMED_SIZE)

{

/* An error message will be emitted in

check_assumed_size_reference (resolve.c). */

diff --git a/gcc/testsuite/gfortran.dg/PR90350.f90

b/gcc/testsuite/gfortran.dg/PR90350.f90

new file mode 100644

index 0000000..2e2cf10

--- /dev/null

+++ b/gcc/testsuite/gfortran.dg/PR90350.f90

@@ -0,0 +1,19 @@

+! { dg-do compile }

+!

+! Test the fix for PR90350

+!

+! Contributed by <

[hidden email]>

+!

+

+program artificial

+implicit none

+integer :: arr(-10:10)

+ call asub(arr,size(arr))

+end program artificial

+subroutine asub(arr,n)

+integer,intent(in) :: arr(*)

+integer,intent(in) :: n

+ write(*,*)'UPPER=',ubound(arr(:n))

+ write(*,*)'LOWER=',lbound(arr(:n))

+ write(*,*)'SIZE=',size(arr(:n))

+end subroutine asub