TestCvtCType
This commit is contained in:
19
cl/_testrt/cvar/in.go
Normal file
19
cl/_testrt/cvar/in.go
Normal file
@@ -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
|
||||
}
|
||||
30
cl/_testrt/cvar/out.ll
Normal file
30
cl/_testrt/cvar/out.ll
Normal file
@@ -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"()
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user