This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Don't abort in C++ on bad input
- To: gcc-patches at gcc dot gnu dot org
- Subject: [PATCH] Don't abort in C++ on bad input
- From: Jakub Jelinek <jakub at redhat dot com>
- Date: Fri, 27 Oct 2000 14:54:07 +0200
- Reply-To: Jakub Jelinek <jakub at redhat dot com>
Hi!
The crash24.C testcase below causes cc1plus to crash (depending on whether
tree checking is on either aborts or segfaults).
Is the following patch ok?
I've enclosed crash25.C test too, which fails in Red Hat g++ but seems to be
fixed in the mainline already just in case it breaks ever again.
2000-10-27 Jakub Jelinek <jakub@redhat.com>
* call.c (build_new_op): If argument types are error_mark_nodes, return
error_mark_node.
(build_over_call): If require_complete_type returns error_mark_node,
return it immediately.
* g++.old-deja/g++.other/crash24.C: New test.
* g++.old-deja/g++.other/crash25.C: New test.
--- gcc/cp/call.c.jj Fri Oct 27 13:38:40 2000
+++ gcc/cp/call.c Fri Oct 27 14:36:25 2000
@@ -3204,6 +3204,11 @@ build_new_op (code, flags, arg1, arg2, a
if (arg3 && TREE_CODE (arg3) == OFFSET_REF)
arg3 = resolve_offset_ref (arg3);
+ if (TREE_TYPE (arg1) == error_mark_node
+ || (arg2 && TREE_TYPE (arg2) == error_mark_node)
+ || (arg3 && TREE_TYPE (arg3) == error_mark_node))
+ return error_mark_node;
+
if (code == COND_EXPR)
{
if (arg2 == NULL_TREE
@@ -4192,6 +4197,8 @@ build_over_call (cand, args, flags)
if (TREE_CODE (TREE_TYPE (fn)) == VOID_TYPE)
return fn;
fn = require_complete_type (fn);
+ if (fn == error_mark_node)
+ return error_mark_node;
if (IS_AGGR_TYPE (TREE_TYPE (fn)))
fn = build_cplus_new (TREE_TYPE (fn), fn);
return convert_from_reference (fn);
--- gcc/testsuite/g++.old-deja/g++.other/crash24.C.jj Fri Oct 27 14:46:21 2000
+++ gcc/testsuite/g++.old-deja/g++.other/crash24.C Fri Oct 27 14:45:07 2000
@@ -0,0 +1,18 @@
+//Build don't link:
+
+#include <iostream>
+
+class foo {
+ public:
+ class __iterator;
+ friend class __iterator;
+ typedef __iterator const_iterator;
+ virtual ~foo() { }
+ __iterator begin(); // ERROR -
+};
+static void iteratorTest(const foo &x)
+{
+ foo::const_iterator i = x.begin(); // ERROR -
+ for (; i; ++i) // ERROR -
+ cout << *i;
+}
--- gcc/testsuite/g++.old-deja/g++.other/crash25.C.jj Fri Oct 27 14:46:25 2000
+++ gcc/testsuite/g++.old-deja/g++.other/crash25.C Wed Oct 25 14:14:19 2000
@@ -0,0 +1,15 @@
+// Build don't link:
+
+class X {
+public:
+ X();
+ virtual ~X();
+}
+
+X::x()
+{ // ERROR -
+}
+
+X::~x()
+{ // ERROR -
+}
Jakub