From 134c2de3336b55561bb73a743dd5368ffef71716 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 24 Jan 2008 16:13:17 +0100 Subject: [PATCH] re PR middle-end/34934 (-O1 crash compile *** glibc detected *** /usr/lib/gcc/i486-linux-gnu/4.2.3/cc1: double free or corruption (!prev)) PR middle-end/34934 * tree-stdarg.c (reachable_at_most_once): Use VEC vector instead of a fixed vector for stack. * gcc.c-torture/compile/20080124-1.c: New test. From-SVN: r131780 --- gcc/ChangeLog | 6 +++ gcc/testsuite/ChangeLog | 5 ++ .../gcc.c-torture/compile/20080124-1.c | 52 +++++++++++++++++++ gcc/tree-stdarg.c | 20 +++---- 4 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/20080124-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9845a3dd17c..b4668e752ff 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2008-01-24 Jakub Jakub Jelinek + + PR middle-end/34934 + * tree-stdarg.c (reachable_at_most_once): Use VEC vector instead of + a fixed vector for stack. + 2008-01-24 Ben Elliston PR c++/25701 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ce0ce9a0412..899cfdca808 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-01-24 Jakub Jakub Jelinek + + PR middle-end/34934 + * gcc.c-torture/compile/20080124-1.c: New test. + 2008-01-24 Paul Thomas PR fortran/34872 diff --git a/gcc/testsuite/gcc.c-torture/compile/20080124-1.c b/gcc/testsuite/gcc.c-torture/compile/20080124-1.c new file mode 100644 index 00000000000..a20937c294e --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/20080124-1.c @@ -0,0 +1,52 @@ +/* PR middle-end/34934 */ + +#include + +typedef struct +{ + int e[1024]; + int f; +} S; + +void foo (long *, va_list); + +void +bar (long *x, S *y, int z, ...) +{ + int i, j; + va_list ap; + va_start (ap, z); + for (j = y->e[i = 1]; i <= y->f; j = y->e[++i]) + { + switch (z) + { + case 1: + if (!(*x & 0x00000020)) + continue; + case 3: + if (!(*x & 0x00000080)) + continue; + case 9: + if (!(*x & 0x04000000)) + continue; + case 4: + if (!(*x & 0x00000200)) + continue; + case 8: + if (!(*x & 0x00100000)) + continue; + case 6: + if (!(*x & 0x00000100)) + continue; + case 7: + if (!(*x & 0x00040000)) + continue; + case 10: + if (!(*x & 0x00000020) + && ((*x & 0x00008000) || (*x & 0x08000000))) + continue; + } + foo (x, ap); + } + va_end (ap); +} diff --git a/gcc/tree-stdarg.c b/gcc/tree-stdarg.c index 168bd2f1564..8df09ec4979 100644 --- a/gcc/tree-stdarg.c +++ b/gcc/tree-stdarg.c @@ -1,5 +1,5 @@ /* Pass computing data for optimizing stdarg functions. - Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. Contributed by Jakub Jelinek This file is part of GCC. @@ -46,9 +46,9 @@ along with GCC; see the file COPYING3. If not see static bool reachable_at_most_once (basic_block va_arg_bb, basic_block va_start_bb) { - edge *stack, e; + VEC (edge, heap) *stack = NULL; + edge e; edge_iterator ei; - int sp; sbitmap visited; bool ret; @@ -58,22 +58,18 @@ reachable_at_most_once (basic_block va_arg_bb, basic_block va_start_bb) if (! dominated_by_p (CDI_DOMINATORS, va_arg_bb, va_start_bb)) return false; - stack = XNEWVEC (edge, n_basic_blocks + 1); - sp = 0; - visited = sbitmap_alloc (last_basic_block); sbitmap_zero (visited); ret = true; FOR_EACH_EDGE (e, ei, va_arg_bb->preds) - stack[sp++] = e; + VEC_safe_push (edge, heap, stack, e); - while (sp) + while (! VEC_empty (edge, stack)) { basic_block src; - --sp; - e = stack[sp]; + e = VEC_pop (edge, stack); src = e->src; if (e->flags & EDGE_COMPLEX) @@ -98,11 +94,11 @@ reachable_at_most_once (basic_block va_arg_bb, basic_block va_start_bb) { SET_BIT (visited, src->index); FOR_EACH_EDGE (e, ei, src->preds) - stack[sp++] = e; + VEC_safe_push (edge, heap, stack, e); } } - free (stack); + VEC_free (edge, heap, stack); sbitmap_free (visited); return ret; }