[committed] Fortran: catch invalid kind in character conversion [PR69636,PR103779]
Checks
Commit Message
Dear all,
the attached trivial and obvious patch replaces an internal error
on encountering an invalid kind in a character conversion by a
regular error recovery.
Pushed after regtesting on x86_64-pc-linux-gnu as
r13-5760-ga618b45ac41cf480f54c4fa4014aed6218931290
Thanks,
Harald
From a618b45ac41cf480f54c4fa4014aed6218931290 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Thu, 9 Feb 2023 21:16:14 +0100
Subject: [PATCH] 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>
---
gcc/fortran/intrinsic.cc | 3 ++-
gcc/testsuite/gfortran.dg/pr103779.f90 | 18 ++++++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gfortran.dg/pr103779.f90
@@ -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;
new file mode 100644
@@ -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" }
--
2.35.3