diff --git a/cmd/xgo/runtime_gen/core/version.go b/cmd/xgo/runtime_gen/core/version.go index cab8eec5..00dd12db 100755 --- a/cmd/xgo/runtime_gen/core/version.go +++ b/cmd/xgo/runtime_gen/core/version.go @@ -7,8 +7,8 @@ import ( ) const VERSION = "1.0.38" -const REVISION = "1bb3d68c0400e9594cd3e95a755cbe52f2283706+1" -const NUMBER = 251 +const REVISION = "c77350703e0305824f28a2ff5879e1499e47fc39+1" +const NUMBER = 252 // these fields will be filled by compiler const XGO_VERSION = "" diff --git a/cmd/xgo/version.go b/cmd/xgo/version.go index 06357dfb..2916665e 100644 --- a/cmd/xgo/version.go +++ b/cmd/xgo/version.go @@ -3,8 +3,8 @@ package main import "fmt" const VERSION = "1.0.38" -const REVISION = "1bb3d68c0400e9594cd3e95a755cbe52f2283706+1" -const NUMBER = 251 +const REVISION = "c77350703e0305824f28a2ff5879e1499e47fc39+1" +const NUMBER = 252 func getRevision() string { revSuffix := "" diff --git a/patch/syntax/vars.go b/patch/syntax/vars.go index 0c1c74e9..f5e1546e 100644 --- a/patch/syntax/vars.go +++ b/patch/syntax/vars.go @@ -457,8 +457,9 @@ func (ctx *BlockContext) traverseExpr(node syntax.Expr, globaleNames map[string] case *syntax.Operation: // take addr? if node.Op == syntax.And && node.Y == nil { + nodeX := deparen(node.X) // &a, - switch x := node.X.(type) { + switch x := nodeX.(type) { case *syntax.Name: return ctx.trapAddrNode(node, x, globaleNames) case *syntax.SelectorExpr: @@ -469,6 +470,9 @@ func (ctx *BlockContext) traverseExpr(node syntax.Expr, globaleNames map[string] if xIsName { return node } + case *syntax.IndexExpr: + // don't insert trap, see https://github.com/xhd2015/xgo/issues/177 + return node } } if node.X != nil && node.Y != nil { @@ -550,6 +554,18 @@ func isBoolOp(op syntax.Operator) bool { return false } +func deparen(expr syntax.Expr) syntax.Expr { + if expr == nil { + return nil + } + for { + p, ok := expr.(*syntax.ParenExpr) + if !ok { + return expr + } + expr = p.X + } +} func getConstType(xgoConv *syntax.XgoSimpleConvert) string { return xgoConv.X.(*syntax.CallExpr).Fun.(*syntax.Name).Value } diff --git a/runtime/core/version.go b/runtime/core/version.go index cab8eec5..00dd12db 100644 --- a/runtime/core/version.go +++ b/runtime/core/version.go @@ -7,8 +7,8 @@ import ( ) const VERSION = "1.0.38" -const REVISION = "1bb3d68c0400e9594cd3e95a755cbe52f2283706+1" -const NUMBER = 251 +const REVISION = "c77350703e0305824f28a2ff5879e1499e47fc39+1" +const NUMBER = 252 // these fields will be filled by compiler const XGO_VERSION = "" diff --git a/runtime/test/trap/trap_var_test.go b/runtime/test/trap/trap_var_test.go new file mode 100644 index 00000000..e88980e9 --- /dev/null +++ b/runtime/test/trap/trap_var_test.go @@ -0,0 +1,15 @@ +package trap + +import "testing" + +var ints [3]int + +// see bug https://github.com/xhd2015/xgo/issues/177 +func TestNoTrapArrayPointer(t *testing.T) { + x := &ints[0] + y := &ints[0] + + if x != y { + t.Fatalf("x != y: x=0x%x, y=0x%x", x, y) + } +}