| 1 |
/* Copyright (C) 2003 Free Software Foundation. |
| 2 |
|
| 3 |
Verify that the malloc-like __builtin_ allocation functions are |
| 4 |
correctly aliased by the compiler. |
| 5 |
|
| 6 |
Written by Roger Sayle, 12th April 2003. */ |
| 7 |
|
| 8 |
/* { dg-do link } */ |
| 9 |
/* { dg-options "-ansi" } */ |
| 10 |
|
| 11 |
typedef __SIZE_TYPE__ size_t; |
| 12 |
|
| 13 |
extern void abort (void); |
| 14 |
extern void *malloc (size_t); |
| 15 |
extern void *calloc (size_t,size_t); |
| 16 |
|
| 17 |
extern void link_error (void); |
| 18 |
|
| 19 |
static int x; |
| 20 |
|
| 21 |
void test1(void) |
| 22 |
{ |
| 23 |
int *ptr1, *ptr2; |
| 24 |
|
| 25 |
ptr1 = &x; |
| 26 |
ptr2 = (int*) malloc (sizeof (int)); |
| 27 |
|
| 28 |
*ptr1 = 12; |
| 29 |
*ptr2 = 8; |
| 30 |
|
| 31 |
if (*ptr1 != 12) |
| 32 |
link_error(); |
| 33 |
} |
| 34 |
|
| 35 |
void test2(void) |
| 36 |
{ |
| 37 |
int *ptr1, *ptr2; |
| 38 |
|
| 39 |
ptr1 = &x; |
| 40 |
ptr2 = (int*) calloc (1, sizeof (int)); |
| 41 |
|
| 42 |
*ptr1 = 12; |
| 43 |
*ptr2 = 8; |
| 44 |
|
| 45 |
if (*ptr1 != 12) |
| 46 |
link_error (); |
| 47 |
} |
| 48 |
|
| 49 |
int main() |
| 50 |
{ |
| 51 |
test1 (); |
| 52 |
test2 (); |
| 53 |
return 0; |
| 54 |
} |
| 55 |
|
| 56 |
#ifndef __OPTIMIZE__ |
| 57 |
void link_error (void) |
| 58 |
{ |
| 59 |
abort (); |
| 60 |
} |
| 61 |
#endif |
| 62 |
|