Fix c/69522, memory management issue in c-parser

Bernd Schmidt bschmidt@redhat.com
Fri Jan 29 11:40:00 GMT 2016


Let's say we have

struct a {
  int x[1];
  int y[1];
} x = { 0, { 0 } };
            ^

When we reach the marked brace, we call into push_init_level, where we 
notice that we have implicit initializers (for x[]) lying around that we 
should deal with now that we've seen another open brace. The problem is 
that we've created a new obstack for the initializer of y, and this is 
where we also put data for the inits of x, freeing it when we see the 
close brace for the initialization of y.

In the actual testcase, which is a little more complex to actually 
demonstrate the issue, we end up allocating two init elts at the same 
address (because of premature freeing) and place them in the same tree, 
which ends up containing a cycle because of this. Then we hang.

Fixed by this patch, which splits off a new function 
finish_implicit_inits from push_init_level and ensures it's called with 
the outer obstack instead of the new one in the problematic case.

Bootstrapped and tested on x86_64-linux, ok?


Bernd
-------------- next part --------------
A non-text attachment was scrubbed...
Name: braced-init.diff
Type: text/x-patch
Size: 7100 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20160129/976cc1dd/attachment.bin>


More information about the Gcc-patches mailing list