[LLVMdev] Another memory fun

Zalunin Pavel wr4bbit at gmail.com
Sun Jan 6 10:29:55 PST 2008


Hey again)

Now I have next code:

; ModuleID = 'sample.lz'
@.str1 = internal global [8 x i8] c" world!\00"         ; <[8 x i8]*>
[#uses=1]
@.str2 = internal global [8 x i8] c"hello, \00"         ; <[8 x i8]*>
[#uses=1]
@.str7 = internal global [21 x i8] c"welcome to out hall!\00"           ;
<[21 x i8]*> [#uses=1]

declare i32 @puts(i8*)

declare i8* @strcat(i8*, i8*)

declare void @llvm.memcpy.i32(i8*, i8*, i32, i32)

define i32 @main() {
mainBlock:
        %.str3 = getelementptr [8 x i8]* @.str2, i64 0, i64 0           ;
<i8*> [#uses=1]
        %.str4 = getelementptr [8 x i8]* @.str1, i64 0, i64 0           ;
<i8*> [#uses=1]
        %tmp5 = call i8* @strcat( i8* %.str3, i8* %.str4 )              ;
<i8*> [#uses=1]
        %tmp6 = call i32 @puts( i8* %tmp5 )             ; <i32> [#uses=0]
        %.str8 = getelementptr [21 x i8]* @.str7, i64 0, i64 0          ;
<i8*> [#uses=1]
        %tmp9 = call i32 @puts( i8* %.str8 )            ; <i32> [#uses=0]
        ret i32 0
}

After compilation I see next(without %):

%
hello,  world!
world!

what is the trouble now?
but next code runs ok:
; ModuleID = 'sample.lz'
@.str1 = internal global [7 x i8] c"father\00"          ; <[7 x i8]*>
[#uses=1]
@.str2 = internal global [8 x i8] c"mother \00"         ; <[8 x i8]*>
[#uses=1]

declare i32 @puts(i8*)

declare i8* @strcat(i8*, i8*)

declare void @llvm.memcpy.i32(i8*, i8*, i32, i32)

define i32 @main() {
mainBlock:
        %.str3 = getelementptr [8 x i8]* @.str2, i64 0, i64 0           ;
<i8*> [#uses=1]
        %.str4 = getelementptr [7 x i8]* @.str1, i64 0, i64 0           ;
<i8*> [#uses=1]
        %tmp5 = call i8* @strcat( i8* %.str3, i8* %.str4 )              ;
<i8*> [#uses=1]
        %tmp6 = call i32 @puts( i8* %tmp5 )             ; <i32> [#uses=0]
        ret i32 0
}

After running:
%
mother father

It's ok, but in prev. example (when I call strcat more than one times)
program works incorrectly
help me please...

Best regards,
   Zalunin Pavel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080106/99ddb9f4/attachment.html>


More information about the llvm-dev mailing list