llgen bugfix

This commit is contained in:
xushiwei
2024-04-29 20:51:27 +08:00
parent a6d31ad8b8
commit fc893ba498
7 changed files with 19 additions and 40 deletions

View File

@@ -10,5 +10,5 @@ func main() {
s := c.String("Hi\n")
s2 := c.Alloca(4)
c.Memcpy(s2, unsafe.Pointer(s), 4)
c.Printf(c.String("%s"), s)
c.Printf(c.String("%s"), s2)
}

View File

@@ -1,9 +1,9 @@
; ModuleID = 'main'
source_filename = "main"
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
@"main.init$guard" = global ptr null
@0 = private unnamed_addr constant [4 x i8] c"Hi\0A\00", align 1
@1 = private unnamed_addr constant [3 x i8] c"%s\00", align 1
define void @main.init() {
_llgo_0:
@@ -21,16 +21,12 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
define void @main() {
_llgo_0:
call void @main.init()
%0 = call ptr @"github.com/goplus/llgo/internal/runtime/c.String"([4 x i8] c"Hi\0A\00")
%1 = alloca i8, i64 4, align 1
%2 = call ptr @memcpy(ptr %1, ptr %0, i64 4)
%3 = call ptr @"github.com/goplus/llgo/internal/runtime/c.String"([3 x i8] c"%s\00")
%4 = call i32 (ptr, ...) @printf(ptr %3, ptr %0)
%0 = alloca i8, i64 4, align 1
%1 = call ptr @memcpy(ptr %0, ptr @0, i64 4)
%2 = call i32 (ptr, ...) @printf(ptr @1, ptr %0)
ret void
}
declare ptr @"github.com/goplus/llgo/internal/runtime/c.String"(%"github.com/goplus/llgo/internal/runtime.String")
declare ptr @memcpy(ptr, ptr, i64)
declare i32 @printf(ptr, ...)