Commit 77c14d29 authored by Ian Lance Taylor's avatar Ian Lance Taylor

[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: default avatarEmmanuel Odeke <emm.odeke@gmail.com>
parent 4ce6a8e8
......@@ -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) }
// 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
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment