runtime.Rethrow fix; llgo/ssa: IndirectJump fix

This commit is contained in:
xushiwei
2024-06-12 20:53:30 +08:00
parent d500902eff
commit 42a5c60af6
13 changed files with 555 additions and 237 deletions

View File

@@ -133,7 +133,7 @@ _llgo_5: ; preds = %_llgo_2
%23 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %21, i32 0, i32 1
store ptr %20, ptr %23, align 8
%24 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %21, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %24)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %24)
unreachable
}
@@ -172,6 +172,6 @@ declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64)
declare void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface")
declare void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface")
declare i32 @printf(ptr, ...)

View File

@@ -2,7 +2,7 @@
source_filename = "main"
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
%"github.com/goplus/llgo/internal/runtime.Defer" = type { i64, ptr, i64 }
%"github.com/goplus/llgo/internal/runtime.Defer" = type { ptr, i64, ptr, ptr }
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@@ -41,109 +41,123 @@ _llgo_0:
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
%2 = load ptr, ptr @__llgo_defer, align 8
%3 = call ptr @pthread_getspecific(ptr %2)
%4 = alloca i8, i64 24, align 1
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 0
store i64 0, ptr %5, align 4
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 1
store ptr %3, ptr %6, align 8
%7 = call i32 @pthread_setspecific(ptr %2, ptr %4)
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 0
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, i32 0, i32 2
%10 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %10, i32 0, i32 0
store ptr @0, ptr %11, align 8
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %10, i32 0, i32 1
store i64 5, ptr %12, align 4
%13 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %10, align 8
%14 = call i1 @main.f(%"github.com/goplus/llgo/internal/runtime.String" %13)
br i1 %14, label %_llgo_2, label %_llgo_3
%2 = load i32, ptr @__llgo_defer, align 4
%3 = call ptr @pthread_getspecific(i32 %2)
%4 = alloca i8, i64 196, align 1
%5 = alloca i8, i64 32, align 1
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %5, i32 0, i32 0
store ptr %4, ptr %6, align 8
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %5, i32 0, i32 1
store i64 0, ptr %7, align 4
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %5, i32 0, i32 2
store ptr %3, ptr %8, align 8
%9 = call i32 @pthread_setspecific(i32 %2, ptr %5)
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %5, i32 0, i32 1
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %5, i32 0, i32 3
%12 = call i32 @sigsetjmp(ptr %4, i32 0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %_llgo_6, label %_llgo_7
_llgo_1: ; No predecessors!
ret i32 0
_llgo_2: ; preds = %_llgo_0
%15 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%16 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %15, i32 0, i32 0
store ptr @1, ptr %16, align 8
%17 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %15, i32 0, i32 1
store i64 5, ptr %17, align 4
%18 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %15, align 8
%19 = load i64, ptr %8, align 4
%20 = or i64 %19, 1
store i64 %20, ptr %8, align 4
%21 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %21, i32 0, i32 0
store ptr @2, ptr %22, align 8
%23 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %21, i32 0, i32 1
store i64 3, ptr %23, align 4
%24 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %21, align 8
%25 = load i64, ptr %8, align 4
%26 = or i64 %25, 2
store i64 %26, ptr %8, align 4
store i64 0, ptr %9, align 4
_llgo_2: ; preds = %_llgo_6
%14 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %14, i32 0, i32 0
store ptr @1, ptr %15, align 8
%16 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %14, i32 0, i32 1
store i64 5, ptr %16, align 4
%17 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %14, align 8
%18 = load i64, ptr %10, align 4
%19 = or i64 %18, 1
store i64 %19, ptr %10, align 4
%20 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%21 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %20, i32 0, i32 0
store ptr @2, ptr %21, align 8
%22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %20, i32 0, i32 1
store i64 3, ptr %22, align 4
%23 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %20, align 8
%24 = load i64, ptr %10, align 4
%25 = or i64 %24, 2
store i64 %25, ptr %10, align 4
store ptr blockaddress(@main, %_llgo_8), ptr %11, align 8
br label %_llgo_4
_llgo_3: ; preds = %_llgo_0
%27 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%28 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %27, i32 0, i32 0
store ptr @3, ptr %28, align 8
%29 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %27, i32 0, i32 1
store i64 5, ptr %29, align 4
%30 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %27, align 8
%31 = load i64, ptr %8, align 4
%32 = or i64 %31, 4
store i64 %32, ptr %8, align 4
store i64 1, ptr %9, align 4
_llgo_3: ; preds = %_llgo_6
%26 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%27 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %26, i32 0, i32 0
store ptr @3, ptr %27, align 8
%28 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %26, i32 0, i32 1
store i64 5, ptr %28, align 4
%29 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %26, align 8
%30 = load i64, ptr %10, align 4
%31 = or i64 %30, 4
store i64 %31, ptr %10, align 4
store ptr blockaddress(@main, %_llgo_9), ptr %11, align 8
br label %_llgo_4
_llgo_4: ; preds = %_llgo_3, %_llgo_2
%33 = load i64, ptr %8, align 4
%34 = and i64 %33, 4
%35 = icmp ne i64 %34, 0
br i1 %35, label %_llgo_7, label %_llgo_8
_llgo_4: ; preds = %_llgo_3, %_llgo_2, %_llgo_7
%32 = load i64, ptr %10, align 4
%33 = and i64 %32, 4
%34 = icmp ne i64 %33, 0
br i1 %34, label %_llgo_10, label %_llgo_11
_llgo_5: ; preds = %_llgo_12
_llgo_5: ; preds = %_llgo_15
call void @"github.com/goplus/llgo/internal/runtime.Rethrow"(ptr %3)
unreachable
_llgo_6: ; preds = %_llgo_0
%35 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%36 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %35, i32 0, i32 0
store ptr @0, ptr %36, align 8
%37 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %35, i32 0, i32 1
store i64 5, ptr %37, align 4
%38 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %35, align 8
%39 = call i1 @main.f(%"github.com/goplus/llgo/internal/runtime.String" %38)
br i1 %39, label %_llgo_2, label %_llgo_3
_llgo_7: ; preds = %_llgo_0
store ptr blockaddress(@main, %_llgo_5), ptr %11, align 8
br label %_llgo_4
_llgo_8: ; preds = %_llgo_15
ret i32 0
_llgo_6: ; preds = %_llgo_12
_llgo_9: ; preds = %_llgo_15
ret i32 0
_llgo_7: ; preds = %_llgo_4
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %30)
_llgo_10: ; preds = %_llgo_4
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %29)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
br label %_llgo_8
br label %_llgo_11
_llgo_8: ; preds = %_llgo_7, %_llgo_4
%36 = and i64 %33, 2
%37 = icmp ne i64 %36, 0
br i1 %37, label %_llgo_9, label %_llgo_10
_llgo_11: ; preds = %_llgo_10, %_llgo_4
%40 = and i64 %32, 2
%41 = icmp ne i64 %40, 0
br i1 %41, label %_llgo_12, label %_llgo_13
_llgo_9: ; preds = %_llgo_8
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %24)
_llgo_12: ; preds = %_llgo_11
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %23)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
br label %_llgo_10
br label %_llgo_13
_llgo_10: ; preds = %_llgo_9, %_llgo_8
%38 = and i64 %33, 1
%39 = icmp ne i64 %38, 0
br i1 %39, label %_llgo_11, label %_llgo_12
_llgo_13: ; preds = %_llgo_12, %_llgo_11
%42 = and i64 %32, 1
%43 = icmp ne i64 %42, 0
br i1 %43, label %_llgo_14, label %_llgo_15
_llgo_11: ; preds = %_llgo_10
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %18)
_llgo_14: ; preds = %_llgo_13
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %17)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
br label %_llgo_12
br label %_llgo_15
_llgo_12: ; preds = %_llgo_11, %_llgo_10
_llgo_15: ; preds = %_llgo_14, %_llgo_13
call void @"main.main$1"()
%40 = load %"github.com/goplus/llgo/internal/runtime.Defer", ptr %4, align 8
%41 = extractvalue %"github.com/goplus/llgo/internal/runtime.Defer" %40, 2
%42 = call i32 @pthread_setspecific(ptr %2, i64 %41)
%43 = load i64, ptr %9, align 4
switch i64 %43, label %_llgo_5 [
i64 1, label %_llgo_6
]
%44 = load %"github.com/goplus/llgo/internal/runtime.Defer", ptr %5, align 8
%45 = extractvalue %"github.com/goplus/llgo/internal/runtime.Defer" %44, 2
%46 = call i32 @pthread_setspecific(i32 %2, ptr %45)
%47 = load ptr, ptr %11, align 8
indirectbr ptr %47, [label %_llgo_5, label %_llgo_8, label %_llgo_9]
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()
@@ -165,14 +179,18 @@ 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)
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
define void @"main.init$after"() {
_llgo_0:
%0 = load ptr, ptr @__llgo_defer, align 8
%1 = icmp eq ptr %0, null
%0 = load i32, ptr @__llgo_defer, align 4
%1 = icmp eq i32 %0, 0
br i1 %1, label %_llgo_1, label %_llgo_2
_llgo_1: ; preds = %_llgo_0

View File

@@ -2,7 +2,7 @@
source_filename = "main"
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
%"github.com/goplus/llgo/internal/runtime.Defer" = type { i64, ptr, i64 }
%"github.com/goplus/llgo/internal/runtime.Defer" = type { ptr, i64, ptr, ptr }
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@@ -47,101 +47,115 @@ _llgo_0:
store i64 5, ptr %4, align 4
%5 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %2, align 8
%6 = call i1 @main.f(%"github.com/goplus/llgo/internal/runtime.String" %5)
%7 = load ptr, ptr @__llgo_defer, align 8
%8 = call ptr @pthread_getspecific(ptr %7)
%9 = alloca i8, i64 24, align 1
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %9, i32 0, i32 0
store i64 0, ptr %10, align 4
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %9, i32 0, i32 1
store ptr %8, ptr %11, align 8
%12 = call i32 @pthread_setspecific(ptr %7, ptr %9)
%13 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %9, i32 0, i32 0
%14 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %9, i32 0, i32 2
br i1 %6, label %_llgo_1, label %_llgo_2
%7 = load i32, ptr @__llgo_defer, align 4
%8 = call ptr @pthread_getspecific(i32 %7)
%9 = alloca i8, i64 196, align 1
%10 = alloca i8, i64 32, align 1
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %10, i32 0, i32 0
store ptr %9, ptr %11, align 8
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %10, i32 0, i32 1
store i64 0, ptr %12, align 4
%13 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %10, i32 0, i32 2
store ptr %8, ptr %13, align 8
%14 = call i32 @pthread_setspecific(i32 %7, ptr %10)
%15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %10, i32 0, i32 1
%16 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %10, i32 0, i32 3
%17 = call i32 @sigsetjmp(ptr %9, i32 0)
%18 = icmp eq i32 %17, 0
br i1 %18, label %_llgo_4, label %_llgo_7
_llgo_1: ; preds = %_llgo_0
%15 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%16 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %15, i32 0, i32 0
store ptr @1, ptr %16, align 8
%17 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %15, i32 0, i32 1
store i64 5, ptr %17, align 4
%18 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %15, align 8
%19 = load i64, ptr %13, align 4
%20 = or i64 %19, 1
store i64 %20, ptr %13, align 4
%21 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %21, i32 0, i32 0
store ptr @2, ptr %22, align 8
%23 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %21, i32 0, i32 1
store i64 3, ptr %23, align 4
%24 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %21, align 8
%25 = load i64, ptr %13, align 4
%26 = or i64 %25, 2
store i64 %26, ptr %13, align 4
store i64 0, ptr %14, align 4
br label %_llgo_4
_llgo_1: ; preds = %_llgo_4
%19 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%20 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %19, i32 0, i32 0
store ptr @1, ptr %20, align 8
%21 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %19, i32 0, i32 1
store i64 5, ptr %21, align 4
%22 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %19, align 8
%23 = load i64, ptr %15, align 4
%24 = or i64 %23, 1
store i64 %24, ptr %15, align 4
%25 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%26 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %25, i32 0, i32 0
store ptr @2, ptr %26, align 8
%27 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %25, i32 0, i32 1
store i64 3, ptr %27, align 4
%28 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %25, align 8
%29 = load i64, ptr %15, align 4
%30 = or i64 %29, 2
store i64 %30, ptr %15, align 4
store ptr blockaddress(@main, %_llgo_8), ptr %16, align 8
br label %_llgo_5
_llgo_2: ; preds = %_llgo_0
%27 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%28 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %27, i32 0, i32 0
store ptr @3, ptr %28, align 8
%29 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %27, i32 0, i32 1
store i64 5, ptr %29, align 4
%30 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %27, align 8
%31 = load i64, ptr %13, align 4
%32 = or i64 %31, 4
store i64 %32, ptr %13, align 4
store i64 1, ptr %14, align 4
br label %_llgo_4
_llgo_2: ; preds = %_llgo_4
%31 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%32 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %31, i32 0, i32 0
store ptr @3, ptr %32, align 8
%33 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %31, i32 0, i32 1
store i64 5, ptr %33, align 4
%34 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %31, align 8
%35 = load i64, ptr %15, align 4
%36 = or i64 %35, 4
store i64 %36, ptr %15, align 4
store ptr blockaddress(@main, %_llgo_9), ptr %16, align 8
br label %_llgo_5
_llgo_3: ; No predecessors!
ret i32 0
_llgo_4: ; preds = %_llgo_2, %_llgo_1
%33 = load i64, ptr %13, align 4
%34 = and i64 %33, 4
%35 = icmp ne i64 %34, 0
br i1 %35, label %_llgo_7, label %_llgo_8
_llgo_4: ; preds = %_llgo_0
br i1 %6, label %_llgo_1, label %_llgo_2
_llgo_5: ; preds = %_llgo_12
ret i32 0
_llgo_6: ; preds = %_llgo_12
ret i32 0
_llgo_7: ; preds = %_llgo_4
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %30)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
br label %_llgo_8
_llgo_8: ; preds = %_llgo_7, %_llgo_4
%36 = and i64 %33, 2
%37 = icmp ne i64 %36, 0
br i1 %37, label %_llgo_9, label %_llgo_10
_llgo_9: ; preds = %_llgo_8
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %24)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
br label %_llgo_10
_llgo_10: ; preds = %_llgo_9, %_llgo_8
%38 = and i64 %33, 1
_llgo_5: ; preds = %_llgo_2, %_llgo_1, %_llgo_7
%37 = load i64, ptr %15, align 4
%38 = and i64 %37, 4
%39 = icmp ne i64 %38, 0
br i1 %39, label %_llgo_11, label %_llgo_12
br i1 %39, label %_llgo_10, label %_llgo_11
_llgo_11: ; preds = %_llgo_10
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %18)
_llgo_6: ; preds = %_llgo_15
call void @"github.com/goplus/llgo/internal/runtime.Rethrow"(ptr %8)
unreachable
_llgo_7: ; preds = %_llgo_0
store ptr blockaddress(@main, %_llgo_6), ptr %16, align 8
br label %_llgo_5
_llgo_8: ; preds = %_llgo_15
ret i32 0
_llgo_9: ; preds = %_llgo_15
ret i32 0
_llgo_10: ; preds = %_llgo_5
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %34)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
br label %_llgo_12
br label %_llgo_11
_llgo_12: ; preds = %_llgo_11, %_llgo_10
%40 = load %"github.com/goplus/llgo/internal/runtime.Defer", ptr %9, align 8
%41 = extractvalue %"github.com/goplus/llgo/internal/runtime.Defer" %40, 2
%42 = call i32 @pthread_setspecific(ptr %7, i64 %41)
%43 = load i64, ptr %14, align 4
switch i64 %43, label %_llgo_5 [
i64 1, label %_llgo_6
]
_llgo_11: ; preds = %_llgo_10, %_llgo_5
%40 = and i64 %37, 2
%41 = icmp ne i64 %40, 0
br i1 %41, label %_llgo_12, label %_llgo_13
_llgo_12: ; preds = %_llgo_11
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %28)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
br label %_llgo_13
_llgo_13: ; preds = %_llgo_12, %_llgo_11
%42 = and i64 %37, 1
%43 = icmp ne i64 %42, 0
br i1 %43, label %_llgo_14, label %_llgo_15
_llgo_14: ; preds = %_llgo_13
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %22)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
br label %_llgo_15
_llgo_15: ; preds = %_llgo_14, %_llgo_13
%44 = load %"github.com/goplus/llgo/internal/runtime.Defer", ptr %10, align 8
%45 = extractvalue %"github.com/goplus/llgo/internal/runtime.Defer" %44, 2
%46 = call i32 @pthread_setspecific(i32 %7, ptr %45)
%47 = load ptr, ptr %16, align 8
indirectbr ptr %47, [label %_llgo_6, label %_llgo_8, label %_llgo_9]
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()
@@ -150,14 +164,18 @@ 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)
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
define void @"main.init$after"() {
_llgo_0:
%0 = load ptr, ptr @__llgo_defer, align 8
%1 = icmp eq ptr %0, null
%0 = load i32, ptr @__llgo_defer, align 4
%1 = icmp eq i32 %0, 0
br i1 %1, label %_llgo_1, label %_llgo_2
_llgo_1: ; preds = %_llgo_0

23
cl/_testgo/defer3/in.go Normal file
View File

@@ -0,0 +1,23 @@
package main
func f(s string) bool {
return len(s) > 2
}
func fail() {
defer println("bye")
panic("panic message")
}
func main() {
defer func() {
println("hi")
}()
if s := "hello"; f(s) {
defer println(s)
} else {
defer println("world")
return
}
fail()
}

271
cl/_testgo/defer3/out.ll Normal file
View File

@@ -0,0 +1,271 @@
; ModuleID = 'main'
source_filename = "main"
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
%"github.com/goplus/llgo/internal/runtime.Defer" = type { ptr, i64, ptr, ptr }
%"github.com/goplus/llgo/internal/runtime.eface" = type { ptr, ptr }
@"main.init$guard" = global ptr null
@0 = private unnamed_addr constant [4 x i8] c"bye\00", align 1
@__llgo_defer = linkonce global ptr null
@1 = private unnamed_addr constant [14 x i8] c"panic message\00", align 1
@_llgo_string = linkonce global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@2 = private unnamed_addr constant [6 x i8] c"hello\00", align 1
@3 = private unnamed_addr constant [6 x i8] c"hello\00", align 1
@4 = private unnamed_addr constant [6 x i8] c"world\00", align 1
@5 = private unnamed_addr constant [3 x i8] c"hi\00", align 1
define i1 @main.f(%"github.com/goplus/llgo/internal/runtime.String" %0) {
_llgo_0:
%1 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %0, 1
%2 = icmp sgt i64 %1, 2
ret i1 %2
}
define void @main.fail() {
_llgo_0:
%0 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%1 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %0, i32 0, i32 0
store ptr @0, ptr %1, align 8
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %0, i32 0, i32 1
store i64 3, ptr %2, align 4
%3 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %0, align 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 32, 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 = call i32 @pthread_setspecific(i32 %4, ptr %7)
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %7, i32 0, i32 1
%13 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %7, i32 0, i32 3
%14 = call i32 @sigsetjmp(ptr %6, i32 0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %_llgo_4, label %_llgo_5
_llgo_1: ; No predecessors!
ret void
_llgo_2: ; preds = %_llgo_5
%16 = load i64, ptr %12, align 4
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %3)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
%17 = load %"github.com/goplus/llgo/internal/runtime.Defer", ptr %7, align 8
%18 = extractvalue %"github.com/goplus/llgo/internal/runtime.Defer" %17, 2
%19 = call i32 @pthread_setspecific(i32 %4, ptr %18)
%20 = load ptr, ptr %13, align 8
indirectbr ptr %20, [label %_llgo_3]
_llgo_3: ; preds = %_llgo_2
call void @"github.com/goplus/llgo/internal/runtime.Rethrow"(ptr %5)
unreachable
_llgo_4: ; preds = %_llgo_0
%21 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %21, i32 0, i32 0
store ptr @1, ptr %22, align 8
%23 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %21, i32 0, i32 1
store i64 13, ptr %23, align 4
%24 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %21, align 8
%25 = load ptr, ptr @_llgo_string, align 8
%26 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16)
store %"github.com/goplus/llgo/internal/runtime.String" %24, ptr %26, align 8
%27 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8
%28 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %27, i32 0, i32 0
store ptr %25, ptr %28, align 8
%29 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %27, i32 0, i32 1
store ptr %26, ptr %29, align 8
%30 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %27, align 8
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %30)
unreachable
_llgo_5: ; preds = %_llgo_0
store ptr blockaddress(@main.fail, %_llgo_3), ptr %13, align 8
br label %_llgo_2
}
define void @main.init() {
_llgo_0:
%0 = load i1, ptr @"main.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"main.init$guard", align 1
call void @"main.init$after"()
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define i32 @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
%2 = load i32, ptr @__llgo_defer, align 4
%3 = call ptr @pthread_getspecific(i32 %2)
%4 = alloca i8, i64 196, align 1
%5 = alloca i8, i64 32, align 1
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %5, i32 0, i32 0
store ptr %4, ptr %6, align 8
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %5, i32 0, i32 1
store i64 0, ptr %7, align 4
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %5, i32 0, i32 2
store ptr %3, ptr %8, align 8
%9 = call i32 @pthread_setspecific(i32 %2, ptr %5)
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %5, i32 0, i32 1
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Defer", ptr %5, i32 0, i32 3
%12 = call i32 @sigsetjmp(ptr %4, i32 0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %_llgo_6, label %_llgo_7
_llgo_1: ; No predecessors!
ret i32 0
_llgo_2: ; preds = %_llgo_6
%14 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %14, i32 0, i32 0
store ptr @3, ptr %15, align 8
%16 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %14, i32 0, i32 1
store i64 5, ptr %16, align 4
%17 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %14, align 8
%18 = load i64, ptr %10, align 4
%19 = or i64 %18, 1
store i64 %19, ptr %10, align 4
call void @main.fail()
store ptr blockaddress(@main, %_llgo_8), ptr %11, align 8
br label %_llgo_4
_llgo_3: ; preds = %_llgo_6
%20 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%21 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %20, i32 0, i32 0
store ptr @4, ptr %21, align 8
%22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %20, i32 0, i32 1
store i64 5, ptr %22, align 4
%23 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %20, align 8
%24 = load i64, ptr %10, align 4
%25 = or i64 %24, 2
store i64 %25, ptr %10, align 4
store ptr blockaddress(@main, %_llgo_9), ptr %11, align 8
br label %_llgo_4
_llgo_4: ; preds = %_llgo_3, %_llgo_2, %_llgo_7
%26 = load i64, ptr %10, align 4
%27 = and i64 %26, 2
%28 = icmp ne i64 %27, 0
br i1 %28, label %_llgo_10, label %_llgo_11
_llgo_5: ; preds = %_llgo_13
call void @"github.com/goplus/llgo/internal/runtime.Rethrow"(ptr %3)
unreachable
_llgo_6: ; preds = %_llgo_0
%29 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%30 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %29, i32 0, i32 0
store ptr @2, ptr %30, align 8
%31 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %29, i32 0, i32 1
store i64 5, ptr %31, align 4
%32 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %29, align 8
%33 = call i1 @main.f(%"github.com/goplus/llgo/internal/runtime.String" %32)
br i1 %33, label %_llgo_2, label %_llgo_3
_llgo_7: ; preds = %_llgo_0
store ptr blockaddress(@main, %_llgo_5), ptr %11, align 8
br label %_llgo_4
_llgo_8: ; preds = %_llgo_13
ret i32 0
_llgo_9: ; preds = %_llgo_13
ret i32 0
_llgo_10: ; preds = %_llgo_4
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %23)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
br label %_llgo_11
_llgo_11: ; preds = %_llgo_10, %_llgo_4
%34 = and i64 %26, 1
%35 = icmp ne i64 %34, 0
br i1 %35, label %_llgo_12, label %_llgo_13
_llgo_12: ; preds = %_llgo_11
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %17)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
br label %_llgo_13
_llgo_13: ; preds = %_llgo_12, %_llgo_11
call void @"main.main$1"()
%36 = load %"github.com/goplus/llgo/internal/runtime.Defer", ptr %5, align 8
%37 = extractvalue %"github.com/goplus/llgo/internal/runtime.Defer" %36, 2
%38 = call i32 @pthread_setspecific(i32 %2, ptr %37)
%39 = load ptr, ptr %11, align 8
indirectbr ptr %39, [label %_llgo_5, label %_llgo_8, label %_llgo_9]
}
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 @"main.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 void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
declare void @"github.com/goplus/llgo/internal/runtime.init"()
define void @"main.main$1"() {
_llgo_0:
%0 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%1 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %0, i32 0, i32 0
store ptr @5, ptr %1, align 8
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %0, i32 0, i32 1
store i64 2, ptr %2, align 4
%3 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %0, align 8
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %3)
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
ret void
}
declare i32 @pthread_key_create(ptr, ptr)

View File

@@ -394,7 +394,7 @@ _llgo_2: ; preds = %_llgo_0
%129 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %127, i32 0, i32 1
store ptr %126, ptr %129, align 8
%130 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %127, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %130)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %130)
unreachable
_llgo_3: ; preds = %_llgo_1
@@ -426,7 +426,7 @@ _llgo_4: ; preds = %_llgo_1
%147 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %145, i32 0, i32 1
store ptr %144, ptr %147, align 8
%148 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %145, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %148)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %148)
unreachable
_llgo_5: ; preds = %_llgo_3
@@ -459,7 +459,7 @@ _llgo_6: ; preds = %_llgo_3
%164 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %162, i32 0, i32 1
store ptr %161, ptr %164, align 8
%165 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %162, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %165)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %165)
unreachable
}
@@ -1184,4 +1184,4 @@ declare void @"github.com/goplus/llgo/internal/runtime.PrintIface"(%"github.com/
declare i1 @"github.com/goplus/llgo/internal/runtime.Implements"(ptr, ptr)
declare void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface")
declare void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface")

View File

@@ -44,7 +44,7 @@ _llgo_2: ; preds = %_llgo_0
%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
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %14)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %14)
unreachable
}
@@ -77,7 +77,7 @@ _llgo_2: ; preds = %_llgo_0
%15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %13, i32 0, i32 1
store ptr %12, ptr %15, align 8
%16 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %13, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %16)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %16)
unreachable
}
@@ -177,7 +177,7 @@ declare ptr @"github.com/goplus/llgo/internal/runtime.PointerTo"(ptr)
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64)
declare void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface")
declare void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface")
declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -44,7 +44,7 @@ _llgo_1: ; preds = %_llgo_0
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1
store ptr %9, ptr %12, align 8
%13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
unreachable
_llgo_2: ; preds = %_llgo_0
@@ -73,7 +73,7 @@ _llgo_1: ; preds = %_llgo_0
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1
store ptr %9, ptr %12, align 8
%13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
unreachable
_llgo_2: ; preds = %_llgo_0
@@ -102,7 +102,7 @@ _llgo_1: ; preds = %_llgo_0
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1
store ptr %9, ptr %12, align 8
%13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
unreachable
_llgo_2: ; preds = %_llgo_0
@@ -131,7 +131,7 @@ _llgo_1: ; preds = %_llgo_0
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1
store ptr %9, ptr %12, align 8
%13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
unreachable
_llgo_2: ; preds = %_llgo_0
@@ -160,7 +160,7 @@ _llgo_1: ; preds = %_llgo_0
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1
store ptr %9, ptr %12, align 8
%13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
unreachable
_llgo_2: ; preds = %_llgo_0
@@ -189,7 +189,7 @@ _llgo_1: ; preds = %_llgo_0
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1
store ptr %9, ptr %12, align 8
%13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
unreachable
_llgo_2: ; preds = %_llgo_0
@@ -218,7 +218,7 @@ _llgo_1: ; preds = %_llgo_0
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1
store ptr %9, ptr %12, align 8
%13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
unreachable
_llgo_2: ; preds = %_llgo_0
@@ -247,7 +247,7 @@ _llgo_1: ; preds = %_llgo_0
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1
store ptr %9, ptr %12, align 8
%13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
unreachable
_llgo_2: ; preds = %_llgo_0
@@ -276,7 +276,7 @@ _llgo_1: ; preds = %_llgo_0
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1
store ptr %9, ptr %12, align 8
%13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
unreachable
_llgo_2: ; preds = %_llgo_0
@@ -305,7 +305,7 @@ _llgo_1: ; preds = %_llgo_0
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1
store ptr %9, ptr %12, align 8
%13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
unreachable
_llgo_2: ; preds = %_llgo_0
@@ -334,7 +334,7 @@ _llgo_1: ; preds = %_llgo_0
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1
store ptr %9, ptr %12, align 8
%13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
unreachable
_llgo_2: ; preds = %_llgo_0
@@ -363,7 +363,7 @@ _llgo_1: ; preds = %_llgo_0
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1
store ptr %9, ptr %12, align 8
%13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %13)
unreachable
_llgo_2: ; preds = %_llgo_0
@@ -387,7 +387,7 @@ _llgo_3: ; preds = %_llgo_2
%24 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %22, i32 0, i32 1
store ptr %21, ptr %24, align 8
%25 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %22, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %25)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %25)
unreachable
_llgo_4: ; preds = %_llgo_2
@@ -488,6 +488,6 @@ 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.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface")
declare void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface")
declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -45,7 +45,7 @@ _llgo_0:
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %8, i32 0, i32 1
store ptr %7, ptr %10, align 8
%11 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %8, align 8
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %11)
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %11)
unreachable
}
@@ -70,4 +70,4 @@ 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.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface")
declare void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface")

View File

@@ -48,6 +48,9 @@ func GoDeferData() Pointer
//go:linkname Unreachable llgo.unreachable
func Unreachable()
//go:linkname Exit C.exit
func Exit(Int)
//go:linkname AllocaSigjmpBuf llgo.sigjmpbuf
func AllocaSigjmpBuf() Pointer

View File

@@ -31,7 +31,7 @@ type Defer struct {
Addr unsafe.Pointer // sigjmpbuf
Bits uintptr
Link *Defer
Rund int // index of RunDefers
Rund unsafe.Pointer // block address after RunDefers
}
// Panic panics with a value.
@@ -49,8 +49,7 @@ func Rethrow(link *Defer) {
ptr := excepKey.Get()
TracePanic(*(*Eface)(ptr))
c.Free(ptr)
// TODO(xsw): noreturn
// c.Unreachable()
c.Exit(2)
} else {
c.Siglongjmp(link.Addr, 1)
}

View File

@@ -125,20 +125,21 @@ func (b Builder) excepKey() Expr {
return b.Load(b.Pkg.newKey(excepKey).Expr)
}
const (
// 0: addr sigjmpbuf
// 1: bits uintptr
// 2: link *Defer
// 3: rund voidptr
deferSigjmpbuf = iota
deferBits
deferLink
deferRund
)
func (b Builder) getDefer(kind DoAction) *aDefer {
self := b.Func
if self.defer_ == nil {
// TODO(xsw): check if in pkg.init
// 0: addr sigjmpbuf
// 1: bits uintptr
// 2: link *Defer
// 3: rund int
const (
deferSigjmpbuf = iota
deferBits
deferLink
deferRund
)
var next, rundBlk BasicBlock
if kind != DeferAlways {
b, next = self.deferInitBuilder()
@@ -173,11 +174,11 @@ func (b Builder) getDefer(kind DoAction) *aDefer {
}
b.If(b.BinOp(token.EQL, retval, czero), next, rundBlk)
b.SetBlockEx(rundBlk, AtEnd, false) // exec runDefers and rethrow
b.Store(rundPtr, prog.Val(0))
b.Store(rundPtr, rethrowBlk.Addr())
b.Jump(procBlk)
b.SetBlockEx(rethrowBlk, AtEnd, false) // rethrow
b.Call(b.Pkg.rtFunc("Rethrow"), b.Load(link))
b.Call(b.Pkg.rtFunc("Rethrow"), link)
b.Unreachable() // TODO: func supports noreturn attribute
if kind == DeferAlways {
@@ -231,14 +232,13 @@ func (b Builder) Defer(kind DoAction, fn Expr, args ...Expr) {
// RunDefers emits instructions to run deferred instructions.
func (b Builder) RunDefers() {
prog := b.Prog
self := b.getDefer(DeferInCond)
b.Store(self.rundPtr, prog.Val(len(self.runsNext)))
b.Jump(self.procBlk)
blk := b.Func.MakeBlock()
self.runsNext = append(self.runsNext, blk)
b.Store(self.rundPtr, blk.Addr())
b.Jump(self.procBlk)
b.SetBlockEx(blk, AtEnd, false)
b.blk.last = blk.last
}
@@ -259,9 +259,9 @@ func (p Function) endDefer(b Builder) {
stmts[i](bits)
}
link := b.getField(b.Load(self.data), 2)
link := b.getField(b.Load(self.data), deferLink)
b.pthreadSetspecific(self.key, link)
b.IndirectJump(self.rundPtr, nexts)
b.IndirectJump(b.Load(self.rundPtr), nexts)
}
// -----------------------------------------------------------------------------
@@ -288,24 +288,4 @@ func (b Builder) Panic(v Expr) {
b.Unreachable() // TODO: func supports noreturn attribute
}
/*
// Panic emits a panic instruction.
func (b Builder) Panic(v Expr) {
vimpl := v.impl
if debugInstr {
log.Printf("Panic %v\n", vimpl)
}
if v.kind != vkEface {
panic("Panic only accepts an any expression")
}
ptr := b.dupMalloc(v)
b.pthreadSetspecific(b.excepKey(), ptr)
}
func (b Builder) doPanic(v Expr) {
b.Call(b.Pkg.rtFunc("TracePanic"), v)
b.impl.CreateUnreachable()
}
*/
// -----------------------------------------------------------------------------

View File

@@ -48,6 +48,12 @@ func (p BasicBlock) Index() int {
return p.idx
}
// Addr returns the address of the basic block.
func (p BasicBlock) Addr() Expr {
fn := p.fn
return Expr{llvm.BlockAddress(fn.impl, p.first), fn.Prog.VoidPtr()}
}
// -----------------------------------------------------------------------------
type aBuilder struct {