From 91d012d33db9c60db5823d0ab52358282f4e3d05 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 3 May 2024 19:02:17 +0800 Subject: [PATCH] TestCvtCType --- cl/_testrt/cvar/in.go | 19 +++++++++++++++++++ cl/_testrt/cvar/out.ll | 30 ++++++++++++++++++++++++++++++ ssa/ssa_test.go | 17 +++++++++++++++++ ssa/type_c.go | 2 +- 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 cl/_testrt/cvar/in.go create mode 100644 cl/_testrt/cvar/out.ll diff --git a/cl/_testrt/cvar/in.go b/cl/_testrt/cvar/in.go new file mode 100644 index 00000000..7f99e7b0 --- /dev/null +++ b/cl/_testrt/cvar/in.go @@ -0,0 +1,19 @@ +package main + +import _ "unsafe" + +//go:linkname barX _bar_x +var barX struct { + Arr [16]int8 + Callbacks [2]func() +} + +//go:linkname barY _bar_y +var barY struct { + Arr [16]int8 +} + +func main() { + _ = barX + _ = barY +} diff --git a/cl/_testrt/cvar/out.ll b/cl/_testrt/cvar/out.ll new file mode 100644 index 00000000..0c10977a --- /dev/null +++ b/cl/_testrt/cvar/out.ll @@ -0,0 +1,30 @@ +; ModuleID = 'main' +source_filename = "main" + +@_bar_x = external global ptr +@_bar_y = external global ptr +@"main.init$guard" = global ptr null + +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 + br label %_llgo_2 + +_llgo_2: ; preds = %_llgo_1, %_llgo_0 + ret void +} + +define void @main() { +_llgo_0: + call void @"github.com/goplus/llgo/internal/runtime.init"() + call void @main.init() + %0 = load { [16 x i8], [2 x ptr] }, ptr @_bar_x, align 8 + %1 = load { [16 x i8] }, ptr @_bar_y, align 1 + ret void +} + +declare void @"github.com/goplus/llgo/internal/runtime.init"() diff --git a/ssa/ssa_test.go b/ssa/ssa_test.go index ff8c21c3..3ccbe147 100644 --- a/ssa/ssa_test.go +++ b/ssa/ssa_test.go @@ -30,6 +30,23 @@ func TestMakeInterface(t *testing.T) { } */ +func TestCvtCType(t *testing.T) { + test := func(typ types.Type) { + defer func() { + if r := recover(); r == nil { + t.Log("cvtCType: no error?") + } + }() + cvtCType(typ) + } + test(types.NewInterfaceType(nil, nil)) + + a := types.NewTypeName(0, nil, "a", nil) + sig := types.NewSignatureType(nil, nil, nil, nil, nil, false) + named := types.NewNamed(a, sig, nil) + test(named) +} + func TestCFuncPtr(t *testing.T) { sig := types.NewSignatureType(nil, nil, nil, nil, nil, false) csig := (*CFuncPtr)(sig) diff --git a/ssa/type_c.go b/ssa/type_c.go index 4dbe193d..045644fe 100644 --- a/ssa/type_c.go +++ b/ssa/type_c.go @@ -82,7 +82,7 @@ func cvtCType(typ types.Type) (types.Type, bool) { return cvtCStruct(t) case *types.Named: if _, cvt := cvtCType(t.Underlying()); cvt { - panic("todo: named type") + panic("don't define named type") } case *types.Signature: t = CFuncDecl(t)