[PATCH] PR c++/30659 segfault w/ invalid input

Seongbae Park seongbae.park@gmail.com
Tue Feb 6 17:10:00 GMT 2007


On 06 Feb 2007 07:50:08 -0800, Ian Lance Taylor <iant@google.com> wrote:
> "Seongbae Park" <seongbae.park@gmail.com> writes:
>
> > This patch fixes the compiler segmentation fault on an invalid input.
> > Bootstrapped and regtested on i686-linux.
> > As I have never looked at c+ frontend before,
> > there's a high chance I'm not doing the right thing.
> > OK for mainline ?
> >
> > 2007-02-05  Seongbae Park <seongbae.park@gmail.com>
> >
> >         PR c++/30659
> >         * search.c (lookup_member): Return error_mark_node on NULL basetype.
>
> It would be appropriate to add the test case to the testsuite as part
> of this patch.

The new patch with the testsuite is attached.

> (I can't approve this patch, but looking at it I wonder if should be
> catching a NULL basetype earlier.)

I wondered about that as well. The NULL xbasetype comes from
DECL_CONTEXT of a decl, and I couldn't quite figure out
whether this is allowed or not and I didn't try to trace back
where it is coming from - and thought it's easier to ask :)
I'm willing to hunt down deeper if that's the right thing to do.
-- 
#pragma ident "Seongbae Park, compiler, http://seongbae.blogspot.com"
-------------- next part --------------
Index: testsuite/g++.dg/other/pr30659.C
===================================================================
--- testsuite/g++.dg/other/pr30659.C	(revision 0)
+++ testsuite/g++.dg/other/pr30659.C	(revision 0)
@@ -0,0 +1,5 @@
+
+// Test to make sure we do not ICE on this invalid program.
+
+extern "C" { 
+  extern template basic_istream<char>& operator>>(basic_istream<char>&, string&); // { dg-error "" }
Index: cp/search.c
===================================================================
--- cp/search.c	(revision 121630)
+++ cp/search.c	(working copy)
@@ -1202,6 +1202,9 @@ lookup_member (tree xbasetype, tree name
 
   gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
 
+  if (xbasetype == NULL_TREE)
+    return error_mark_node;
+
   if (TREE_CODE (xbasetype) == TREE_BINFO)
     {
       type = BINFO_TYPE (xbasetype);


More information about the Gcc-patches mailing list