tags:

views:

70

answers:

1

The expression &ptr->fld doesn't represent a dereference, instead it should be treated as (uint32_t)ptr + offsetof (ptr, fld). I am certain that GCC does this simplification, but I cannot find where in the code.

The above ends up as ADDR_EXPR(COMPONENT_REF (INDIRECT_REF (ptr), fld)) in the AST, but at some point it should go through and simplify it. Having looked up almost every occurrence of ADDR_EXPR, COMPONENT_REF, and INDIRECT_REF in the gcc tree, I'm having trouble discovering where. Any ideas?

Note that I've tried seeking out help from GCC people. In general they're pretty unhelpful, but people here may know the answer. If this is a bad question I'll understand if it's closed.

+1  A: 

Since you are already familiar with the AST of GCC, one way to find out would be to produce all tree and RTL dumps with gcc -fdump-tree-all -fdump-rtl-all and then do a binary search through them to localize the pass which does the transformmation.

Laurynas Biveinis
This is a good suggestion, but it's not clear how the different dumps work or how to compare them. Regardless I haven't seen any evidence of this optimization happening in the front or middle ends, so perhaps it's deferred until code generation.
Dan Olson