[LLVMdev] getelementptr on static const struct

Reid Kleckner rnk at google.com
Thu Jan 30 10:01:36 PST 2014


On Thu, Jan 30, 2014 at 9:46 AM, Jonas Maebe <jonas.maebe at elis.ugent.be>wrote:
>
> The GEP takes the address of the 5th element (= offset 4) of your "char
> t[4]". It's not entirely clear to me from the description of "inbounds"
> whether this means the the GEP results in a poison value or not, but it
> definitely looks wrong.


I believe LLVM IR allows you to GEP from inside of one field into the next,
but I would defer to experts.

The constant folder is what creates this, and it totally ignores the
element index when folding a zero initialized array type:

Constant *ConstantAggregateZero::getSequentialElement() const {
  return Constant::getNullValue(getType()->getSequentialElementType());
}
Constant *ConstantAggregateZero::getElementValue(unsigned Idx) const {
  if (isa<SequentialType>(getType()))
    return getSequentialElement();  // Doesn't pass in Idx or check bounds.
  return getStructElement(Idx);
}

Looks like a bug to me.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140130/1c3a26f9/attachment.html>


More information about the llvm-dev mailing list