[PATCH] A new HeapToStack allocation promotion pass
David Tweed
david.tweed at arm.com
Tue Sep 24 07:04:07 PDT 2013
Hi,
|This should work correctly because it is testing the variables in SSA form. Your example is really:
|int* p = malloc(<blah>);
|<blah>
|if (not_big_enough) {
| q = realloc(p,<blah>);
|}
|<blah>
|r = phi(p, q)
|free(r);
|and there is not a free of p on every path out of the function.
Thanks for clarifying that. That's the only case of a standard library function I can think of that is intended to be used to potentially "re-point" a pointer
that otherwise has a within-function scope. I can't immediately see how a function along the lines of
hidden_realloc_ptr(int** p,int n) { free(*p); *p=malloc(n); }
used in place of the realloc() call above as
hidden_realloc_pointer(&p,<blah>)
would fare, but if that's handled without generating incorrect code then I think then the only snag I could think of isn't a problem.
Cheers,
Dave
More information about the llvm-commits
mailing list