[PATCH] A new HeapToStack allocation promotion pass

Hal Finkel hfinkel at anl.gov
Sat Oct 5 13:30:58 PDT 2013


----- Stephen Checkoway <s at pahtak.org> wrote:
> 
> On Oct 2, 2013, at 10:31 AM, hfinkel at anl.gov wrote:
> 
> > This is an updated implementation, with a few major changes:
> 
> 
> Hi Hal,
> 
> In addition to not working with standard library functions that except things in the heap (malloc_usable_size, mallinfo) as I mentioned previously, it also doesn't work if the allocated memory escapes via exceptions (I think someone else mentioned that previously).

Yep, Nick also pointed this out; thanks for confirming!

I'll work up a more conservative version and post it soon.

 -Hal


> 
> Here's an example:
> 
> #include <stdlib.h>
> 
> static __attribute__((noinline)) void bar(int *p, int a)
> {
> *p = a;
> if (a > 1)
> throw p;
> }
> 
> static __attribute__((noinline)) void foo(int a)
> {
> int *p = (int *)malloc(sizeof(int));
> bar(p, a);
> free(p);
> }
> 
> int main(int argc, char *argv[])
> {
> try
> {
> foo(argc);
> }
> catch (int *p)
> {
> free(p);
> }
> return 0;
> }
> 
> [secdev:~/m] s$ ../build-master/bin/clang++ b.cc -O3
> [secdev:~/m] s$ ./a.out 1 2 3 4
> *** Error in `./a.out': free(): invalid pointer: 0x00007fff10617a70 ***
> 
> -- 
> Stephen Checkoway
> 
> 
> 
> 
> 

-- 
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory



More information about the llvm-commits mailing list