1 | // RUN: %clang_cc1 -emit-llvm %s -o /dev/null |
2 | |
3 | // Test list stuff |
4 | |
5 | void *malloc(unsigned); |
6 | |
7 | // Test opaque structure support. the list type is defined later |
8 | struct list; |
9 | |
10 | struct list *PassThroughList(struct list *L) { |
11 | return L; |
12 | } |
13 | |
14 | |
15 | // Recursive data structure tests... |
16 | |
17 | typedef struct list { |
18 | int Data; |
19 | struct list *Next; |
20 | } list; |
21 | |
22 | list *Data; |
23 | |
24 | void 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 | |
31 | extern list ListNode1; |
32 | list ListNode3 = { 4, 0 }; |
33 | list ListNode2 = { 3, &ListNode3 }; |
34 | list ListNode0 = { 1, &ListNode1 }; |
35 | list ListNode1 = { 2, &ListNode2 }; |
36 | |
37 | |
38 | list ListArray[10]; |
39 | |
40 | // Iterative insert fn |
41 | void 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 |
50 | list *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 | |
56 | void foundIt(void); |
57 | |
58 | // Driver fn... |
59 | void 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 | |