Merge pull request #975 from visualfc/namedslice
compiler/cl: fix named slice type
This commit is contained in:
11
compiler/cl/_testrt/namedslice/in.go
Normal file
11
compiler/cl/_testrt/namedslice/in.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
type MyBytes []byte
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var i any = MyBytes{}
|
||||||
|
_, ok := i.(MyBytes)
|
||||||
|
if !ok {
|
||||||
|
panic("bad slice")
|
||||||
|
}
|
||||||
|
}
|
||||||
151
compiler/cl/_testrt/namedslice/out.ll
Normal file
151
compiler/cl/_testrt/namedslice/out.ll
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
; ModuleID = 'main'
|
||||||
|
source_filename = "main"
|
||||||
|
|
||||||
|
%"github.com/goplus/llgo/runtime/internal/runtime.Slice" = type { ptr, i64, i64 }
|
||||||
|
%"github.com/goplus/llgo/runtime/internal/runtime.eface" = type { ptr, ptr }
|
||||||
|
%"github.com/goplus/llgo/runtime/internal/runtime.String" = type { ptr, i64 }
|
||||||
|
|
||||||
|
@"main.init$guard" = global i1 false, align 1
|
||||||
|
@__llgo_argc = global i32 0, align 4
|
||||||
|
@__llgo_argv = global ptr null, align 8
|
||||||
|
@_llgo_main.MyBytes = linkonce global ptr null, align 8
|
||||||
|
@0 = private unnamed_addr constant [4 x i8] c"main", align 1
|
||||||
|
@1 = private unnamed_addr constant [7 x i8] c"MyBytes", align 1
|
||||||
|
@_llgo_byte = linkonce global ptr null, align 8
|
||||||
|
@"[]_llgo_byte" = linkonce global ptr null, align 8
|
||||||
|
@2 = private unnamed_addr constant [9 x i8] c"bad slice", align 1
|
||||||
|
@_llgo_string = linkonce global ptr null, align 8
|
||||||
|
|
||||||
|
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/runtime/internal/runtime.init"()
|
||||||
|
call void @main.init()
|
||||||
|
%2 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 0)
|
||||||
|
%3 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %2, 0
|
||||||
|
%4 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %3, i64 0, 1
|
||||||
|
%5 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %4, i64 0, 2
|
||||||
|
%6 = load ptr, ptr @_llgo_main.MyBytes, align 8
|
||||||
|
%7 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 24)
|
||||||
|
store %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %5, ptr %7, align 8
|
||||||
|
%8 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %6, 0
|
||||||
|
%9 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %8, ptr %7, 1
|
||||||
|
%10 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %9, 0
|
||||||
|
%11 = load ptr, ptr @_llgo_main.MyBytes, align 8
|
||||||
|
%12 = icmp eq ptr %10, %11
|
||||||
|
br i1 %12, label %_llgo_3, label %_llgo_4
|
||||||
|
|
||||||
|
_llgo_1: ; preds = %_llgo_5
|
||||||
|
%13 = load ptr, ptr @_llgo_string, align 8
|
||||||
|
%14 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||||
|
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @2, i64 9 }, ptr %14, align 8
|
||||||
|
%15 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %13, 0
|
||||||
|
%16 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %15, ptr %14, 1
|
||||||
|
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %16)
|
||||||
|
unreachable
|
||||||
|
|
||||||
|
_llgo_2: ; preds = %_llgo_5
|
||||||
|
ret i32 0
|
||||||
|
|
||||||
|
_llgo_3: ; preds = %_llgo_0
|
||||||
|
%17 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %9, 1
|
||||||
|
%18 = load %"github.com/goplus/llgo/runtime/internal/runtime.Slice", ptr %17, align 8
|
||||||
|
%19 = insertvalue { %"github.com/goplus/llgo/runtime/internal/runtime.Slice", i1 } undef, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %18, 0
|
||||||
|
%20 = insertvalue { %"github.com/goplus/llgo/runtime/internal/runtime.Slice", i1 } %19, i1 true, 1
|
||||||
|
br label %_llgo_5
|
||||||
|
|
||||||
|
_llgo_4: ; preds = %_llgo_0
|
||||||
|
br label %_llgo_5
|
||||||
|
|
||||||
|
_llgo_5: ; preds = %_llgo_4, %_llgo_3
|
||||||
|
%21 = phi { %"github.com/goplus/llgo/runtime/internal/runtime.Slice", i1 } [ %20, %_llgo_3 ], [ zeroinitializer, %_llgo_4 ]
|
||||||
|
%22 = extractvalue { %"github.com/goplus/llgo/runtime/internal/runtime.Slice", i1 } %21, 0
|
||||||
|
%23 = extractvalue { %"github.com/goplus/llgo/runtime/internal/runtime.Slice", i1 } %21, 1
|
||||||
|
br i1 %23, label %_llgo_2, label %_llgo_1
|
||||||
|
}
|
||||||
|
|
||||||
|
declare void @"github.com/goplus/llgo/runtime/internal/runtime.init"()
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64)
|
||||||
|
|
||||||
|
define void @"main.init$after"() {
|
||||||
|
_llgo_0:
|
||||||
|
%0 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamed"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 4 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 7 }, i64 23, i64 24, i64 0, i64 0)
|
||||||
|
%1 = load ptr, ptr @_llgo_main.MyBytes, align 8
|
||||||
|
%2 = icmp eq ptr %1, null
|
||||||
|
br i1 %2, label %_llgo_1, label %_llgo_2
|
||||||
|
|
||||||
|
_llgo_1: ; preds = %_llgo_0
|
||||||
|
store ptr %0, ptr @_llgo_main.MyBytes, align 8
|
||||||
|
br label %_llgo_2
|
||||||
|
|
||||||
|
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||||
|
%3 = load ptr, ptr @_llgo_byte, align 8
|
||||||
|
%4 = icmp eq ptr %3, null
|
||||||
|
br i1 %4, label %_llgo_3, label %_llgo_4
|
||||||
|
|
||||||
|
_llgo_3: ; preds = %_llgo_2
|
||||||
|
%5 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 40)
|
||||||
|
store ptr %5, ptr @_llgo_byte, align 8
|
||||||
|
br label %_llgo_4
|
||||||
|
|
||||||
|
_llgo_4: ; preds = %_llgo_3, %_llgo_2
|
||||||
|
%6 = load ptr, ptr @_llgo_byte, align 8
|
||||||
|
%7 = load ptr, ptr @"[]_llgo_byte", align 8
|
||||||
|
%8 = icmp eq ptr %7, null
|
||||||
|
br i1 %8, label %_llgo_5, label %_llgo_6
|
||||||
|
|
||||||
|
_llgo_5: ; preds = %_llgo_4
|
||||||
|
%9 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 40)
|
||||||
|
%10 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.SliceOf"(ptr %9)
|
||||||
|
store ptr %10, ptr @"[]_llgo_byte", align 8
|
||||||
|
br label %_llgo_6
|
||||||
|
|
||||||
|
_llgo_6: ; preds = %_llgo_5, %_llgo_4
|
||||||
|
%11 = load ptr, ptr @"[]_llgo_byte", align 8
|
||||||
|
br i1 %2, label %_llgo_7, label %_llgo_8
|
||||||
|
|
||||||
|
_llgo_7: ; preds = %_llgo_6
|
||||||
|
call void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamed"(ptr %0, ptr %11, { ptr, i64, i64 } zeroinitializer, { ptr, i64, i64 } zeroinitializer)
|
||||||
|
br label %_llgo_8
|
||||||
|
|
||||||
|
_llgo_8: ; preds = %_llgo_7, %_llgo_6
|
||||||
|
%12 = load ptr, ptr @_llgo_string, align 8
|
||||||
|
%13 = icmp eq ptr %12, null
|
||||||
|
br i1 %13, label %_llgo_9, label %_llgo_10
|
||||||
|
|
||||||
|
_llgo_9: ; preds = %_llgo_8
|
||||||
|
%14 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 24)
|
||||||
|
store ptr %14, ptr @_llgo_string, align 8
|
||||||
|
br label %_llgo_10
|
||||||
|
|
||||||
|
_llgo_10: ; preds = %_llgo_9, %_llgo_8
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamed"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.String", i64, i64, i64, i64)
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64)
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.SliceOf"(ptr)
|
||||||
|
|
||||||
|
declare void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamed"(ptr, ptr, %"github.com/goplus/llgo/runtime/internal/runtime.Slice", %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64)
|
||||||
|
|
||||||
|
declare void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface")
|
||||||
@@ -691,6 +691,7 @@ func (p *context) compileInstrOrValue(b llssa.Builder, iv instrOrValue, asValue
|
|||||||
max = p.compileValue(b, v.Max)
|
max = p.compileValue(b, v.Max)
|
||||||
}
|
}
|
||||||
ret = b.Slice(x, low, high, max)
|
ret = b.Slice(x, low, high, max)
|
||||||
|
ret.Type = b.Prog.Type(v.Type(), llssa.InGo)
|
||||||
case *ssa.MakeInterface:
|
case *ssa.MakeInterface:
|
||||||
if refs := *v.Referrers(); len(refs) == 1 {
|
if refs := *v.Referrers(); len(refs) == 1 {
|
||||||
switch ref := refs[0].(type) {
|
switch ref := refs[0].(type) {
|
||||||
|
|||||||
Reference in New Issue
Block a user