From 5e1727892bf36076ee45c417b56bba32801ffbd7 Mon Sep 17 00:00:00 2001 From: Hiroshi Ioka Date: Wed, 5 Dec 2018 08:01:07 +0900 Subject: cmd/cgo: reject names that are likely to be mangled C name Fixes #28721 Change-Id: I00356f3a9b0c2fb21dc9c2237dd5296fcb3b319b Reviewed-on: https://go-review.googlesource.com/c/152657 Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor --- misc/cgo/errors/errors_test.go | 1 + misc/cgo/errors/src/issue28721.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 misc/cgo/errors/src/issue28721.go (limited to 'misc/cgo/errors') diff --git a/misc/cgo/errors/errors_test.go b/misc/cgo/errors/errors_test.go index 0d7ca4cf9d..d2a72a46f4 100644 --- a/misc/cgo/errors/errors_test.go +++ b/misc/cgo/errors/errors_test.go @@ -121,6 +121,7 @@ func TestReportsTypeErrors(t *testing.T) { "issue16591.go", "issue18452.go", "issue18889.go", + "issue28721.go", } { check(t, file) } diff --git a/misc/cgo/errors/src/issue28721.go b/misc/cgo/errors/src/issue28721.go new file mode 100644 index 0000000000..0eb2a9271c --- /dev/null +++ b/misc/cgo/errors/src/issue28721.go @@ -0,0 +1,29 @@ +// Copyright 2018 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. + +// cgo should reject the use of mangled C names. + +package main + +/* +typedef struct a { + int i; +} a; +void fn(void) {} +*/ +import "C" + +type B _Ctype_struct_a // ERROR HERE + +var a _Ctype_struct_a // ERROR HERE + +type A struct { + a *_Ctype_struct_a // ERROR HERE +} + +var notExist _Ctype_NotExist // ERROR HERE + +func main() { + _Cfunc_fn() // ERROR HERE +} -- cgit v1.3-5-g9baa