Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssa: fix cvtType check types.Alias #955

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/ssa/abitype.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package ssa
import (
"go/token"
"go/types"
"unsafe"

"github.com/goplus/llgo/compiler/ssa/abi"
"github.com/goplus/llvm"
Expand Down Expand Up @@ -248,7 +249,7 @@ func (b Builder) abiNamedInterfaceOf(t *types.Named) func() Expr {
}

func (b Builder) sizeof(t types.Type) int64 {
sizes := (*goProgram)(b.Prog)
sizes := (*goProgram)(unsafe.Pointer(b.Prog))
return sizes.Sizeof(t)
}

Expand Down Expand Up @@ -332,7 +333,7 @@ func (b Builder) abiChanOf(t *types.Chan) func() Expr {
func (b Builder) abiMapOf(t *types.Map) func() Expr {
key := b.abiTypeOf(t.Key())
elem := b.abiTypeOf(t.Elem())
sizes := (*goProgram)(b.Prog)
sizes := (*goProgram)(unsafe.Pointer(b.Prog))
bucket := b.abiTypeOf(abi.MapBucketType(t, sizes))
flags := abi.MapTypeFlags(t, sizes)
return func() Expr {
Expand Down
7 changes: 4 additions & 3 deletions compiler/ssa/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package ssa
import (
"fmt"
"go/types"
"unsafe"

"github.com/goplus/llgo/compiler/ssa/abi"
"github.com/goplus/llvm"
Expand Down Expand Up @@ -96,7 +97,7 @@ func (p *goProgram) Alignof(T types.Type) int64 {
// Offsetsof must implement the offset guarantees required by the spec.
// A negative entry in the result indicates that the struct is too large.
func (p *goProgram) Offsetsof(fields []*types.Var) (ret []int64) {
prog := Program(p)
prog := Program(unsafe.Pointer(p))
ptrSize := int64(prog.PointerSize())
extra := int64(0)
ret = p.sizes.Offsetsof(fields)
Expand All @@ -111,7 +112,7 @@ func (p *goProgram) Offsetsof(fields []*types.Var) (ret []int64) {
// Sizeof must implement the size guarantees required by the spec.
// A negative result indicates that T is too large.
func (p *goProgram) Sizeof(T types.Type) int64 {
prog := Program(p)
prog := Program(unsafe.Pointer(p))
ptrSize := int64(prog.PointerSize())
baseSize := prog.sizes.Sizeof(T) + p.extraSize(T, ptrSize)
switch T.Underlying().(type) {
Expand Down Expand Up @@ -171,7 +172,7 @@ func (t Type) RawType() types.Type {
// TypeSizes returns the sizes of the types.
func (p Program) TypeSizes(sizes types.Sizes) types.Sizes {
p.sizes = sizes
return (*goProgram)(p)
return (*goProgram)(unsafe.Pointer(p))
}

// TODO(xsw):
Expand Down
2 changes: 1 addition & 1 deletion compiler/ssa/type_cvt.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
case *types.TypeParam:
return typ.Underlying(), false
case *types.Alias:
return types.Unalias(t), true
return p.cvtType(types.Unalias(t))

Check warning on line 119 in compiler/ssa/type_cvt.go

View check run for this annotation

Codecov / codecov/patch

compiler/ssa/type_cvt.go#L119

Added line #L119 was not covered by tests
default:
panic(fmt.Sprintf("cvtType: unexpected type - %T", typ))
}
Expand Down
Loading