Merge pull request #539 from visualfc/bineq

ssa: fix binop closure/funcdecl
This commit is contained in:
xushiwei
2024-07-19 11:29:15 +08:00
committed by GitHub
3 changed files with 23 additions and 19 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)
if y.kind == vkClosure {
y = b.Field(y, 0)
}
fallthrough
case vkFuncPtr, vkFuncDecl, vkChan, vkMap:
if y.kind == vkClosure {
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())
}
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)