On Wed, Aug 31, 2011 at 6:53 PM, Aldy Hernandez <al...@redhat.com> wrote: > >>>> Sure. I assume in this case, *bit_offset would be 0, right? >>> >>> It would be DECL_FIELD_BIT_OFFSET of that field. Oh, and >>> *byte_offset would be >>> >>> *byte_offset = size_binop (MULT_EXPR, TREE_OPERAND (exp, 2), >>> size_int (DECL_OFFSET_ALIGN >>> (field) / BITS_PER_UNIT)); >>> >>> see expr.c:component_ref_field_offset () (which you conveniently >>> could use here). >>> >>> Note that both TREE_OPERAND (exp, 2) and compoment_ref_field_offset >>> return offsets relative to the immediate containing struct type, not >>> relative to the base object like get_inner_reference does ... >>> (where it is still unclear to me what we are supposed to return from this >>> function ...) > > Ok, I see where your confusion lies. The function is supposed to return a > byte offset from the base object, none of this containing object or > immediate struct, or whatever. Base object, as in "a" in a.i.j.k, as in > what you get back from get_base_address(). > > Originally everything was calculated with get_inner_reference(), which is > relative to the base object, but now we have this hodge podge of > get_inner_reference() calls with ad-hoc calculations and optimizations. > Gladly, we've agreed to use get_inner_reference() and optimize at a later > time. > > So... base object throughout, anything else is a mistake on my part. > > BTW, this whole variable length offset I still can't trigger. I know you > want to cater to Ada, but does it even make sense to enable the C++ memory > model in Ada? Who would ever do this? Be that as it may, I'll humor you > and handle it. > >>> Thus, conservative would be using get_inner_reference here, if the >>> offset is supposed to be relative to the base object. >> >> That said, shouldn't *maxbits not at least make sure to cover the field >> itself? > > Is this what you want? > > /* Be as conservative as possible on variable offsets. */ > if (TREE_OPERAND (exp, 2) > && !host_integerp (TREE_OPERAND (exp, 2), 1)) > { > get_inner_reference (build3 (COMPONENT_REF, > TREE_TYPE (exp), > TREE_OPERAND (exp, 0), > field, NULL_TREE), > &tbitsize, &start_bitpos, &start_offset, > &tmode, &tunsignedp, &tvolatilep, true); > > *byte_offset = start_offset ? start_offset : size_zero_node; > *bit_offset = start_bitpos; > *maxbits = tbitsize; > return; > }
Yes, exactly. Richard.