GEP Instruction: i32 vs i64

I tried to understand the LLVMs GetElementPtr (GEP) instruction and came across this document:

http://llvm.org/docs/GetElementPtr.html

This is very useful, but there are a few things that I find confusing. In particular, under What is dereferenced by GEP? ( http://llvm.org/docs/GetElementPtr.html#id6 ) discusses the following code:

%MyVar = uninitialized global { [40 x i32 ]* }
...
%idx = getelementptr { [40 x i32]* }, { [40 x i32]* }* %MyVar, i64 0, i32 0, i64 0, i64 17

%MyVar- a global variable that is a pointer to a structure containing a pointer to an array of 40 ints. It is clear. I understand that the arguments after %MyVarare indexes in it, but I don’t understand why some of them are declared as i64, and others as i32.

I understand that this code was written for a 64-bit machine, and it is assumed that pointers are 64 bits wide. The contents of the array pointed %MyVarto are 32 bits wide. Why then the last index i64 17, and not i32 17?

I should also point out that this example illustrates the illegal use of GEP (the pointer in the structure must be dereferenced to index into an array of 40 ints), and I am trying to get a very good idea of ​​why this is the case.

+4
source share
1 answer

: " GEP?" . , GEP : , . .

:

%idx = getelementptr { [40 x i32]* }, { [40 x i32]* }* %MyVar, i64 0, i32 0, i64 0, i64 17

%MyVar, { [40 x i32]* }*, , .

i64 0 struct { [40 x i32]* }. %MyVar , .

i32 0 [40 x i32]*, . , , %MyVar.

i64 0 [40 x i32]. . GEP , . , GEP "" , , , , .

, i32 0 i64 0 , /. 17, .

+2

Source: https://habr.com/ru/post/1589290/


All Articles