comparison gen/aa.cpp @ 1643:8f121883bce8

Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
author Kelly Wilson <wilsonk cpsc.ucalgary.ca>
date Mon, 08 Mar 2010 23:37:40 -0700
parents 819b4f961711
children
comparison
equal deleted inserted replaced
1642:f49cb50c6064 1643:8f121883bce8
12 #include "gen/logger.h" 12 #include "gen/logger.h"
13 #include "gen/irstate.h" 13 #include "gen/irstate.h"
14 #include "gen/dvalue.h" 14 #include "gen/dvalue.h"
15 #include "ir/irmodule.h" 15 #include "ir/irmodule.h"
16 16
17 // makes sure the key value lives in memory so it can be passed to the runtime functions without problems
18 // returns the pointer
19 static LLValue* to_pkey(Loc& loc, DValue* key)
20 {
21 Type* keytype = key->getType();
22 bool needmem = !DtoIsPassedByRef(keytype);
23 LLValue* pkey;
24 if (key->isIm()) {
25 pkey = key->getRVal();
26 }
27 else if (DVarValue* var = key->isVar()) {
28 pkey = key->getLVal();
29 needmem = false;
30 }
31 else if (key->isConst()) {
32 needmem = true;
33 pkey = key->getRVal();
34 }
35 else {
36 LLValue* tmp = DtoAlloca(keytype, "aatmpkeystorage");
37 DVarValue var(keytype, tmp);
38 DtoAssign(loc, &var, key);
39 return tmp;
40 }
41
42 // give memory
43 if (needmem) {
44 LLValue* tmp = DtoAlloca(keytype, "aatmpkeystorage");
45 DtoStore(pkey, tmp);
46 pkey = tmp;
47 }
48
49 return pkey;
50 }
51
52 // returns the keytype typeinfo 17 // returns the keytype typeinfo
53 static LLValue* to_keyti(DValue* key) 18 static LLValue* to_keyti(DValue* key)
54 { 19 {
55 // keyti param 20 // keyti param
56 Type* keytype = key->getType(); 21 Type* keytype = key->getType();
77 // keyti param 42 // keyti param
78 LLValue* keyti = to_keyti(key); 43 LLValue* keyti = to_keyti(key);
79 keyti = DtoBitCast(keyti, funcTy->getParamType(1)); 44 keyti = DtoBitCast(keyti, funcTy->getParamType(1));
80 45
81 // pkey param 46 // pkey param
82 LLValue* pkey = to_pkey(loc, key); 47 LLValue* pkey = makeLValue(loc, key);
83 pkey = DtoBitCast(pkey, funcTy->getParamType(lvalue ? 3 : 2)); 48 pkey = DtoBitCast(pkey, funcTy->getParamType(lvalue ? 3 : 2));
84 49
85 // call runtime 50 // call runtime
86 LLValue* ret; 51 LLValue* ret;
87 if (lvalue) { 52 if (lvalue) {
162 // keyti param 127 // keyti param
163 LLValue* keyti = to_keyti(key); 128 LLValue* keyti = to_keyti(key);
164 keyti = DtoBitCast(keyti, funcTy->getParamType(1)); 129 keyti = DtoBitCast(keyti, funcTy->getParamType(1));
165 130
166 // pkey param 131 // pkey param
167 LLValue* pkey = to_pkey(loc, key); 132 LLValue* pkey = makeLValue(loc, key);
168 pkey = DtoBitCast(pkey, funcTy->getParamType(2)); 133 pkey = DtoBitCast(pkey, funcTy->getParamType(2));
169 134
170 // call runtime 135 // call runtime
171 LLValue* ret = gIR->CreateCallOrInvoke3(func, aaval, keyti, pkey, "aa.in").getInstruction(); 136 LLValue* ret = gIR->CreateCallOrInvoke3(func, aaval, keyti, pkey, "aa.in").getInstruction();
172 137
204 // keyti param 169 // keyti param
205 LLValue* keyti = to_keyti(key); 170 LLValue* keyti = to_keyti(key);
206 keyti = DtoBitCast(keyti, funcTy->getParamType(1)); 171 keyti = DtoBitCast(keyti, funcTy->getParamType(1));
207 172
208 // pkey param 173 // pkey param
209 LLValue* pkey = to_pkey(loc, key); 174 LLValue* pkey = makeLValue(loc, key);
210 pkey = DtoBitCast(pkey, funcTy->getParamType(2)); 175 pkey = DtoBitCast(pkey, funcTy->getParamType(2));
211 176
212 // build arg vector 177 // build arg vector
213 LLSmallVector<LLValue*, 3> args; 178 LLSmallVector<LLValue*, 3> args;
214 args.push_back(aaval); 179 args.push_back(aaval);