From 578bc165c43e9022615a352ab92927b6cd8901ff Mon Sep 17 00:00:00 2001 From: Li Jie Date: Mon, 5 Aug 2024 20:52:34 +0800 Subject: [PATCH] test: fix cl and ssa tests --- cl/_testdata/async/in.go | 12 --- cl/_testdata/async/out.ll | 210 -------------------------------------- cl/compile_test.go | 2 +- ssa/cl_test.go | 2 +- 4 files changed, 2 insertions(+), 224 deletions(-) diff --git a/cl/_testdata/async/in.go b/cl/_testdata/async/in.go index a59eec6c..d83cdae8 100644 --- a/cl/_testdata/async/in.go +++ b/cl/_testdata/async/in.go @@ -1,8 +1,6 @@ package async import ( - "fmt" - "github.com/goplus/llgo/x/async" ) @@ -27,13 +25,3 @@ func UseGenInts() int { } return r } - -func GenIntsWithDefer() (co *async.Promise[int]) { - defer func() { - if r := recover(); r != nil { - fmt.Println("panic:", r) - } - }() - co.Yield(1) - panic("GenIntsWithDefer") -} diff --git a/cl/_testdata/async/out.ll b/cl/_testdata/async/out.ll index c6c0f612..9aff8cda 100644 --- a/cl/_testdata/async/out.ll +++ b/cl/_testdata/async/out.ll @@ -1,18 +1,9 @@ ; ModuleID = 'async' source_filename = "async" -%"github.com/goplus/llgo/internal/runtime.Defer" = type { ptr, i64, ptr, ptr, ptr } -%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 } -%"github.com/goplus/llgo/internal/runtime.eface" = type { ptr, ptr } -%"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 } -%"github.com/goplus/llgo/internal/runtime.iface" = type { ptr, ptr } %"github.com/goplus/llgo/x/async.Promise[int]" = type { ptr, i64 } @"async.init$guard" = global i1 false, align 1 -@__llgo_defer = linkonce global i32 0, align 4 -@0 = private unnamed_addr constant [16 x i8] c"GenIntsWithDefer", align 1 -@_llgo_string = linkonce global ptr null, align 8 -@1 = private unnamed_addr constant [6 x i8] c"panic:", align 1 define ptr @async.GenInts() presplitcoroutine { entry: @@ -73,155 +64,6 @@ _llgo_8: ; preds = %_llgo_7 ] } -define ptr @async.GenIntsWithDefer() presplitcoroutine { -entry: - %promise = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 16) - %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null) - %need.dyn.alloc = call i1 @llvm.coro.alloc(token %id) - br i1 %need.dyn.alloc, label %alloc, label %_llgo_5 - -alloc: ; preds = %entry - %frame.size = call i64 @llvm.coro.size.i64() - %frame = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 %frame.size) - br label %_llgo_5 - -clean: ; preds = %_llgo_6, %_llgo_9 - %0 = call ptr @llvm.coro.free(token %id, ptr %hdl) - br label %suspend - -suspend: ; preds = %_llgo_6, %_llgo_9, %clean - %1 = call i1 @llvm.coro.end(ptr %hdl, i1 false, token none) - ret ptr %promise - -trap: ; preds = %_llgo_6 - call void @llvm.trap() - unreachable - -_llgo_5: ; preds = %alloc, %entry - %frame1 = phi ptr [ null, %entry ], [ %frame, %alloc ] - %hdl = call ptr @llvm.coro.begin(token %id, ptr %frame1) - store ptr %hdl, ptr %promise, align 8 - %2 = alloca ptr, align 8 - %3 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %2, i64 8) - %4 = load i32, ptr @__llgo_defer, align 4 - %5 = call ptr @pthread_getspecific(i32 %4) - %6 = alloca i8, i64 196, align 1 - %7 = alloca i8, i64 40, align 1 - %8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %7, i32 0, i32 0 - store ptr %6, ptr %8, align 8 - %9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %7, i32 0, i32 1 - store i64 0, ptr %9, align 4 - %10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %7, i32 0, i32 2 - store ptr %5, ptr %10, align 8 - %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %7, i32 0, i32 3 - store ptr blockaddress(@async.GenIntsWithDefer, %_llgo_7), ptr %11, align 8 - %12 = call i32 @pthread_setspecific(i32 %4, ptr %7) - %13 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %7, i32 0, i32 1 - %14 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %7, i32 0, i32 3 - %15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %7, i32 0, i32 4 - %16 = call i32 @sigsetjmp(ptr %6, i32 0) - %17 = icmp eq i32 %16, 0 - br i1 %17, label %_llgo_9, label %_llgo_10 - -_llgo_6: ; preds = %_llgo_9, %_llgo_8 - %18 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %19 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %18, i32 0, i32 0 - store ptr @0, ptr %19, align 8 - %20 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %18, i32 0, i32 1 - store i64 16, ptr %20, align 4 - %21 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %18, align 8 - %22 = load ptr, ptr @_llgo_string, align 8 - %23 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) - store %"github.com/goplus/llgo/internal/runtime.String" %21, ptr %23, align 8 - %24 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 - %25 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %24, i32 0, i32 0 - store ptr %22, ptr %25, align 8 - %26 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %24, i32 0, i32 1 - store ptr %23, ptr %26, align 8 - %27 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %24, align 8 - call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %27) - unreachable - %28 = load ptr, ptr %3, align 8 - %29 = call i8 @llvm.coro.suspend(token %id, i1 true) - switch i8 %29, label %suspend [ - i8 0, label %trap - i8 1, label %clean - ] - -_llgo_7: ; preds = %_llgo_10 - store ptr blockaddress(@async.GenIntsWithDefer, %_llgo_8), ptr %14, align 8 - %30 = load i64, ptr %13, align 4 - call void @"async.GenIntsWithDefer$1"() - %31 = load %"github.com/goplus/llgo/internal/runtime.Defer", ptr %7, align 8 - %32 = extractvalue %"github.com/goplus/llgo/internal/runtime.Defer" %31, 2 - %33 = call i32 @pthread_setspecific(i32 %4, ptr %32) - %34 = load ptr, ptr %15, align 8 - indirectbr ptr %34, [label %_llgo_8] - -_llgo_8: ; preds = %_llgo_10, %_llgo_7 - call void @"github.com/goplus/llgo/internal/runtime.Rethrow"(ptr %5) - br label %_llgo_6 - -_llgo_9: ; preds = %_llgo_5 - %35 = load ptr, ptr %3, align 8 - call void @"github.com/goplus/llgo/x/async.(*Promise).setValue[int]"(ptr %promise, i64 1) - %36 = call i8 @llvm.coro.suspend(token %id, i1 false) - switch i8 %36, label %suspend [ - i8 0, label %_llgo_6 - i8 1, label %clean - ] - -_llgo_10: ; preds = %_llgo_5 - store ptr blockaddress(@async.GenIntsWithDefer, %_llgo_8), ptr %15, align 8 - %37 = load ptr, ptr %14, align 8 - indirectbr ptr %37, [label %_llgo_8, label %_llgo_7] - -_llgo_11: ; No predecessors! -} - -define void @"async.GenIntsWithDefer$1"() { -_llgo_0: - %0 = call %"github.com/goplus/llgo/internal/runtime.eface" @"github.com/goplus/llgo/internal/runtime.Recover"() - %1 = call i1 @"github.com/goplus/llgo/internal/runtime.EfaceEqual"(%"github.com/goplus/llgo/internal/runtime.eface" %0, %"github.com/goplus/llgo/internal/runtime.eface" zeroinitializer) - %2 = xor i1 %1, true - br i1 %2, label %_llgo_1, label %_llgo_2 - -_llgo_1: ; preds = %_llgo_0 - %3 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32) - %4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %3, i64 0 - %5 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %5, i32 0, i32 0 - store ptr @1, ptr %6, align 8 - %7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %5, i32 0, i32 1 - store i64 6, ptr %7, align 4 - %8 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %5, align 8 - %9 = load ptr, ptr @_llgo_string, align 8 - %10 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) - store %"github.com/goplus/llgo/internal/runtime.String" %8, ptr %10, align 8 - %11 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 - %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %11, i32 0, i32 0 - store ptr %9, ptr %12, align 8 - %13 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %11, i32 0, i32 1 - store ptr %10, ptr %13, align 8 - %14 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %11, align 8 - store %"github.com/goplus/llgo/internal/runtime.eface" %14, ptr %4, align 8 - %15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %3, i64 1 - store %"github.com/goplus/llgo/internal/runtime.eface" %0, ptr %15, align 8 - %16 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 - %17 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %16, i32 0, i32 0 - store ptr %3, ptr %17, align 8 - %18 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %16, i32 0, i32 1 - store i64 2, ptr %18, align 4 - %19 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %16, i32 0, i32 2 - store i64 2, ptr %19, align 4 - %20 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %16, align 8 - %21 = call { i64, %"github.com/goplus/llgo/internal/runtime.iface" } @fmt.Println(%"github.com/goplus/llgo/internal/runtime.Slice" %20) - br label %_llgo_2 - -_llgo_2: ; preds = %_llgo_1, %_llgo_0 - ret void -} - define i64 @async.UseGenInts() { _llgo_0: %0 = call ptr @async.WrapGenInts() @@ -285,8 +127,6 @@ _llgo_0: _llgo_1: ; preds = %_llgo_0 store i1 true, ptr @"async.init$guard", align 1 - call void @fmt.init() - call void @"async.init$after"() br label %_llgo_2 _llgo_2: ; preds = %_llgo_1, %_llgo_0 @@ -326,52 +166,6 @@ _llgo_0: ; Function Attrs: nounwind declare i8 @llvm.coro.suspend(token, i1) -declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64) - -declare ptr @pthread_getspecific(i32) - -declare i32 @pthread_setspecific(i32, ptr) - -declare i32 @sigsetjmp(ptr, i32) - -declare void @"github.com/goplus/llgo/internal/runtime.Rethrow"(ptr) - -define void @"async.init$after"() { -_llgo_0: - %0 = load ptr, ptr @_llgo_string, align 8 - %1 = icmp eq ptr %0, null - br i1 %1, label %_llgo_1, label %_llgo_2 - -_llgo_1: ; preds = %_llgo_0 - %2 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) - store ptr %2, ptr @_llgo_string, align 8 - br label %_llgo_2 - -_llgo_2: ; preds = %_llgo_1, %_llgo_0 - %3 = load i32, ptr @__llgo_defer, align 4 - %4 = icmp eq i32 %3, 0 - br i1 %4, label %_llgo_3, label %_llgo_4 - -_llgo_3: ; preds = %_llgo_2 - %5 = call i32 @pthread_key_create(ptr @__llgo_defer, ptr null) - br label %_llgo_4 - -_llgo_4: ; preds = %_llgo_3, %_llgo_2 - ret void -} - -declare ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64) - -declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64) - -declare void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface") - -declare %"github.com/goplus/llgo/internal/runtime.eface" @"github.com/goplus/llgo/internal/runtime.Recover"() - -declare i1 @"github.com/goplus/llgo/internal/runtime.EfaceEqual"(%"github.com/goplus/llgo/internal/runtime.eface", %"github.com/goplus/llgo/internal/runtime.eface") - -declare { i64, %"github.com/goplus/llgo/internal/runtime.iface" } @fmt.Println(%"github.com/goplus/llgo/internal/runtime.Slice") - define i1 @"github.com/goplus/llgo/x/async.(*Promise).Done[int]"(ptr %0) { _llgo_0: %1 = getelementptr inbounds %"github.com/goplus/llgo/x/async.Promise[int]", ptr %0, i32 0, i32 0 @@ -398,12 +192,8 @@ _llgo_0: ret void } -declare void @fmt.init() - ; Function Attrs: nounwind memory(argmem: readwrite) declare i1 @llvm.coro.done(ptr nocapture readonly) declare void @llvm.coro.resume(ptr) -declare i32 @pthread_key_create(ptr, ptr) - diff --git a/cl/compile_test.go b/cl/compile_test.go index b1942b80..1bdd3ac1 100644 --- a/cl/compile_test.go +++ b/cl/compile_test.go @@ -53,7 +53,7 @@ func TestFromTestrt(t *testing.T) { } func TestFromTestdata(t *testing.T) { - cltest.FromDir(t, "", "./_testdata", false) + cltest.FromDir(t, "", "./_testdata", true) } func TestFromTestpymath(t *testing.T) { diff --git a/ssa/cl_test.go b/ssa/cl_test.go index 837a990a..4ba7132d 100644 --- a/ssa/cl_test.go +++ b/ssa/cl_test.go @@ -50,7 +50,7 @@ func TestFromTestrt(t *testing.T) { } func TestFromTestdata(t *testing.T) { - cltest.FromDir(t, "", "../cl/_testdata", false) + cltest.FromDir(t, "", "../cl/_testdata", true) } func TestMakeInterface(t *testing.T) {