llvm.org GIT mirror llvm / 67c619b
FixedNumOperandTraits and VariadicOperandTraits assumed that, given a "this" pointer for any subclass of User, you could static_cast it to User* and then reinterpret_cast that to Use* to get the end of the operand list. This isn't a safe assumption in general, because the static_cast might adjust the "this" pointer. Fixed by having these OperandTraits classes take an extra template parameter, which is the subclass of User. This is groundwork for PR889. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123235 91177308-0d34-0410-b5e6-96231b3b80d8 Jay Foad 9 years ago
8 changed file(s) with 68 addition(s) and 42 deletion(s). Raw diff Collapse all Expand all
404404 };
405405
406406 template <>
407 struct OperandTraits : public VariadicOperandTraits<> {
407 struct OperandTraits :
408 public VariadicOperandTraits {
408409 };
409410
410411 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantArray, Constant)
453454 };
454455
455456 template <>
456 struct OperandTraits : public VariadicOperandTraits<> {
457 struct OperandTraits :
458 public VariadicOperandTraits {
457459 };
458460
459461 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantStruct, Constant)
510512 };
511513
512514 template <>
513 struct OperandTraits : public VariadicOperandTraits<> {
515 struct OperandTraits :
516 public VariadicOperandTraits {
514517 };
515518
516519 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantVector, Constant)
591594 };
592595
593596 template <>
594 struct OperandTraits : public FixedNumOperandTraits<2> {
597 struct OperandTraits :
598 public FixedNumOperandTraits {
595599 };
596600
597601 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(BlockAddress, Value)
870874 };
871875
872876 template <>
873 struct OperandTraits : public VariadicOperandTraits<1> {
877 struct OperandTraits :
878 public VariadicOperandTraits {
874879 };
875880
876881 DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantExpr, Constant)
8888 };
8989
9090 template <>
91 struct OperandTraits : public FixedNumOperandTraits<1> {
91 struct OperandTraits :
92 public FixedNumOperandTraits {
9293 };
9394
9495 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Value)
168168 };
169169
170170 template <>
171 struct OperandTraits : public OptionalOperandTraits<> {
171 struct OperandTraits :
172 public OptionalOperandTraits {
172173 };
173174
174175 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalVariable, Value)
127127 };
128128
129129 template <>
130 struct OperandTraits : public FixedNumOperandTraits<1> {
130 struct OperandTraits :
131 public FixedNumOperandTraits {
131132 };
132133
133134 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UnaryInstruction, Value)
431432 };
432433
433434 template <>
434 struct OperandTraits : public FixedNumOperandTraits<2> {
435 struct OperandTraits :
436 public FixedNumOperandTraits {
435437 };
436438
437439 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BinaryOperator, Value)
902904
903905 // FIXME: these are redundant if CmpInst < BinaryOperator
904906 template <>
905 struct OperandTraits : public FixedNumOperandTraits<2> {
907 struct OperandTraits : public FixedNumOperandTraits<CmpInst, 2> {
906908 };
907909
908910 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CmpInst, Value)
261261 };
262262
263263 template <>
264 struct OperandTraits : public FixedNumOperandTraits<2> {
264 struct OperandTraits : public FixedNumOperandTraits<StoreInst, 2> {
265265 };
266266
267267 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
523523 };
524524
525525 template <>
526 struct OperandTraits : public VariadicOperandTraits<1> {
526 struct OperandTraits :
527 public VariadicOperandTraits {
527528 };
528529
529530 template
10861087 };
10871088
10881089 template <>
1089 struct OperandTraits : public VariadicOperandTraits<1> {
1090 struct OperandTraits : public VariadicOperandTraits<CallInst, 1> {
10901091 };
10911092
10921093 template
11941195 };
11951196
11961197 template <>
1197 struct OperandTraits : public FixedNumOperandTraits<3> {
1198 struct OperandTraits : public FixedNumOperandTraits<SelectInst, 3> {
11981199 };
11991200
12001201 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
12911292 };
12921293
12931294 template <>
1294 struct OperandTraits : public FixedNumOperandTraits<2> {
1295 struct OperandTraits :
1296 public FixedNumOperandTraits {
12951297 };
12961298
12971299 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
13491351 };
13501352
13511353 template <>
1352 struct OperandTraits : public FixedNumOperandTraits<3> {
1354 struct OperandTraits :
1355 public FixedNumOperandTraits {
13531356 };
13541357
13551358 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
14061409 };
14071410
14081411 template <>
1409 struct OperandTraits : public FixedNumOperandTraits<3> {
1412 struct OperandTraits :
1413 public FixedNumOperandTraits {
14101414 };
14111415
14121416 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
17501754 };
17511755
17521756 template <>
1753 struct OperandTraits : public FixedNumOperandTraits<2> {
1757 struct OperandTraits :
1758 public FixedNumOperandTraits {
17541759 };
17551760
17561761 template
20312036 };
20322037
20332038 template <>
2034 struct OperandTraits : public VariadicOperandTraits<> {
2039 struct OperandTraits : public VariadicOperandTraits<ReturnInst> {
20352040 };
20362041
20372042 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
21242129 };
21252130
21262131 template <>
2127 struct OperandTraits : public VariadicOperandTraits<1> {};
2132 struct OperandTraits : public VariadicOperandTraits<BranchInst, 1> {
2133 };
21282134
21292135 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
21302136
26152621 };
26162622
26172623 template <>
2618 struct OperandTraits : public VariadicOperandTraits<3> {
2624 struct OperandTraits : public VariadicOperandTraits<InvokeInst, 3> {
26192625 };
26202626
26212627 template
2626 /// when it is a prefix to the User object, and the number of Use objects is
2727 /// known at compile time.
2828
29 template <unsigned ARITY>
29 template <typename SubClass, unsigned ARITY>
3030 struct FixedNumOperandTraits {
31 static Use *op_begin(User* U) {
31 static Use *op_begin(SubClass* U) {
3232 return reinterpret_cast(U) - ARITY;
3333 }
34 static Use *op_end(User* U) {
34 static Use *op_end(SubClass* U) {
3535 return reinterpret_cast(U);
3636 }
3737 static unsigned operands(const User*) {
5656 /// OptionalOperandTraits - when the number of operands may change at runtime.
5757 /// Naturally it may only decrease, because the allocations may not change.
5858
59 template
60 struct OptionalOperandTraits : public FixedNumOperandTraits {
59 template
60 struct OptionalOperandTraits : public FixedNumOperandTraits {
6161 static unsigned operands(const User *U) {
6262 return U->getNumOperands();
6363 }
7171 /// when it is a prefix to the User object, and the number of Use objects is
7272 /// only known at allocation time.
7373
74 template <unsigned MINARITY = 0>
74 template <typename SubClass, unsigned MINARITY = 0>
7575 struct VariadicOperandTraits {
76 static Use *op_begin(User* U) {
77 return reinterpret_cast(U) - U->getNumOperands();
78 }
79 static Use *op_end(User* U) {
76 static Use *op_begin(SubClass* U) {
77 return reinterpret_cast(U) - static_cast(U)->getNumOperands();
78 }
79 static Use *op_end(SubClass* U) {
8080 return reinterpret_cast(U);
8181 }
8282 static unsigned operands(const User *U) {
161161
162162 // FIXME: can we inherit this from ConstantExpr?
163163 template <>
164 struct OperandTraits : public FixedNumOperandTraits<1> {
164 struct OperandTraits :
165 public FixedNumOperandTraits {
165166 };
166167 }
167168
238238 };
239239
240240 template <>
241 struct OperandTraits : public FixedNumOperandTraits<1> {
241 struct OperandTraits :
242 public FixedNumOperandTraits {
242243 };
243244 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UnaryConstantExpr, Value)
244245
245246 template <>
246 struct OperandTraits : public FixedNumOperandTraits<2> {
247 struct OperandTraits :
248 public FixedNumOperandTraits {
247249 };
248250 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BinaryConstantExpr, Value)
249251
250252 template <>
251 struct OperandTraits : public FixedNumOperandTraits<3> {
253 struct OperandTraits :
254 public FixedNumOperandTraits {
252255 };
253256 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectConstantExpr, Value)
254257
255258 template <>
256 struct OperandTraits : public FixedNumOperandTraits<2> {
259 struct OperandTraits :
260 public FixedNumOperandTraits {
257261 };
258262 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementConstantExpr, Value)
259263
260264 template <>
261 struct OperandTraits : public FixedNumOperandTraits<3> {
265 struct OperandTraits :
266 public FixedNumOperandTraits {
262267 };
263268 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementConstantExpr, Value)
264269
265270 template <>
266 struct OperandTraits : public FixedNumOperandTraits<3> {
271 struct OperandTraits :
272 public FixedNumOperandTraits {
267273 };
268274 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorConstantExpr, Value)
269275
270276 template <>
271 struct OperandTraits : public FixedNumOperandTraits<1> {
277 struct OperandTraits :
278 public FixedNumOperandTraits {
272279 };
273280 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractValueConstantExpr, Value)
274281
275282 template <>
276 struct OperandTraits : public FixedNumOperandTraits<2> {
283 struct OperandTraits :
284 public FixedNumOperandTraits {
277285 };
278286 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueConstantExpr, Value)
279287
280288 template <>
281 struct OperandTraits : public VariadicOperandTraits<1> {
289 struct OperandTraits :
290 public VariadicOperandTraits {
282291 };
283292
284293 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrConstantExpr, Value)
285294
286295
287296 template <>
288 struct OperandTraits : public FixedNumOperandTraits<2> {
297 struct OperandTraits :
298 public FixedNumOperandTraits {
289299 };
290300 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CompareConstantExpr, Value)
291301