diff --git a/cl/_testgo/equal/in.go b/cl/_testgo/equal/in.go index 83663a70..9060898c 100644 --- a/cl/_testgo/equal/in.go +++ b/cl/_testgo/equal/in.go @@ -10,10 +10,15 @@ func init() { fn3 := func() { println(n) } var fn4 func() int assert(test != nil) + assert(nil != test) assert(fn1 != nil) + assert(nil != fn1) assert(fn2 != nil) + assert(nil != fn2) assert(fn3 != nil) + assert(nil != fn3) assert(fn4 == nil) + assert(nil == fn4) } // array diff --git a/cl/_testgo/equal/out.ll b/cl/_testgo/equal/out.ll index 2beb4cd3..abfde0a4 100644 --- a/cl/_testgo/equal/out.ll +++ b/cl/_testgo/equal/out.ll @@ -96,7 +96,15 @@ _llgo_0: call void @main.assert(i1 true) call void @main.assert(i1 true) call void @main.assert(i1 true) + call void @main.assert(i1 true) + call void @main.assert(i1 true) + call void @main.assert(i1 true) %7 = extractvalue { ptr, ptr } %6, 0 + %8 = icmp ne ptr %7, null + call void @main.assert(i1 %8) + %9 = extractvalue { ptr, ptr } %6, 0 + %10 = icmp ne ptr null, %9 + call void @main.assert(i1 %10) call void @main.assert(i1 true) call void @main.assert(i1 true) ret void diff --git a/ssa/expr.go b/ssa/expr.go index 4b179ea8..46dd202f 100644 --- a/ssa/expr.go +++ b/ssa/expr.go @@ -501,12 +501,6 @@ func (b Builder) BinOp(op token.Token, x, y Expr) Expr { case vkUnsigned, vkPtr: pred := uintPredOpToLLVM[op-predOpBase] return Expr{llvm.CreateICmp(b.impl, pred, x.impl, y.impl), tret} - case vkMap: - switch op { - case token.EQL, token.NEQ: - pred := uintPredOpToLLVM[op-predOpBase] - return Expr{llvm.CreateICmp(b.impl, pred, x.impl, y.impl), tret} - } case vkFloat: pred := floatPredOpToLLVM[op-predOpBase] return Expr{llvm.CreateFCmp(b.impl, pred, x.impl, y.impl), tret} @@ -554,21 +548,18 @@ func (b Builder) BinOp(op token.Token, x, y Expr) Expr { } case vkClosure: x = b.Field(x, 0) - y = b.Field(y, 0) - fallthrough - case vkFuncPtr, vkFuncDecl: - switch op { - case token.EQL: // TODO(xsw): check this code - return b.Prog.BoolVal(x.impl.IsNull() == y.impl.IsNull()) - case token.NEQ: - return b.Prog.BoolVal(x.impl.IsNull() != y.impl.IsNull()) + if y.kind == vkClosure { + y = b.Field(y, 0) + } + fallthrough + case vkFuncPtr, vkFuncDecl, vkChan, vkMap: + if y.kind == vkClosure { + y = b.Field(y, 0) } - case vkChan: switch op { - case token.EQL: - return Expr{llvm.CreateICmp(b.impl, llvm.IntEQ, x.impl, y.impl), tret} - case token.NEQ: - return Expr{llvm.CreateICmp(b.impl, llvm.IntNE, x.impl, y.impl), tret} + case token.EQL, token.NEQ: + pred := uintPredOpToLLVM[op-predOpBase] + return Expr{llvm.CreateICmp(b.impl, pred, x.impl, y.impl), tret} } case vkArray: typ := x.raw.Type.(*types.Array)