libgfortran/ChangeLog:
[official-gcc.git] / gcc / testsuite / gcc.dg / builtins-13.c
blob149407b5406f68c06346722cd5ab1c04c9baad24
1 /* Copyright (C) 2003 Free Software Foundation.
3 Verify that the malloc-like __builtin_ allocation functions are
4 correctly aliased by the compiler.
6 Written by Roger Sayle, 12th April 2003. */
8 /* { dg-do link } */
9 /* { dg-options "-ansi" } */
11 typedef __SIZE_TYPE__ size_t;
13 extern void abort (void);
14 extern void *malloc (size_t);
15 extern void *calloc (size_t,size_t);
17 extern void link_error (void);
19 static int x;
21 void test1(void)
23 int *ptr1, *ptr2;
25 ptr1 = &x;
26 ptr2 = (int*) malloc (sizeof (int));
28 *ptr1 = 12;
29 *ptr2 = 8;
31 if (*ptr1 != 12)
32 link_error();
35 void test2(void)
37 int *ptr1, *ptr2;
39 ptr1 = &x;
40 ptr2 = (int*) calloc (1, sizeof (int));
42 *ptr1 = 12;
43 *ptr2 = 8;
45 if (*ptr1 != 12)
46 link_error ();
49 int main()
51 test1 ();
52 test2 ();
53 return 0;
56 #ifndef __OPTIMIZE__
57 void link_error (void)
59 abort ();
61 #endif