This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/18602] segfault on a huge switch statement.
- From: "dj at redhat dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 22 Nov 2004 21:36:38 -0000
- Subject: [Bug c/18602] segfault on a huge switch statement.
- References: <20041121231617.18602.kazu@cs.umass.edu>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From dj at redhat dot com 2004-11-22 21:36 -------
Subject: Re: segfault on a huge switch statement.
> Confirmed, the problem is because of stack overflow. Either
> splay_tree_delete_helper needs a little help or the C/C++ front-end
> needs to stop using splay trees.
How about this?
/* Deallocate NODE (a member of SP), and all its sub-trees. */
static void
splay_tree_delete_helper (sp, node)
splay_tree sp;
splay_tree_node node;
{
splay_tree_node pending = 0;
splay_tree_node active = 0;
if (!node)
return;
#define KDEL(x) if (sp->delete_key) (*sp->delete_key)(x);
#define VDEL(x) if (sp->delete_value) (*sp->delete_value)(x);
KDEL (node->key);
VDEL (node->value);
/* We use the "key" field to hold the "next" pointer. */
node->key = (splay_tree_key)pending;
pending = (splay_tree_node)node;
/* Now, keep processing the pending list until there aren't any
more. This is a little more complicated than just recursing, but
it doesn't toast the stack for large trees. */
while (pending)
{
active = pending;
pending = 0;
while (active)
{
splay_tree_node temp;
/* active points to a node which has its key and value
deallocated, we just need to process left and right. */
if (active->left)
{
KDEL (active->left->key);
VDEL (active->left->value);
active->left->key = (splay_tree_key)pending;
pending = (splay_tree_node)(active->left);
}
if (active->right)
{
KDEL (active->right->key);
VDEL (active->right->value);
active->right->key = (splay_tree_key)pending;
pending = (splay_tree_node)(active->right);
}
temp = active;
active = (splay_tree_node)(temp->key);
(*sp->deallocate) ((char*) temp, sp->allocate_data);
}
}
#undef KDEL
#undef VDEL
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18602