Skip to content

Commit

Permalink
fix var index addr trap
Browse files Browse the repository at this point in the history
  • Loading branch information
xhd2015 committed Jun 2, 2024
1 parent c773507 commit 862f2c7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmd/xgo/runtime_gen/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
4 changes: 2 additions & 2 deletions cmd/xgo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := ""
Expand Down
18 changes: 17 additions & 1 deletion patch/syntax/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
15 changes: 15 additions & 0 deletions runtime/test/trap/trap_var_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 862f2c7

Please sign in to comment.