Merge pull request #837 from cpunion/const-conv

ssa: fix int constant type conversion
This commit is contained in:
xushiwei
2024-10-23 10:58:08 +08:00
committed by GitHub
3 changed files with 56 additions and 3 deletions

View File

@@ -223,15 +223,15 @@ func (b Builder) Const(v constant.Value, typ Type) Expr {
case kind == types.Bool:
return Expr{prog.BoolVal(constant.BoolVal(v)).impl, typ}
case kind >= types.Int && kind <= types.Int64:
if v, exact := constant.Int64Val(v); exact {
if v, exact := constant.Int64Val(constant.ToInt(v)); exact {
return prog.IntVal(uint64(v), typ)
}
case kind >= types.Uint && kind <= types.Uintptr:
if v, exact := constant.Uint64Val(v); exact {
if v, exact := constant.Uint64Val(constant.ToInt(v)); exact {
return prog.IntVal(v, typ)
}
case kind == types.Float64 || kind == types.Float32:
v, _ := constant.Float64Val(v)
v, _ := constant.Float64Val(constant.ToFloat(v))
return prog.FloatVal(v, typ)
case kind == types.String:
return Expr{b.Str(constant.StringVal(v)).impl, typ}