[llvm-dev] Referencing fields in initializers

Jan Hoogerbrugge via llvm-dev llvm-dev at lists.llvm.org
Fri Mar 8 04:30:10 PST 2019


I have found the issue. I used i64 as indices. For structs it should be an
i32. That solved the problem.

Jan.

On Thu, Mar 7, 2019 at 4:31 PM Jan Hoogerbrugge <jan.hoogerbrugge at gmail.com>
wrote:

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


More information about the llvm-dev mailing list