[PATCH] A new HeapToStack allocation promotion pass

Stephen Checkoway s at pahtak.org
Sat Oct 5 13:03:49 PDT 2013


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).

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









More information about the llvm-commits mailing list