]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: catch invalid kind in character conversion [PR69636,PR103779]
authorHarald Anlauf <anlauf@gmx.de>
Thu, 9 Feb 2023 20:16:14 +0000 (21:16 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Thu, 9 Feb 2023 20:21:06 +0000 (21:21 +0100)
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>
gcc/fortran/intrinsic.cc
gcc/testsuite/gfortran.dg/pr103779.f90 [new file with mode: 0644]

index 68f481473b43dc8aa8bd0981f9437de195a9292f..17ee999c3b9767327e9d3008c0229a6c5a94eff3 100644 (file)
@@ -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 (file)
index 0000000..3d76c90
--- /dev/null
@@ -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" }