[LLVMdev] Undefined behavior in Operator class?
Eli Friedman
eli.friedman at gmail.com
Sat Oct 6 21:28:00 PDT 2012
On Sat, Oct 6, 2012 at 8:43 PM, Sean Silva <silvas at purdue.edu> wrote:
> If I understand correctly, Operator is basically a trivial temporary
> object that holds some common functionality for both Instruction and
> ConstantExpr.
>
> It looks to me like Operator is doing something illegal though. For
> example, in this member function of class Operator (in
> include/llvm/Operator.h):
>
> /// getOpcode - Return the opcode for this Instruction or ConstantExpr.
> ///
> unsigned getOpcode() const {
> if (const Instruction *I = dyn_cast<Instruction>(this))
> return I->getOpcode();
> return cast<ConstantExpr>(this)->getOpcode();
> }
>
> In this function, the `this` pointer is not pointing at an Operator
> object. That's undefined behavior, right?
Yes.
-Eli
More information about the llvm-dev
mailing list