mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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. Fixed #32579 Change-Id: I3cb78becff4f8035d66fc5536e5b52857eacaa3d Reviewed-on: https://go-review.googlesource.com/c/go/+/183458 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
4ae3835aa2
commit
38fc0afca6
3 changed files with 15 additions and 0 deletions
|
|
@ -57,6 +57,7 @@ func Test26066(t *testing.T) { test26066(t) }
|
||||||
func Test27660(t *testing.T) { test27660(t) }
|
func Test27660(t *testing.T) { test27660(t) }
|
||||||
func Test28896(t *testing.T) { test28896(t) }
|
func Test28896(t *testing.T) { test28896(t) }
|
||||||
func Test30065(t *testing.T) { test30065(t) }
|
func Test30065(t *testing.T) { test30065(t) }
|
||||||
|
func Test32579(t *testing.T) { test32579(t) }
|
||||||
func TestAlign(t *testing.T) { testAlign(t) }
|
func TestAlign(t *testing.T) { testAlign(t) }
|
||||||
func TestAtol(t *testing.T) { testAtol(t) }
|
func TestAtol(t *testing.T) { testAtol(t) }
|
||||||
func TestBlocking(t *testing.T) { testBlocking(t) }
|
func TestBlocking(t *testing.T) { testBlocking(t) }
|
||||||
|
|
|
||||||
|
|
@ -852,6 +852,8 @@ static void issue29781F(char **p, int n) {}
|
||||||
// issue 31093
|
// issue 31093
|
||||||
static uint16_t issue31093F(uint16_t v) { return v; }
|
static uint16_t issue31093F(uint16_t v) { return v; }
|
||||||
|
|
||||||
|
// issue 32579
|
||||||
|
typedef struct S32579 { int data[1]; } S32579;
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
|
@ -2083,3 +2085,13 @@ func test30065(t *testing.T) {
|
||||||
func Issue31093() {
|
func Issue31093() {
|
||||||
C.issue31093F(C.ushort(0))
|
C.issue31093F(C.ushort(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// issue 32579
|
||||||
|
|
||||||
|
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
|
return true
|
||||||
case *ast.SelectorExpr:
|
case *ast.SelectorExpr:
|
||||||
return p.isVariable(x.X)
|
return p.isVariable(x.X)
|
||||||
|
case *ast.IndexExpr:
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue