mirror of
https://github.com/golang/go
synced 2024-11-11 18:51:37 -07:00
[release-branch.go1.12] cmd/cgo: fix inappropriate array copy
Ensure that during rewriting of expressions that take the address of an array, that we properly recognize *ast.IndexExpr as an operation to create a pointer variable and thus assign the proper addressOf and deference operators as "&" and "*" respectively. This fixes a regression from CL 142884. This is a backport of CLs 183458 and 183778 to the 1.12 release branch. It is not a cherry pick because the code in misc/cgo/test has changed. Updates #32579 Fixes #32756 Change-Id: I0daa75ec62cccbe82ab658cb2947f51423e0c235 Reviewed-on: https://go-review.googlesource.com/c/go/+/183627 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
This commit is contained in:
parent
4ce6a8e896
commit
77c14d2973
@ -95,6 +95,7 @@ func Test26213(t *testing.T) { test26213(t) }
|
||||
func Test27660(t *testing.T) { test27660(t) }
|
||||
func Test28896(t *testing.T) { test28896(t) }
|
||||
func Test30065(t *testing.T) { test30065(t) }
|
||||
func Test32579(t *testing.T) { test32579(t) }
|
||||
|
||||
func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) }
|
||||
func BenchmarkGoString(b *testing.B) { benchGoString(b) }
|
||||
|
22
misc/cgo/test/issue32579.go
Normal file
22
misc/cgo/test/issue32579.go
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package cgotest
|
||||
|
||||
// #include <string.h>
|
||||
// typedef struct S32579 { unsigned char data[1]; } S32579;
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func test32579(t *testing.T) {
|
||||
var s [1]C.struct_S32579
|
||||
C.memset(unsafe.Pointer(&s[0].data[0]), 1, 1)
|
||||
if s[0].data[0] != 1 {
|
||||
t.Errorf("&s[0].data[0] failed: got %d, want %d", s[0].data[0], 1)
|
||||
}
|
||||
}
|
@ -1256,6 +1256,8 @@ func (p *Package) isVariable(x ast.Expr) bool {
|
||||
return true
|
||||
case *ast.SelectorExpr:
|
||||
return p.isVariable(x.X)
|
||||
case *ast.IndexExpr:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user