1// RUN: %clang_cc1 -emit-llvm %s  -o /dev/null
2
3// Test list stuff
4
5void *malloc(unsigned);
6
7// Test opaque structure support.  the list type is defined later
8struct list;
9
10struct list *PassThroughList(struct list *L) {
11  return L;
12}
13
14
15// Recursive data structure tests...
16
17typedef struct list {
18  int Data;
19  struct list *Next;
20} list;
21
22list *Data;
23
24void foo() {
25  static int Foo = 0;            // Test static local variable
26  Foo += 1;                      // Increment static variable
27
28  Data = (list*)malloc(12);      // This is not a proper list allocation
29}
30
31extern list ListNode1;
32list ListNode3 = { 4, 0          };
33list ListNode2 = { 3, &ListNode3 };
34list ListNode0 = { 1, &ListNode1 };
35list ListNode1 = { 2, &ListNode2 };
36
37
38list ListArray[10];
39
40// Iterative insert fn
41void InsertIntoListTail(list **L, int Data) {
42  while (*L)
43    L = &(*L)->Next;
44  *L = (list*)malloc(sizeof(list));
45  (*L)->Data = Data;
46  (*L)->Next = 0;
47}
48
49// Recursive list search fn
50list *FindData(list *L, int Data) {
51  if (L == 0) return 0;
52  if (L->Data == Data) return L;
53  return FindData(L->Next, Data);
54}
55
56void foundIt(void);
57
58// Driver fn...
59void DoListStuff() {
60  list *MyList = 0;
61  InsertIntoListTail(&MyList, 100);
62  InsertIntoListTail(&MyList, 12);
63  InsertIntoListTail(&MyList, 42);
64  InsertIntoListTail(&MyList, 1123);
65  InsertIntoListTail(&MyList, 1213);
66
67  if (FindData(MyList, 75)) foundIt();
68  if (FindData(MyList, 42)) foundIt();
69  if (FindData(MyList, 700)) foundIt();
70}
71
72