Hi,
I stumbled across a segfault in the algol68 compiler when it encounters
an invalid module syntax.
After seeing a `module' symbol token, the parser skips over the contents
of the module until it finds the terminating `fed' symbol token, then
moves forward to the next token to scan. If instead the parser reaches
the end of file, then skip_module_text returns NULL, triggering an ICE
in the call to FORWARD.
Ran the compiler testsuite and didn't observe any regressions.
OK?
Regards,
Iain.
---
gcc/algol68/ChangeLog:
* a68-parser-extract.cc (a68_extract_indicants): Don't call FORWARD if
skip_module_text returns NO_NODE.
gcc/testsuite/ChangeLog:
* algol68/compile/error-module-definition-1.a68: New test.
* algol68/compile/error-module-definition-2.a68: New test.
---
gcc/algol68/a68-parser-extract.cc | 4 ++--
gcc/testsuite/algol68/compile/error-module-definition-1.a68 | 1 +
gcc/testsuite/algol68/compile/error-module-definition-2.a68 | 3 +++
3 files changed, 6 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/algol68/compile/error-module-definition-1.a68
create mode 100644 gcc/testsuite/algol68/compile/error-module-definition-2.a68
diff --git a/gcc/algol68/a68-parser-extract.cc
b/gcc/algol68/a68-parser-extract.cc
index 32a9933bd72..92a1e676012 100644
--- a/gcc/algol68/a68-parser-extract.cc
+++ b/gcc/algol68/a68-parser-extract.cc
@@ -415,8 +415,8 @@ a68_extract_indicants (NODE_T *p)
}
else
{
- q = skip_module_text (NEXT (q));
- FORWARD (q);
+ if ((q = skip_module_text (NEXT (q))) != NO_NODE)
+ FORWARD (q);
}
}
else
diff --git a/gcc/testsuite/algol68/compile/error-module-definition-1.a68
b/gcc/testsuite/algol68/compile/error-module-definition-1.a68
new file mode 100644
index 00000000000..bc763bd682b
--- /dev/null
+++ b/gcc/testsuite/algol68/compile/error-module-definition-1.a68
@@ -0,0 +1 @@
+module Module = { dg-error "" }
diff --git a/gcc/testsuite/algol68/compile/error-module-definition-2.a68
b/gcc/testsuite/algol68/compile/error-module-definition-2.a68
new file mode 100644
index 00000000000..d2ad87b5d6c
--- /dev/null
+++ b/gcc/testsuite/algol68/compile/error-module-definition-2.a68
@@ -0,0 +1,3 @@
+module Module = { dg-error "" }
+begin
+end
--
2.43.0