Massimo Nazaria <ma...@rocketmail.com> writes:

> I'm working on a pass and I need to handle some pointer expressions.
> For example, I have this C-code:
>   int v[1000];
>   int *p;  
>   p = &v[10];
>
> The problem is that, when I'm trying to parse "p = &v[10];", I'm not able to 
> get the array offset (10 in this case).
>
> Namely, for a given statement like "p = &v[10]", I need to get:
>   array:  v  (I can do that)
>   offset: 10
>
> Here is the code I am working on:
>   op0 = gimple_op (stmt, 0);
>   op1 = gimple_op (stmt, 1);
>   
>   if (gimple_assign_rhs_code (stmt) == ADDR_EXPR)
>     {
>       base = get_base_address (TREE_OPERAND (op1, 0)); // the array v, OK
>       offset = // ???
>
> How can I do?

There is nothing wrong with calling get_base_address, but by doing
that you have thrown away the offset information.  I would expected
TREE_OPERAND (op1, 0) to be an ARRAY_REF.  Operand 0 of that will be
an array, operand 1 will be an index.

I would recommend taking a look at get_inner_reference rather than
get_base_address.

Ian

Reply via email to