This is the error I am getting: "test8.c:11:7: internal compiler error: in expand_expr_real_1, at expr.c:8755" Looking at the code I see that this is an assert statement. The call to the function get_addr_base_and_unit_offset() returns NULL, which is expected as per the comments on this function. Zahed On Fri, Mar 9, 2012 at 9:02 PM, Ian Lance Taylor <iant@xxxxxxxxxx> wrote: > zahed khurasani <sdzahed@xxxxxxxxx> writes: > >> Let me try again. If I have an expression of the from a[i][10], then I >> need to insert the >> following function call into the tree: >> check_deref(a[i][10], sizeof(a[i][10]), &a[i][10]); >> >> I tried POINTER_PLUS_EXPR. It fails at the same place. However, it >> works if I have >> constant indices like a[1][10]. >> >> Hope this is clearer than before. Thanks! > > Exactly how does it fail if you have non-constant indices? > > Ian > >> On Fri, Mar 9, 2012 at 7:48 PM, Ian Lance Taylor <iant@xxxxxxxxxx> wrote: >>> zahed khurasani <sdzahed@xxxxxxxxx> writes: >>> >>>> I need to build a node that is equivalent to the address of the memory >>>> being derenferenced. >>>> MEM_REF would help with the first parameter. But what about the third parameter? >>>> I would need an ADDR_EXPR for this parameter. However, the code I am using >>>> is failing. >>>> Thanks for the help. >>> >>> I'm not sure I completely understand, but I will say that a >>> POINTER_PLUS_EXPR would be the address equivalent of a MEM_REF. >>> >>> Ian >>> >>>> On Fri, Mar 9, 2012 at 6:04 PM, Ian Lance Taylor <iant@xxxxxxxxxx> wrote: >>>>> zahed khurasani <sdzahed@xxxxxxxxx> writes: >>>>> >>>>>> My check function accepts three parameters: the value being >>>>>> dereferenced, the size of the object and the address in memory. I am >>>>>> using the following two lines to get the third address parameter. >>>>>> >>>>>> addr = build1 (ADDR_EXPR, build_pointer_type (type), t); // t is the >>>>>> ARRAY_REF node >>>>>> fold_convert_loc(location, ptr_type_node, addr); // type case to void * >>>>>> >>>>>> However, this is failing whenever the array_ref contains a >>>>>> non-constant expression, say like a[i+1]. The specific failure is >>>>>> inside the expand_expr_real_1 method in the file expr.c. Looks like >>>>>> such non-constant indices are not allowed at this stage in the >>>>>> compilation (I've inserted the pass just before lowering to RTL >>>>>> happens). >>>>>> >>>>>> My question is, what would be the right way to get the address? I am >>>>>> looking for something that will preferably work for all dereferences >>>>>> like MEM_REF, INDIRECT_REF etc. >>>>> >>>>> ARRAY_REF certainly permits non-constant indices, so I don't think that >>>>> is your problem. >>>>> >>>>> However, MEM_REF is the most general memory reference expression. >>>>> >>>>> Ian