[LLVMdev] trouble with getelementptr
Dale Johannesen
dalej at apple.com
Sat Jan 5 16:32:00 PST 2008
On Jan 5, 2008, at 4:09 PM, Zalunin Pavel wrote:
> Hello,
> I have next code:
> ;begin
> ; ModuleID = 'sample.lz'
> @.str1 = internal constant [20 x i8] c"\22hello, cruel world
> \22" ; <[20 x i8]*> [#uses=1]
> @.str4 = internal constant [9 x i8] c"\22hello, \22" ; <
> [9 x i8]*> [#uses=1]
> @.str7 = internal constant [7 x i8] c"\22heya!\22" ; <
> [7 x i8]*> [#uses=1]
>
> declare i32 @puts(i8*)
puts expects strings to be null-terminated. Compare output of llvm-
gcc -emit-llvm -S -O0.
> declare i8 @strcat(i8*, i8*)
>
> define i32 @main() {
> mainBlock:
> %tmp2 = getelementptr [20 x i8]* @.str1, i64 0, i64
> 0 ; <i8*> [#uses=1]
> %tmp3 = call i32 @puts( i8* %tmp2 ) ; <i32>
> [#uses=0]
> %tmp5 = getelementptr [9 x i8]* @.str4, i64 0, i64
> 0 ; <i8*> [#uses=1]
> %tmp6 = call i32 @puts( i8* %tmp5 ) ; <i32>
> [#uses=0]
> %tmp8 = getelementptr [7 x i8]* @.str7, i64 0, i64
> 0 ; <i8*> [#uses=1]
> %tmp9 = call i32 @puts( i8* %tmp8 ) ; <i32>
> [#uses=0]
> ret i32 0
> }
>
> ;end
>
> llvm-as test.ll -o test.ll.bc
> llc test.ll.bc -o test.ll.s
> gcc test.ll.s -o test.ll.native
>
> After running a see next:
>
> whiter4bbit at LiZa /home/whiter4bbit/programming
> /study/yapis/liza $ ./test.ll.native
> "hello, cruel world""hello, ""heya!"
> "hello, ""heya!"
> "heya!"
>
> It isn't a target result:) target is:
>
> whiter4bbit at LiZa /home/whiter4bbit/programming/study/yapis/liza $ ./
> test.ll.native
> "hello, cruel world"
> "hello, "
> "heya!"
>
> what is the trouble here?
> I think about freeing memory after using getelementptr, is it right?
> (and if it right can anybody answer 'how?')
> Help me please...
>
> Best regards, Zalunin Pavel
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list