mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-04-13 15:37:24 +00:00
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
This commit is contained in:
parent
65fdded319
commit
67c619ba3e
@ -405,7 +405,8 @@ public:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<ConstantArray> : public VariadicOperandTraits<> {
|
||||
struct OperandTraits<ConstantArray> :
|
||||
public VariadicOperandTraits<ConstantArray> {
|
||||
};
|
||||
|
||||
DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantArray, Constant)
|
||||
@ -454,7 +455,8 @@ public:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<ConstantStruct> : public VariadicOperandTraits<> {
|
||||
struct OperandTraits<ConstantStruct> :
|
||||
public VariadicOperandTraits<ConstantStruct> {
|
||||
};
|
||||
|
||||
DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantStruct, Constant)
|
||||
@ -511,7 +513,8 @@ public:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<ConstantVector> : public VariadicOperandTraits<> {
|
||||
struct OperandTraits<ConstantVector> :
|
||||
public VariadicOperandTraits<ConstantVector> {
|
||||
};
|
||||
|
||||
DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantVector, Constant)
|
||||
@ -592,7 +595,8 @@ public:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<BlockAddress> : public FixedNumOperandTraits<2> {
|
||||
struct OperandTraits<BlockAddress> :
|
||||
public FixedNumOperandTraits<BlockAddress, 2> {
|
||||
};
|
||||
|
||||
DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(BlockAddress, Value)
|
||||
@ -871,7 +875,8 @@ private:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<ConstantExpr> : public VariadicOperandTraits<1> {
|
||||
struct OperandTraits<ConstantExpr> :
|
||||
public VariadicOperandTraits<ConstantExpr, 1> {
|
||||
};
|
||||
|
||||
DEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantExpr, Constant)
|
||||
|
@ -89,7 +89,8 @@ public:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<GlobalAlias> : public FixedNumOperandTraits<1> {
|
||||
struct OperandTraits<GlobalAlias> :
|
||||
public FixedNumOperandTraits<GlobalAlias, 1> {
|
||||
};
|
||||
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Value)
|
||||
|
@ -169,7 +169,8 @@ public:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<GlobalVariable> : public OptionalOperandTraits<> {
|
||||
struct OperandTraits<GlobalVariable> :
|
||||
public OptionalOperandTraits<GlobalVariable> {
|
||||
};
|
||||
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalVariable, Value)
|
||||
|
@ -128,7 +128,8 @@ public:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<UnaryInstruction> : public FixedNumOperandTraits<1> {
|
||||
struct OperandTraits<UnaryInstruction> :
|
||||
public FixedNumOperandTraits<UnaryInstruction, 1> {
|
||||
};
|
||||
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UnaryInstruction, Value)
|
||||
@ -432,7 +433,8 @@ public:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<BinaryOperator> : public FixedNumOperandTraits<2> {
|
||||
struct OperandTraits<BinaryOperator> :
|
||||
public FixedNumOperandTraits<BinaryOperator, 2> {
|
||||
};
|
||||
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BinaryOperator, Value)
|
||||
@ -903,7 +905,7 @@ private:
|
||||
|
||||
// FIXME: these are redundant if CmpInst < BinaryOperator
|
||||
template <>
|
||||
struct OperandTraits<CmpInst> : public FixedNumOperandTraits<2> {
|
||||
struct OperandTraits<CmpInst> : public FixedNumOperandTraits<CmpInst, 2> {
|
||||
};
|
||||
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CmpInst, Value)
|
||||
|
@ -262,7 +262,7 @@ private:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<StoreInst> : public FixedNumOperandTraits<2> {
|
||||
struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
|
||||
};
|
||||
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
|
||||
@ -524,7 +524,8 @@ public:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<GetElementPtrInst> : public VariadicOperandTraits<1> {
|
||||
struct OperandTraits<GetElementPtrInst> :
|
||||
public VariadicOperandTraits<GetElementPtrInst, 1> {
|
||||
};
|
||||
|
||||
template<typename RandomAccessIterator>
|
||||
@ -1087,7 +1088,7 @@ private:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<CallInst> : public VariadicOperandTraits<1> {
|
||||
struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
|
||||
};
|
||||
|
||||
template<typename RandomAccessIterator>
|
||||
@ -1195,7 +1196,7 @@ public:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<SelectInst> : public FixedNumOperandTraits<3> {
|
||||
struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
|
||||
};
|
||||
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
|
||||
@ -1292,7 +1293,8 @@ public:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<ExtractElementInst> : public FixedNumOperandTraits<2> {
|
||||
struct OperandTraits<ExtractElementInst> :
|
||||
public FixedNumOperandTraits<ExtractElementInst, 2> {
|
||||
};
|
||||
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
|
||||
@ -1350,7 +1352,8 @@ public:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<InsertElementInst> : public FixedNumOperandTraits<3> {
|
||||
struct OperandTraits<InsertElementInst> :
|
||||
public FixedNumOperandTraits<InsertElementInst, 3> {
|
||||
};
|
||||
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
|
||||
@ -1407,7 +1410,8 @@ public:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<ShuffleVectorInst> : public FixedNumOperandTraits<3> {
|
||||
struct OperandTraits<ShuffleVectorInst> :
|
||||
public FixedNumOperandTraits<ShuffleVectorInst, 3> {
|
||||
};
|
||||
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
|
||||
@ -1751,7 +1755,8 @@ public:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<InsertValueInst> : public FixedNumOperandTraits<2> {
|
||||
struct OperandTraits<InsertValueInst> :
|
||||
public FixedNumOperandTraits<InsertValueInst, 2> {
|
||||
};
|
||||
|
||||
template<typename RandomAccessIterator>
|
||||
@ -2032,7 +2037,7 @@ public:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<ReturnInst> : public VariadicOperandTraits<> {
|
||||
struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
|
||||
};
|
||||
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
|
||||
@ -2125,7 +2130,8 @@ private:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<BranchInst> : public VariadicOperandTraits<1> {};
|
||||
struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
|
||||
};
|
||||
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
|
||||
|
||||
@ -2616,7 +2622,7 @@ private:
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<InvokeInst> : public VariadicOperandTraits<3> {
|
||||
struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
|
||||
};
|
||||
|
||||
template<typename RandomAccessIterator>
|
||||
|
@ -27,12 +27,12 @@ namespace llvm {
|
||||
/// when it is a prefix to the User object, and the number of Use objects is
|
||||
/// known at compile time.
|
||||
|
||||
template <unsigned ARITY>
|
||||
template <typename SubClass, unsigned ARITY>
|
||||
struct FixedNumOperandTraits {
|
||||
static Use *op_begin(User* U) {
|
||||
static Use *op_begin(SubClass* U) {
|
||||
return reinterpret_cast<Use*>(U) - ARITY;
|
||||
}
|
||||
static Use *op_end(User* U) {
|
||||
static Use *op_end(SubClass* U) {
|
||||
return reinterpret_cast<Use*>(U);
|
||||
}
|
||||
static unsigned operands(const User*) {
|
||||
@ -57,8 +57,8 @@ struct FixedNumOperandTraits {
|
||||
/// OptionalOperandTraits - when the number of operands may change at runtime.
|
||||
/// Naturally it may only decrease, because the allocations may not change.
|
||||
|
||||
template <unsigned ARITY = 1>
|
||||
struct OptionalOperandTraits : public FixedNumOperandTraits<ARITY> {
|
||||
template <typename SubClass, unsigned ARITY = 1>
|
||||
struct OptionalOperandTraits : public FixedNumOperandTraits<SubClass, ARITY> {
|
||||
static unsigned operands(const User *U) {
|
||||
return U->getNumOperands();
|
||||
}
|
||||
@ -72,12 +72,12 @@ struct OptionalOperandTraits : public FixedNumOperandTraits<ARITY> {
|
||||
/// when it is a prefix to the User object, and the number of Use objects is
|
||||
/// only known at allocation time.
|
||||
|
||||
template <unsigned MINARITY = 0>
|
||||
template <typename SubClass, unsigned MINARITY = 0>
|
||||
struct VariadicOperandTraits {
|
||||
static Use *op_begin(User* U) {
|
||||
return reinterpret_cast<Use*>(U) - U->getNumOperands();
|
||||
static Use *op_begin(SubClass* U) {
|
||||
return reinterpret_cast<Use*>(U) - static_cast<User*>(U)->getNumOperands();
|
||||
}
|
||||
static Use *op_end(User* U) {
|
||||
static Use *op_end(SubClass* U) {
|
||||
return reinterpret_cast<Use*>(U);
|
||||
}
|
||||
static unsigned operands(const User *U) {
|
||||
|
@ -162,7 +162,8 @@ namespace {
|
||||
|
||||
// FIXME: can we inherit this from ConstantExpr?
|
||||
template <>
|
||||
struct OperandTraits<ConstantPlaceHolder> : public FixedNumOperandTraits<1> {
|
||||
struct OperandTraits<ConstantPlaceHolder> :
|
||||
public FixedNumOperandTraits<ConstantPlaceHolder, 1> {
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -239,54 +239,64 @@ struct CompareConstantExpr : public ConstantExpr {
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OperandTraits<UnaryConstantExpr> : public FixedNumOperandTraits<1> {
|
||||
struct OperandTraits<UnaryConstantExpr> :
|
||||
public FixedNumOperandTraits<UnaryConstantExpr, 1> {
|
||||
};
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UnaryConstantExpr, Value)
|
||||
|
||||
template <>
|
||||
struct OperandTraits<BinaryConstantExpr> : public FixedNumOperandTraits<2> {
|
||||
struct OperandTraits<BinaryConstantExpr> :
|
||||
public FixedNumOperandTraits<BinaryConstantExpr, 2> {
|
||||
};
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BinaryConstantExpr, Value)
|
||||
|
||||
template <>
|
||||
struct OperandTraits<SelectConstantExpr> : public FixedNumOperandTraits<3> {
|
||||
struct OperandTraits<SelectConstantExpr> :
|
||||
public FixedNumOperandTraits<SelectConstantExpr, 3> {
|
||||
};
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectConstantExpr, Value)
|
||||
|
||||
template <>
|
||||
struct OperandTraits<ExtractElementConstantExpr> : public FixedNumOperandTraits<2> {
|
||||
struct OperandTraits<ExtractElementConstantExpr> :
|
||||
public FixedNumOperandTraits<ExtractElementConstantExpr, 2> {
|
||||
};
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementConstantExpr, Value)
|
||||
|
||||
template <>
|
||||
struct OperandTraits<InsertElementConstantExpr> : public FixedNumOperandTraits<3> {
|
||||
struct OperandTraits<InsertElementConstantExpr> :
|
||||
public FixedNumOperandTraits<InsertElementConstantExpr, 3> {
|
||||
};
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementConstantExpr, Value)
|
||||
|
||||
template <>
|
||||
struct OperandTraits<ShuffleVectorConstantExpr> : public FixedNumOperandTraits<3> {
|
||||
struct OperandTraits<ShuffleVectorConstantExpr> :
|
||||
public FixedNumOperandTraits<ShuffleVectorConstantExpr, 3> {
|
||||
};
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorConstantExpr, Value)
|
||||
|
||||
template <>
|
||||
struct OperandTraits<ExtractValueConstantExpr> : public FixedNumOperandTraits<1> {
|
||||
struct OperandTraits<ExtractValueConstantExpr> :
|
||||
public FixedNumOperandTraits<ExtractValueConstantExpr, 1> {
|
||||
};
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractValueConstantExpr, Value)
|
||||
|
||||
template <>
|
||||
struct OperandTraits<InsertValueConstantExpr> : public FixedNumOperandTraits<2> {
|
||||
struct OperandTraits<InsertValueConstantExpr> :
|
||||
public FixedNumOperandTraits<InsertValueConstantExpr, 2> {
|
||||
};
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueConstantExpr, Value)
|
||||
|
||||
template <>
|
||||
struct OperandTraits<GetElementPtrConstantExpr> : public VariadicOperandTraits<1> {
|
||||
struct OperandTraits<GetElementPtrConstantExpr> :
|
||||
public VariadicOperandTraits<GetElementPtrConstantExpr, 1> {
|
||||
};
|
||||
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrConstantExpr, Value)
|
||||
|
||||
|
||||
template <>
|
||||
struct OperandTraits<CompareConstantExpr> : public FixedNumOperandTraits<2> {
|
||||
struct OperandTraits<CompareConstantExpr> :
|
||||
public FixedNumOperandTraits<CompareConstantExpr, 2> {
|
||||
};
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CompareConstantExpr, Value)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user