Another question today: an array of string literals in my C program
was transformed to independent global variables, each holding one
string, and another array of getelementptr's to them, here it is:
@words= global [5 x i8*] [ i8* getelementptr ([10 x i8]* @.str11, i32
0, i32 0), i8* getelementptr ([6 x i8]* @.str12, i32 0, i32 0), i8*
getelementptr ([7 x i8]* @.str13, i32 0, i32 0), i8* getelementptr ([6
x i8]* @.str14, i32 0, i32 0), i8* getelementptr ([11 x i8]* @.str15,
i32 0, i32 0) ] ; <[5 x i8*]*> [#uses=1]
Does this make sense? Are the elements of this array indeed regular
GetElementPtrInst's, which is a kind of Instruction? How can an
instruction live outside of a BasicBlock and a Function?
Thanks,
Harel
Another question today: an array of string literals in my C program
was transformed to independent global variables, each holding one
string, and another array of getelementptr's to them, here it is:
@words= global [5 x i8*] [ i8* getelementptr ([10 x i8]* @.str11, i32
0, i32 0), i8* getelementptr ([6 x i8]* @.str12, i32 0, i32 0), i8*
getelementptr ([7 x i8]* @.str13, i32 0, i32 0), i8* getelementptr ([6
x i8]* @.str14, i32 0, i32 0), i8* getelementptr ([11 x i8]* @.str15,
i32 0, i32 0) ] ; <[5 x i8*]*> [#uses=1]
Does this make sense?
Yes, consider the difference between
const char *const words[2] = { "foo", "bar" };
and
const char words[2][4] = { "foo", "bar" };
The first one is an array of pointers, the second is a two-dimensional array. Your code is a correct translation of the first one.
Are the elements of this array indeed regular
GetElementPtrInst's, which is a kind of Instruction? How can an
instruction live outside of a BasicBlock and a Function?
I am not an LLVM language lawyer, but these GEPs are constant expressions which is allowed, see http://llvm.org/docs/LangRef.html#constantexprs
Regards,
/jakob