I encountered a segmentation fault when executing an unrolled version of
20040811-1.c (tested with -O2)
void *volatile p;
int
main (void)
{
int n = 0;
lab:;
{
int x[n % 1000 + 1];
x[0] = 1;
x[n % 1000] = 2;
p = x;
n++;
}
{
int x[n % 1000 + 1];
x[0] = 1;
x[n % 1000] = 2;
p = x;
n++;
}
if (n < 1000000)
goto lab;
return 0;
}
The problem is that the first pair of
__builtin_stack_save/__builtin_satck_restore of the unrolled loop is optimized
out in optimize_stack_restore (tree-ssa-ccp.c) of fab pass. Consequently, the
dynamic memory allocated grows bigger and bigger and causes segfault. The
following is from tst.c.139t.optimized
lab:
saved_stack.1_3 = 0B;
D.2723_4 = n_1 % 1000;
D.2724_5 = D.2723_4 + 1;
D.2728_15 = (long unsigned int) D.2724_5;
D.2730_16 = D.2728_15 * 4;
D.2732_17 = __builtin_alloca (D.2730_16);
x.0_18 = (int[0:D.2727] *) D.2732_17;
(*x.0_18)[0] = 1;
(*x.0_18)[D.2723_4] = 2;
p ={v} x.0_18;
D.2770_66 = (unsigned int) n_1;
D.2771_65 = D.2770_66 + 1;
n_64 = (int) D.2771_65;
GIMPLE_NOP
saved_stack.3_21 = __builtin_stack_save ();
D.2723_22 = n_64 % 1000;
D.2734_23 = D.2723_22 + 1;
D.2738_33 = (long unsigned int) D.2734_23;
D.2740_34 = D.2738_33 * 4;
D.2742_35 = __builtin_alloca (D.2740_34);
x.2_36 = (int[0:D.2737] *) D.2742_35;
(*x.2_36)[0] = 1;
(*x.2_36)[D.2723_22] = 2;
p ={v} x.2_36;
D.2773_62 = D.2770_66 + 2;
n_61 = (int) D.2773_62;
__builtin_stack_restore (saved_stack.3_21);
if (n_61 != 1000000)
goto <bb 3> (lab);
else
goto <bb 4>;
--
Summary: Paritially optimized
__builtin_save_stack/__builtin_restore_stack causes
segmentation fault
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: bmei at broadcom dot com
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43220