diff --git a/include/llvm/OperandTraits.h b/include/llvm/OperandTraits.h index a4b634c7623..83c1025c07b 100644 --- a/include/llvm/OperandTraits.h +++ b/include/llvm/OperandTraits.h @@ -124,8 +124,8 @@ struct HungoffOperandTraits { inline op_iterator op_end(); \ inline const_op_iterator op_end() const; \ protected: \ - template inline Use &Op(); \ - template inline const Use &Op() const; \ + template inline Use &Op(); \ + template inline const Use &Op() const; \ public: \ inline unsigned getNumOperands() const @@ -157,12 +157,11 @@ void CLASS::setOperand(unsigned i_nocapture, VALUECLASS *Val_nocapture) { \ unsigned CLASS::getNumOperands() const { \ return OperandTraits::operands(this); \ } \ -template Use &CLASS::Op() { \ - return OperandTraits::op_begin(this)[Idx_nocapture]; \ +template Use &CLASS::Op() { \ + return this->OpFrom(this); \ } \ -template const Use &CLASS::Op() const { \ - return OperandTraits::op_begin( \ - const_cast(this))[Idx_nocapture]; \ +template const Use &CLASS::Op() const { \ + return this->OpFrom(this); \ } @@ -195,12 +194,11 @@ void CLASS::setOperand(unsigned i_nocapture, VALUECLASS *Val_nocapture) { \ unsigned CLASS::getNumOperands() const { \ return OperandTraits::operands(this); \ } \ -template Use &CLASS::Op() { \ - return OperandTraits::op_begin(this)[Idx_nocapture]; \ +template Use &CLASS::Op() { \ + return this->OpFrom(this); \ } \ -template const Use &CLASS::Op() const { \ - return OperandTraits::op_begin( \ - const_cast(this))[Idx_nocapture]; \ +template const Use &CLASS::Op() const { \ + return this->OpFrom(this); \ } diff --git a/include/llvm/User.h b/include/llvm/User.h index f2df23e3412..1a88ce0cce8 100644 --- a/include/llvm/User.h +++ b/include/llvm/User.h @@ -83,11 +83,16 @@ public: assert(0 && "Constructor throws?"); } protected: - template Use &Op() { - return OperandTraits::op_begin(this)[Idx]; + template static Use &OpFrom(const U *that) { + return Idx < 0 + ? OperandTraits::op_end(const_cast(that))[Idx] + : OperandTraits::op_begin(const_cast(that))[Idx]; } - template const Use &Op() const { - return OperandTraits::op_begin(const_cast(this))[Idx]; + template Use &Op() { + return OpFrom(this); + } + template const Use &Op() const { + return OpFrom(this); } public: Value *getOperand(unsigned i) const {