summaryrefslogtreecommitdiff
path: root/test/LLC/badfuncptr.c
blob: 8da7fbe3eb7ea3989e88c65bc244372ede7c6286 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 * Program: llc
 * 
 * Test Name: badfuncptr.c
 * 
 * Test Problem:
 *      Indirect call via function pointer is mishandled in reg. alloc.
 *      The indirect call address was allocated the same register as the
 *      first outgoing argument, so it was overwritten before the call.
 *
 * Test Resolution:
 *      In PhyRegAlloc.cpp, mark the live range for the indirect call
 *      address as having a Call Interference.  This has to be done
 *      as a special case since it may not be live after the call.
 *
 * Resolution Status:
 *      Fixed on 3/29/02 -- Adve.
 */
/* For copyright information, see olden_v1.0/COPYRIGHT */

#include <stdlib.h>
/* #include "hash.h" */
/*--------*/
/* hash.h */
/*--------*/
/* For copyright information, see olden_v1.0/COPYRIGHT */

#include "stdio.h"

typedef struct hash_entry {
  unsigned int key;
  void *entry;
  struct hash_entry *next;
} *HashEntry;

typedef struct hash {
  HashEntry *array;
  int (*mapfunc)(unsigned int);
  int size;
} *Hash;

Hash MakeHash(int size, int (*map)(unsigned int));
void *HashLookup(unsigned int key, Hash hash);
void HashInsert(void *entry,unsigned int key, Hash hash);
void HashDelete(unsigned int key, Hash hash);
/*--------*/
/* END hash.h */
/*--------*/

#define assert(num,a) if (!(a)) {printf("Assertion failure:%d in hash\n",num); exit(-1);}

void *HashLookup(unsigned int key, Hash hash)
{
  int j;
  HashEntry ent;
  
  j = (hash->mapfunc)(key);        /* 14% miss in hash->mapfunc */  
  assert(1,j>=0);
  assert(2,j<hash->size);
  for (ent = hash->array[j];       /* 17% miss in hash->array[j] */ /* adt_pf can't detect :( */
       ent &&                      /* 47% miss in ent->key */       /* adt_pf can detect :) */
           ent->key!=key; 
       ent=ent->next);             /* 8% miss in ent->next */       /* adt_pf can detect :) */
  if (ent) return ent->entry;
  return NULL;
}

/* essentially dummy main so testing does not fail */
int
main()
{
  printf("&HashLookup = 0x%p\n", HashLookup);
  return 0;
}