diff options
author | Harald Anlauf <anlauf@gmx.de> | 2021-11-06 19:42:01 +0100 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2021-11-06 19:42:01 +0100 |
commit | df2135e88a8f78c853b35246ad426b01b6d08378 (patch) | |
tree | 33e01532cebc6ecabcf0fefa5b39e6d6ecc4a8cf | |
parent | 6b8152b96c114f038d2ef3fc753593c414b8cdb6 (diff) | |
download | gcc-df2135e88a8f78c853b35246ad426b01b6d08378.zip gcc-df2135e88a8f78c853b35246ad426b01b6d08378.tar.gz gcc-df2135e88a8f78c853b35246ad426b01b6d08378.tar.bz2 |
Fortran: error recovery on rank mismatch of array and its initializer
gcc/fortran/ChangeLog:
PR fortran/102715
* decl.c (add_init_expr_to_sym): Reject rank mismatch between
array and its initializer.
gcc/testsuite/ChangeLog:
PR fortran/102715
* gfortran.dg/pr68019.f90: Adjust error message.
* gfortran.dg/pr102715.f90: New test.
-rw-r--r-- | gcc/fortran/decl.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/pr102715.f90 | 13 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/pr68019.f90 | 2 |
3 files changed, 22 insertions, 1 deletions
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index ab88ab5..c0fec90 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -2105,6 +2105,14 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus) } } + if (sym->attr.flavor == FL_PARAMETER && sym->attr.dimension && sym->as + && sym->as->rank && init->rank && init->rank != sym->as->rank) + { + gfc_error ("Rank mismatch of array at %L and its initializer " + "(%d/%d)", &sym->declared_at, sym->as->rank, init->rank); + return false; + } + /* If sym is implied-shape, set its upper bounds from init. */ if (sym->attr.flavor == FL_PARAMETER && sym->attr.dimension && sym->as->type == AS_IMPLIED_SHAPE) diff --git a/gcc/testsuite/gfortran.dg/pr102715.f90 b/gcc/testsuite/gfortran.dg/pr102715.f90 new file mode 100644 index 0000000..7b29a1c --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr102715.f90 @@ -0,0 +1,13 @@ +! { dg-do compile } +! PR fortran/102715 - ICE in gfc_simplify_transpose + +program p + type t + end type + type(t), parameter :: a(4) = t() + type(t), parameter :: b(2,2) = reshape(a, [2]) ! { dg-error "Rank mismatch" } + type(t), parameter :: c(2,2) = transpose(b) ! { dg-error "must be of rank 2" } + type(t), parameter :: s2(*) = b(2,:) ! { dg-error "Syntax error" } + type(t), parameter :: x(*,*) = reshape(a, [2]) ! { dg-error "Rank mismatch" } + type(t), parameter :: s3(*) = x(2,:) ! { dg-error "Syntax error" } +end diff --git a/gcc/testsuite/gfortran.dg/pr68019.f90 b/gcc/testsuite/gfortran.dg/pr68019.f90 index 2e304c3..77fd55b 100644 --- a/gcc/testsuite/gfortran.dg/pr68019.f90 +++ b/gcc/testsuite/gfortran.dg/pr68019.f90 @@ -9,5 +9,5 @@ program p integer :: n end type type(t), parameter :: vec(*) = [(t(i), i = 1, 4)] - type(t), parameter :: arr(*) = reshape(vec, [2, 2]) ! { dg-error "ranks 1 and 2 in assignment" } + type(t), parameter :: arr(*) = reshape(vec, [2, 2]) ! { dg-error "Rank mismatch" } end |