diff --git a/cl/_testdata/untyped/in.go b/cl/_testdata/untyped/in.go new file mode 100644 index 00000000..7bccf8d6 --- /dev/null +++ b/cl/_testdata/untyped/in.go @@ -0,0 +1,11 @@ +package main + +const c = 100 + +var a float64 = 1 + +func main() { + if c > 100 { + a = 0 + } +} diff --git a/cl/_testdata/untyped/out.ll b/cl/_testdata/untyped/out.ll new file mode 100644 index 00000000..fd8b4d8e --- /dev/null +++ b/cl/_testdata/untyped/out.ll @@ -0,0 +1,32 @@ +; ModuleID = 'main' +source_filename = "main" + +@main.a = global ptr null +@"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 + store double 1.000000e+00, ptr @main.a, align 8 + br label %_llgo_2 + +_llgo_2: ; preds = %_llgo_1, %_llgo_0 + ret void +} + +define void @main() { +_llgo_0: + call void @main.init() + br i1 false, label %_llgo_1, label %_llgo_2 + +_llgo_1: ; preds = %_llgo_0 + store double 0.000000e+00, ptr @main.a, align 8 + br label %_llgo_2 + +_llgo_2: ; preds = %_llgo_1, %_llgo_0 + ret void +} diff --git a/cl/compile.go b/cl/compile.go index fbaace4d..7bbca572 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -484,7 +484,7 @@ func (p *context) compileValue(b llssa.Builder, v ssa.Value) llssa.Expr { g := p.varOf(v) return g.Expr case *ssa.Const: - t := v.Type() + t := types.Default(v.Type()) return b.Const(v.Value, p.prog.Type(t)) } panic(fmt.Sprintf("compileValue: unknown value - %T\n", v)) diff --git a/ssa/expr.go b/ssa/expr.go index 5f533ae5..c6010e1e 100644 --- a/ssa/expr.go +++ b/ssa/expr.go @@ -140,7 +140,7 @@ func (b Builder) Const(v constant.Value, typ Type) Expr { if v == nil { return prog.Null(typ) } - switch t := types.Default(typ.t).(type) { + switch t := typ.t.(type) { case *types.Basic: kind := t.Kind() switch { diff --git a/ssa/type.go b/ssa/type.go index 27ba2faa..aef4c354 100644 --- a/ssa/type.go +++ b/ssa/type.go @@ -212,7 +212,7 @@ func (p Program) tyInt64() llvm.Type { } func (p Program) toLLVMType(typ types.Type) Type { - switch t := types.Default(typ).(type) { + switch t := typ.(type) { case *types.Basic: switch t.Kind() { case types.Int: