[LLVMdev] Problems accessing structs
Chris Lattner
sabre at nondot.org
Tue May 11 10:03:01 PDT 2004
On Tue, 11 May 2004, John Criswell wrote:
> > "Kernel"* "createKernel"()
> > {
> > "myKernelMapInstance" = malloc "myKernelMap"
> > "myKernel" = malloc "Kernel"
> > "myKernelMapPTR" = getelementptr "Kernel"* "myKernel", long 0, ubyte 0
> > store "myKernelMap"* "myKernelMapInstance", "myKernelMap"** "myKernelMapPTR"
> > "puts_kernelPTRPTRMAP" = getelementptr "Kernel"* "myKernel", long 0, ubyte 0
> > "puts_kernelPTRMAP" = load "myKernelMap"** "puts_kernelPTRPTRMAP"
> > "puts_kernelPTR" = getelementptr "myKernelMap"* "puts_kernelPTRMAP", long 0, ubyte 0
> > store int (sbyte*)* %puts_kernel, int (sbyte*)** "puts_kernelPTR"
> > ret "Kernel"* "myKernel"
> ^---------------
> + I'm guessing this line might be the problem.
> :)
>
>
> The initialization code below is never getting reached, so the getchar()
> function pointer is never initialized.
I agree with John. If you run your code through the optimizers:
$ llvm-as < t.ll | opt -inline -load-vn -gcse -simplifycfg | llvm-dis
You get the following function:
int %main() {
createKernel.entry:
%myKernelMapInstance.i = malloc %myKernelMap ; <%myKernelMap*> [#uses=2]
%myKernel.i = malloc %Kernel ; <%Kernel*> [#uses=3]
%myKernelMapPTR.i = getelementptr %Kernel* %myKernel.i, long 0, uint 0 ; <%myKernelMap**> [#uses=1]
store %myKernelMap* %myKernelMapInstance.i, %myKernelMap** %myKernelMapPTR.i
%puts_kernelPTR.i = getelementptr %myKernelMap* %myKernelMapInstance.i, long 0, uint 0 ; <int (sbyte*)**> [#uses=1]
store int (sbyte*)* %puts_kernel, int (sbyte*)** %puts_kernelPTR.i
%PTRMAP.i = getelementptr %Kernel* %myKernel.i, long 0, uint 0 ; <%myKernelMap**> [#uses=3]
%MAP.i = load %myKernelMap** %PTRMAP.i ; <%myKernelMap*> [#uses=1]
%puts_kernelPTR.i2 = getelementptr %myKernelMap* %MAP.i, long 0, uint 0 ; <int (sbyte*)**> [#uses=1]
%tmp.i = load int (sbyte*)** %puts_kernelPTR.i2 ; <int (sbyte*)*> [#uses=1]
"Hello Kernel.i" = getelementptr [14 x sbyte]* "Hello KernelConst", long 0, long 0 ; <sbyte*> [#uses=1]
%tmp_result.i = call int %tmp.i( sbyte* "Hello Kernel.i" ) ; <int> [#uses=0]
%MAP.i4 = load %myKernelMap** %PTRMAP.i ; <%myKernelMap*> [#uses=1]
%getchar_kernelPTR.i5 = getelementptr %myKernelMap* %MAP.i4, long 0, uint 1 ; <int ()**> [#uses=1]
%tmp.i = load int ()** %getchar_kernelPTR.i5 ; <int ()*> [#uses=1]
%tmp_result.i6 = call int %tmp.i( ) ; <int> [#uses=0]
%myKernel_MapPTR = load %myKernelMap** %PTRMAP.i ; <%myKernelMap*> [#uses=1]
free %myKernelMap* %myKernel_MapPTR
free %Kernel* %myKernel.i
ret int 0
}
-Chris
--
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/
More information about the llvm-dev
mailing list