[COMMITTED] algol68: introduce _libga68_unreachable and use it in unions
Jose E. Marchesi
jemarch@gnu.org
Sat Mar 15 19:44:48 GMT 2025
---
gcc/algol68/a68-low-coercions.cc | 14 +++++++++++++-
gcc/algol68/a68-low-runtime.def | 5 +++--
libga68/ga68-error.c | 9 +++++++++
libga68/ga68.h | 1 +
4 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/gcc/algol68/a68-low-coercions.cc b/gcc/algol68/a68-low-coercions.cc
index 4464397784c..b9e1acee9ce 100644
--- a/gcc/algol68/a68-low-coercions.cc
+++ b/gcc/algol68/a68-low-coercions.cc
@@ -115,7 +115,19 @@ a68_lower_uniting (NODE_T *p, LOW_CTX_T ctx)
field_index += 1;
}
- // XXX emit run-time error: this should not be reached.
+ /* This should not be reached. Emit run-time error. */
+ {
+ unsigned int lineno = NUMBER (LINE (INFO (p)));
+ const char *filename_str = FILENAME (LINE (INFO (p)));
+ tree filename = build_string_literal (strlen (filename_str) + 1,
+ filename_str);
+ tree call = a68_build_libcall (A68_LIBCALL_UNREACHABLE,
+ void_type_node, 2,
+ filename,
+ build_int_cst (unsigned_type_node, lineno));
+ a68_add_stmt (call);
+ }
+
a68_add_stmt (build1 (LABEL_EXPR, void_type_node, done_label));
a68_add_stmt (rows);
return a68_pop_range ();
diff --git a/gcc/algol68/a68-low-runtime.def b/gcc/algol68/a68-low-runtime.def
index 443884425c5..86c85e28bc4 100644
--- a/gcc/algol68/a68-low-runtime.def
+++ b/gcc/algol68/a68-low-runtime.def
@@ -41,8 +41,9 @@ along with GCC; see the file COPYING3. If not see
DEF_A68_RUNTIME (ASSERT, "_libga68_assert", RT(VOID), P2(CONSTCHARPTR, UINT), ECF_NORETURN)
DEF_A68_RUNTIME (MALLOC, "_libga68_malloc", RT(VOIDPTR), P1(SIZE), ECF_NOTHROW | ECF_LEAF)
-DEF_A68_RUNTIME (DEREFNIL, "_libga68_derefnil", RT(VOID), P2(CONSTCHARPTR, UINT), 0)
-DEF_A68_RUNTIME (BITSBOUNDSERROR, "_libga68_bitsboundserror", RT(VOID), P3(CONSTCHARPTR,UINT,INT), 0)
+DEF_A68_RUNTIME (DEREFNIL, "_libga68_derefnil", RT(VOID), P2(CONSTCHARPTR, UINT), ECF_NORETURN)
+DEF_A68_RUNTIME (UNREACHABLE, "_libga68_unreachable", RT(VOID), P2(CONSTCHARPTR, UINT), ECF_NORETURN)
+DEF_A68_RUNTIME (BITSBOUNDSERROR, "_libga68_bitsboundserror", RT(VOID), P3(CONSTCHARPTR,UINT,INT), ECF_NORETURN)
DEF_A68_RUNTIME (ARRAYBOUNDS, "_libga68_bounds", RT(VOID),
P5(CONSTCHARPTR, UINT, INT, INT, INT), ECF_NORETURN)
DEF_A68_RUNTIME (RANDOM, "_libga68_random", RT(FLOAT), P0(), 0)
diff --git a/libga68/ga68-error.c b/libga68/ga68-error.c
index 9cee47e3c0d..317d99fdf4d 100644
--- a/libga68/ga68-error.c
+++ b/libga68/ga68-error.c
@@ -66,6 +66,15 @@ _libga68_bitsboundserror (const char *filename, unsigned int lineno,
pos, filename, lineno);
}
+/* Unreachable error. */
+
+void
+_libga68_unreachable (const char *filename, unsigned int lineno)
+{
+ _libga68_abort ("run-time error: unreachable reached at %s:%d\n",
+ filename, lineno);
+}
+
/* Bounds failure. */
void
diff --git a/libga68/ga68.h b/libga68/ga68.h
index 41657b8321a..076787b722a 100644
--- a/libga68/ga68.h
+++ b/libga68/ga68.h
@@ -38,6 +38,7 @@ void _libga68_assert (const char *filename, unsigned int lineno);
void _libga68_derefnil (const char *filename, unsigned int lineno);
void _libga68_bitsboundserror (const char *filename, unsigned int lineno,
ssize_t pos);
+void _libga68_unreachable (const char *filename, unsigned int lineno);
void _libga68_bounds (const char *filename, unsigned int lineno,
ssize_t index, ssize_t lower_bound, ssize_t upper_bound);
--
2.30.2
More information about the Algol68
mailing list