public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH, committed] Fortran: ICE on procedure arguments with non-integer length [PR107707]
Date: Wed, 16 Nov 2022 22:58:18 +0100	[thread overview]
Message-ID: <trinity-f69af5d4-c8de-4af1-94d3-d9f20963f1ef-1668635898373@3c-app-gmx-bap19> (raw)

[-- Attachment #1: Type: text/plain, Size: 302 bytes --]

Dear all,

I've committed the attached patch for Steve after regtesting.
It obviously checks the types of character length to be integer
before passing them to mpz_*.

Pushed as r13-4113-gbdd784fc48a283d54f5f1e3cc2a0668c14dd3bee

Thanks,
Harald

@Steve: please close PR if you think everything is ok.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr107707.diff --]
[-- Type: text/x-patch, Size: 2150 bytes --]

From bdd784fc48a283d54f5f1e3cc2a0668c14dd3bee Mon Sep 17 00:00:00 2001
From: Steve Kargl <kargl@gcc.gnu.org>
Date: Wed, 16 Nov 2022 22:46:55 +0100
Subject: [PATCH] Fortran: ICE on procedure arguments with non-integer length
 [PR107707]

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               |  2 ++
 gcc/testsuite/gfortran.dg/pr107707.f90 | 13 +++++++++++++
 2 files changed, 15 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/pr107707.f90

diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc
index 49dbd1d886c..616ae2b1197 100644
--- a/gcc/fortran/interface.cc
+++ b/gcc/fortran/interface.cc
@@ -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
index 00000000000..a8be2b5b299
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr107707.f90
@@ -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
--
2.35.3


             reply	other threads:[~2022-11-16 21:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-16 21:58 Harald Anlauf [this message]
2022-11-16 22:01 ` Steve Kargl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=trinity-f69af5d4-c8de-4af1-94d3-d9f20963f1ef-1668635898373@3c-app-gmx-bap19 \
    --to=anlauf@gmx.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).