d0adf10ed5ac0c73fa7581649a92f2f349625923
[oota-llvm.git] / test / LLC / badfuncptr.c
1 /*
2  * Program: llc
3  * 
4  * Test Name: badfuncptr.c
5  * 
6  * Test Problem:
7  *      Indirect call via function pointer is mishandled in reg. alloc.
8  *      The indirect call address was allocated the same register as the
9  *      first outgoing argument, so it was overwritten before the call.
10  *
11  * Test Resolution:
12  *      In PhyRegAlloc.cpp, mark the live range for the indirect call
13  *      address as having a Call Interference.  This has to be done
14  *      as a special case since it may not be live after the call.
15  *
16  * Resolution Status:
17  *      Fixed on 3/29/02 -- Adve.
18  */
19 /* For copyright information, see olden_v1.0/COPYRIGHT */
20
21 #include <stdlib.h>
22 /* #include "hash.h" */
23 /*--------*/
24 /* hash.h */
25 /*--------*/
26 /* For copyright information, see olden_v1.0/COPYRIGHT */
27
28 #include "stdio.h"
29
30 typedef struct hash_entry {
31   unsigned int key;
32   void *entry;
33   struct hash_entry *next;
34 } *HashEntry;
35
36 typedef struct hash {
37   HashEntry *array;
38   int (*mapfunc)(unsigned int);
39   int size;
40 } *Hash;
41
42 Hash MakeHash(int size, int (*map)(unsigned int));
43 void *HashLookup(unsigned int key, Hash hash);
44 void HashInsert(void *entry,unsigned int key, Hash hash);
45 void HashDelete(unsigned int key, Hash hash);
46 /*--------*/
47 /* END hash.h */
48 /*--------*/
49
50 #define assert(num,a) if (!(a)) {printf("Assertion failure:%d in hash\n",num); exit(-1);}
51
52 void *HashLookup(unsigned int key, Hash hash)
53 {
54   int j;
55   HashEntry ent;
56   
57   j = (hash->mapfunc)(key);        /* 14% miss in hash->mapfunc */  
58   assert(1,j>=0);
59   assert(2,j<hash->size);
60   for (ent = hash->array[j];       /* 17% miss in hash->array[j] */ /* adt_pf can't detect :( */
61        ent &&                      /* 47% miss in ent->key */       /* adt_pf can detect :) */
62            ent->key!=key; 
63        ent=ent->next);             /* 8% miss in ent->next */       /* adt_pf can detect :) */
64   if (ent) return ent->entry;
65   return NULL;
66 }
67
68 /* essentially dummy main so testing does not fail */
69 int
70 main()
71 {
72   printf("&HashLookup = %d\n", !!HashLookup);
73   return 0;
74 }