brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 243a196 Raw
72 lines · c
1// RUN: %clang_cc1 -emit-llvm %s  -o /dev/null2 3// Test list stuff4 5void *malloc(unsigned);6 7// Test opaque structure support.  the list type is defined later8struct 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(void) {25  static int Foo = 0;            // Test static local variable26  Foo += 1;                      // Increment static variable27 28  Data = (list*)malloc(12);      // This is not a proper list allocation29}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 fn41void 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 fn50list *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(void) {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