]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: ICE on procedure arguments with non-integer length [PR107707]
authorSteve Kargl <kargl@gcc.gnu.org>
Wed, 16 Nov 2022 21:46:55 +0000 (22:46 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Wed, 16 Nov 2022 21:50:51 +0000 (22:50 +0100)
gcc/fortran/ChangeLog:

PR fortran/107707
* interface.cc (gfc_compare_actual_formal): Check that we actually
have integer values before asking gmp_* to use them.

gcc/testsuite/ChangeLog:

PR fortran/107707
* gfortran.dg/pr107707.f90: New test.

gcc/fortran/interface.cc
gcc/testsuite/gfortran.dg/pr107707.f90 [new file with mode: 0644]

index 49dbd1d886c540356b43dd0ac04b05ca0540f3a0..616ae2b11973ad1db2a9fc9f089a253d3b14444d 100644 (file)
@@ -3273,9 +3273,11 @@ gfc_compare_actual_formal (gfc_actual_arglist **ap, gfc_formal_arglist *formal,
       if (a->expr->ts.type == BT_CHARACTER
          && a->expr->ts.u.cl && a->expr->ts.u.cl->length
          && a->expr->ts.u.cl->length->expr_type == EXPR_CONSTANT
+         && a->expr->ts.u.cl->length->ts.type == BT_INTEGER
          && f->sym->ts.type == BT_CHARACTER && f->sym->ts.u.cl
          && f->sym->ts.u.cl->length
          && f->sym->ts.u.cl->length->expr_type == EXPR_CONSTANT
+         && f->sym->ts.u.cl->length->ts.type == BT_INTEGER
          && (f->sym->attr.pointer || f->sym->attr.allocatable
              || (f->sym->as && f->sym->as->type == AS_ASSUMED_SHAPE))
          && (mpz_cmp (a->expr->ts.u.cl->length->value.integer,
diff --git a/gcc/testsuite/gfortran.dg/pr107707.f90 b/gcc/testsuite/gfortran.dg/pr107707.f90
new file mode 100644 (file)
index 0000000..a8be2b5
--- /dev/null
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! PR fortran/107707 - ICE in gfc_compare_actual_formal
+! Contributed by G.Steinmetz
+
+program p
+  character(3), allocatable :: c
+  c = 'abc'
+  call s(c)
+contains
+  subroutine s(x)
+    character(real(3)), allocatable :: x ! { dg-error "must be of INTEGER type" }
+  end
+end