[LLVMdev] Accessing constant indexes in GetElementPtr

Bill? Wendling wendling at isanbard.org
Mon Sep 23 00:24:01 PDT 2002


Also sprach Wojciech Stryjewski:
} Ok. Let's say I have a GetElementPtrInst that is used to access structure
} elements. In this case the indexes will be constants and I want to get the
} constant values as an a native C int.
} 
} Now I can iterate over all the indexes with idx_begin(). I can cast
} all of the indexes to a ConstantIntegral. However, I cannot cast the
} indexes to a ConstantSInt or ConstantUInt (cast<> throws an assertion) and
} these two classes are the ones that have the getValue() method I need.
} 
} Am I missing something here?
} 
I'm not quite sure what particular problem you're having, but a few
things to remember...

    - Not all of the operands of getelementptr are constants. (In
      particular, Operand(0) isn't).
    - You might try "dyn_cast" which will return a valid pointer or 0
      instead of throwing an assertion.
    - Look at the "getNullValue()" method in "Constant". That might be
      useful as well.

-- 
|| Bill? Wendling			wendling at isanbard.org



More information about the llvm-dev mailing list