<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi,</div><div><br></div><div>For an IR transformation pass I need to get all addresses of fields in an global variable that refer</div><div>to global variables in their initializer. <br></div><div><br></div><div>For example, in this code I need the addresses of s.b[1] and s.c[0]:<br></div><div><br></div><div>  int foo, bar;</div><div><br></div><div>  struct S</div><div>  {</div><div>    int a;</div><div>    int *b[2];</div><div>    int *c[3];<br></div><div>  } s = {1, {0, &foo}, {&bar, 0, 0}};</div><div><br></div><div>I tried to achieve this by traversing the initializer and maintaining a path of how I get to the</div><div>current position in the data structure. In the example s.b[1] corresponds to path (1, 1) and</div><div>s.c[0] with path (2, 0). The paths are then uses as indices for GetElementPtr. So I do</div><div>GetElementPtr s 1 1 and GetElementPtr s 2 0. This works in many cases but it crashes</div><div>on cases where there are GetElementPtr operators in the tree on the path leading <br></div><div>to the position where I want to take the address ("Invalid GetElementPtrInst indices for type!").</div><div><br></div><div>Does anyone have a suggestion on how I can find the places in initialized global variables where <br></div><div>addresses of global variables are used for initialization?</div><div><br></div><div>Regards,</div><div>Jan.<br></div></div></div></div></div>