public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-3201] Fortran - reject function entries with mismatched characteristics
@ 2021-08-28 18:10 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2021-08-28 18:10 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f9809ef57005409ee658294d6e8dad9ee8897e88

commit r12-3201-gf9809ef57005409ee658294d6e8dad9ee8897e88
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Sat Aug 28 20:09:44 2021 +0200

    Fortran - reject function entries with mismatched characteristics
    
    gcc/fortran/ChangeLog:
    
            PR fortran/87737
            * resolve.c (resolve_entries): For functions of type CHARACTER
            tighten the checks for matching characteristics.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/87737
            * gfortran.dg/entry_24.f90: New test.

Diff:
---
 gcc/fortran/resolve.c                  |  9 +++++++++
 gcc/testsuite/gfortran.dg/entry_24.f90 | 20 ++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 5b9ba43780e..f641d0d4dae 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -804,6 +804,15 @@ resolve_entries (gfc_namespace *ns)
 	     the same string length, i.e. both len=*, or both len=4.
 	     Having both len=<variable> is also possible, but difficult to
 	     check at compile time.  */
+	  else if (ts->type == BT_CHARACTER
+		   && (el->sym->result->attr.allocatable
+		       != ns->entries->sym->result->attr.allocatable))
+	    {
+	      gfc_error ("Function %s at %L has entry %s with mismatched "
+			 "characteristics", ns->entries->sym->name,
+			 &ns->entries->sym->declared_at, el->sym->name);
+	      return;
+	    }
 	  else if (ts->type == BT_CHARACTER && ts->u.cl && fts->u.cl
 		   && (((ts->u.cl->length && !fts->u.cl->length)
 			||(!ts->u.cl->length && fts->u.cl->length))
diff --git a/gcc/testsuite/gfortran.dg/entry_24.f90 b/gcc/testsuite/gfortran.dg/entry_24.f90
new file mode 100644
index 00000000000..9773597f4e1
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/entry_24.f90
@@ -0,0 +1,20 @@
+! { dg-do compile }
+! PR fortran/87737 - improve check on function entry characteristics
+
+function f() ! { dg-error "mismatched characteristics" }
+  character(:), allocatable :: f
+  character(1)              :: g
+  f = 'f'
+  return
+entry g()
+  g = 'g'
+end
+
+function f2() ! { dg-error "mismatched characteristics" }
+  character(1)              :: f2
+  character(1), allocatable :: g2
+  f2 = 'f'
+  return
+entry g2()
+  g2 = 'g'
+end


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-28 18:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-28 18:10 [gcc r12-3201] Fortran - reject function entries with mismatched characteristics Harald Anlauf

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).