llgo/ssa: llvmSignature/castPtr/castInt bugfix; link: runtime

This commit is contained in:
xushiwei
2024-04-29 00:16:00 +08:00
parent 78d7f984d1
commit c30ed1b3c8
6 changed files with 715 additions and 27 deletions

View File

@@ -494,19 +494,37 @@ func (b Builder) Convert(t Type, x Expr) (ret Expr) {
kind := und.Kind()
switch {
case kind >= types.Int && kind <= types.Uintptr:
ret.impl = b.impl.CreateIntCast(x.impl, t.ll, "castInt")
ret.impl = castInt(b.impl, x.impl, t.ll)
return
case kind == types.UnsafePointer:
ret.impl = b.impl.CreatePointerCast(x.impl, t.ll, "castPtr")
ret.impl = castPtr(b.impl, x.impl, t.ll)
return
}
case *types.Pointer:
ret.impl = b.impl.CreatePointerCast(x.impl, t.ll, "castPtr")
ret.impl = castPtr(b.impl, x.impl, t.ll)
return
}
panic("todo")
}
func castInt(b llvm.Builder, x llvm.Value, t llvm.Type) llvm.Value {
xt := x.Type()
if xt.TypeKind() == llvm.PointerTypeKind {
return b.CreatePtrToInt(x, t, "ptr2int")
}
if xt.IntTypeWidth() <= t.IntTypeWidth() {
return b.CreateIntCast(x, t, "castInt")
}
return b.CreateTrunc(x, t, "truncInt")
}
func castPtr(b llvm.Builder, x llvm.Value, t llvm.Type) llvm.Value {
if x.Type().TypeKind() == llvm.PointerTypeKind {
return b.CreatePointerCast(x, t, "castPtr")
}
return b.CreateIntToPtr(x, t, "int2ptr")
}
// MakeInterface constructs an instance of an interface type from a
// value of a concrete type.
//