OSDN Git Service

2004-05-20 H.J. Lu <hongjiu.lu@intel.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / builtins-13.c
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
10 typedef __SIZE_TYPE__ size_t;
11
12 extern void abort (void);
13 extern void *malloc (size_t);
14 extern void *calloc (size_t,size_t);
15
16 extern void link_error (void);
17
18 static int x;
19
20 void test1(void)
21 {
22   int *ptr1, *ptr2;
23
24   ptr1 = &x;
25   ptr2 = (int*) malloc (sizeof (int));
26
27   *ptr1 = 12;
28   *ptr2 = 8;
29
30   if (*ptr1 != 12)
31     link_error();
32 }
33
34 void test2(void)
35 {
36   int *ptr1, *ptr2;
37
38   ptr1 = &x;
39   ptr2 = (int*) calloc (1, sizeof (int));
40
41   *ptr1 = 12;
42   *ptr2 = 8;
43
44   if (*ptr1 != 12)
45     link_error ();
46 }
47
48 int main()
49 {
50   test1 ();
51   test2 ();
52   return 0;
53 }
54
55 #ifndef __OPTIMIZE__
56 void link_error (void)
57 {
58   abort ();
59 }
60 #endif
61