public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-5760] Fortran: catch invalid kind in character conversion [PR69636, PR103779]
@ 2023-02-09 20:22 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2023-02-09 20:22 UTC (permalink / raw)
  To: gcc-cvs

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

commit r13-5760-ga618b45ac41cf480f54c4fa4014aed6218931290
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Thu Feb 9 21:16:14 2023 +0100

    Fortran: catch invalid kind in character conversion [PR69636,PR103779]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/69636
            PR fortran/103779
            * intrinsic.cc (gfc_convert_chartype): Recover on invalid character
            kind in conversion instead of generating an internal error.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/69636
            PR fortran/103779
            * gfortran.dg/pr103779.f90: New test.
    
    Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>

Diff:
---
 gcc/fortran/intrinsic.cc               |  3 ++-
 gcc/testsuite/gfortran.dg/pr103779.f90 | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/intrinsic.cc b/gcc/fortran/intrinsic.cc
index 68f481473b4..17ee999c3b9 100644
--- a/gcc/fortran/intrinsic.cc
+++ b/gcc/fortran/intrinsic.cc
@@ -5419,7 +5419,8 @@ gfc_convert_chartype (gfc_expr *expr, gfc_typespec *ts)
   gcc_assert (expr->ts.type == BT_CHARACTER && ts->type == BT_CHARACTER);
 
   sym = find_char_conv (&expr->ts, ts);
-  gcc_assert (sym);
+  if (sym == NULL)
+    return false;
 
   /* Insert a pre-resolved function call to the right function.  */
   old_where = expr->where;
diff --git a/gcc/testsuite/gfortran.dg/pr103779.f90 b/gcc/testsuite/gfortran.dg/pr103779.f90
new file mode 100644
index 00000000000..3d76c901e75
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr103779.f90
@@ -0,0 +1,18 @@
+! { dg-do compile }
+! PR fortran/69636
+! PR fortran/103779
+! Contributed by G.Steinmetz
+
+character(1,) function f() ! { dg-error "Expected initialization expression" }
+  f = 'a'
+end
+
+character(1,kind=) function g() ! { dg-error "Expected initialization expression" }
+  g = 'a'
+end
+
+character(1,n) function h() ! { dg-error "has not been declared" }
+  h = 'a'
+end
+
+! { dg-prune-output "Bad kind expression" }

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

only message in thread, other threads:[~2023-02-09 20:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-09 20:22 [gcc r13-5760] Fortran: catch invalid kind in character conversion [PR69636, PR103779] 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).