[PATCH] A new HeapToStack allocation promotion pass
Renato Golin
renato.golin at linaro.org
Mon Oct 7 01:01:38 PDT 2013
On 5 October 2013 23:29, Hal Finkel <hfinkel at anl.gov> wrote:
> 2. A function that we call may throw, longjmp, etc. making the code after
> it potentially unreachable. This affects the 'free on all exit paths'
> condition. So we need to way to recognize safe functions in this regard
> (maybe 'always_returns'?).
>
Hi Hal,
It's not that the code is unreachable (which could be fixed by freeing on
all accessible landing pads), it's that people may use the fact that it's
unreachable as a feature.
void check() {
if (IamSilly)
throw();
}
void prepare(void *p) {
p = malloc(whatever);
...
check();
...
free(p);
}
void stuff(void *p) {
if (p)
use(p);
}
void cleanup(void *p) {
if (p)
free(p);
}
If you add frees to the landing pads as a safety mechanism, stuff(p); won't
work as "expected". I have seen a lot of code that uses exception handling
as control-flow mechanism, and they would probably all fail if you try to
be smart around a throw.
cheers,
--renato
PS: Not that I don't want them to fail, but...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131007/93a7283e/attachment.html>
More information about the llvm-commits
mailing list