void test4(int b) { int *p = __builtin_malloc (sizeof (int) * 4); if (b) __builtin_free (p); *p = 5; __builtin_free (p); }
int main () { /* Heap allocated memory. */ char *p = (char *)__builtin_malloc (42); int r = foo (p); __builtin_free (p); p = (char *)__builtin_malloc (1024); bar (p, p + 1024); bar (p + 1024, p + 1023); bar (p + 1, p + 1023); __builtin_free (p); p = (char *)__builtin_malloc (4096); bar (p, p + 4096); bar (p + 10, p + 100); bar (p + 1024, p + 4096); bar (p + 4095, p + 4096); bar (p + 4095, p + 4094); bar (p + 100, p + 4096); bar (p + 100, p + 4094); __builtin_free (p); /* Global variable. */ bar (&global[0], &global[1]); bar (&global[1], &global[2]); bar (&global[2], &global[1]); bar (&global[0], &global[100]); bar (&global[1000], &global[7000]); bar (&global[500], &global[10]); p = &global[0]; bar (p, p + 8192); p = &global[8000]; bar (p, p + 192); p = &small_global[0]; bar (p, p + 1); bar (p, p + 7); bar (p + 7, p + 1); bar (p + 6, p + 7); bar (p + 7, p + 7); /* Stack variable. */ char stack[10000]; bar (&stack[0], &stack[100]); bar (&stack[1000], &stack[9000]); bar (&stack[500], &stack[10]); baz (0, &stack[10]); return 0; }
void test2(void) { int *p = __builtin_malloc (sizeof (int) * 4); if (p == (void *)0) __builtin_abort (); __builtin_free (p); }
void test1(void) { int *p = __builtin_malloc (sizeof (int) * 4); int *q = p; *q++ = 4; *q++ = 4; __builtin_free (p); }
void foo(int n) { int * f = (int*) __builtin_malloc (n * sizeof (int)); int * ff = (int*) __builtin_malloc (n * sizeof (int)); int i; for (i = 0; i < n; ++i) { f[i] = 1; ff[i] = 2; if (f[i] != 1) link_error (); if (ff[i] != 2) link_error (); } __builtin_free (f); __builtin_free (ff); }
__attribute__((noinline, noclone)) void f1 (int i) { volatile int j; struct S s; s.p = (char *) __builtin_calloc (N, 1); j = s.p[i]; j = *(s.p + i); __builtin_free (s.p); }
int main () { volatile double d = 0.0; double *p = __builtin_calloc (1, sizeof (double)); d += 1.0; *p += 2.0; __builtin_free (p); return 0; }
int main () { struct S *p = __builtin_malloc (sizeof (struct S) + 16); if (p) { p->a = 1; __builtin_strcpy (p->b, "abcdefg"); if (foo (p) != 7 || bar (p) != 7) __builtin_abort (); __builtin_free (p); } return 0; }
void h(){ char*p=__builtin_malloc(42); g=__builtin_memset(p,3,10); __builtin_free(p); }
// C++14 sized deallocation function inline void operator delete(void *p, __SIZE_TYPE__) { __builtin_free(p); }
inline void operator delete(void *p) { __builtin_free(p); }
void test5(int b) { int *p = __builtin_malloc (sizeof (int) * 4); if (p) __builtin_free (p); }