From 10cb39afc4e81d126c71153dba7b9f1878bae61a Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Wed, 25 Nov 2015 13:09:14 -0800 Subject: [PATCH] cmd/cgo: fix C.complexfloat and C.complexdouble This also fixes an unintended behavior where C's "complex float" and "complex double" types were interchangeable with Go's "complex64" and "complex128" types. Fixes #13402. Change-Id: I73f96d9a4772088d495073783c6982e9634430e8 Reviewed-on: https://go-review.googlesource.com/17208 Reviewed-by: Ian Lance Taylor --- misc/cgo/test/issue13402.go | 10 ++++++++++ misc/cgo/test/issue8694.go | 4 ++-- src/cmd/cgo/doc.go | 3 ++- src/cmd/cgo/gcc.go | 8 +++----- 4 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 misc/cgo/test/issue13402.go diff --git a/misc/cgo/test/issue13402.go b/misc/cgo/test/issue13402.go new file mode 100644 index 0000000000..6e3e24c2b7 --- /dev/null +++ b/misc/cgo/test/issue13402.go @@ -0,0 +1,10 @@ +// Copyright 2015 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 + +import "C" + +var _ C.complexfloat +var _ C.complexdouble diff --git a/misc/cgo/test/issue8694.go b/misc/cgo/test/issue8694.go index 1876f782d9..ba7a344c53 100644 --- a/misc/cgo/test/issue8694.go +++ b/misc/cgo/test/issue8694.go @@ -22,14 +22,14 @@ func test8694(t *testing.T) { t.Skip("test8694 is disabled on ARM because 5l cannot handle thumb library.") } // Really just testing that this compiles, but check answer anyway. - x := complex64(2 + 3i) + x := C.complexfloat(2 + 3i) x2 := x * x cx2 := C.complexFloatSquared(x) if cx2 != x2 { t.Errorf("C.complexFloatSquared(%v) = %v, want %v", x, cx2, x2) } - y := complex128(2 + 3i) + y := C.complexdouble(2 + 3i) y2 := y * y cy2 := C.complexDoubleSquared(y) if cy2 != y2 { diff --git a/src/cmd/cgo/doc.go b/src/cmd/cgo/doc.go index 38667a2a59..8ec4301112 100644 --- a/src/cmd/cgo/doc.go +++ b/src/cmd/cgo/doc.go @@ -117,7 +117,8 @@ The standard C numeric types are available under the names C.char, C.schar (signed char), C.uchar (unsigned char), C.short, C.ushort (unsigned short), C.int, C.uint (unsigned int), C.long, C.ulong (unsigned long), C.longlong (long long), -C.ulonglong (unsigned long long), C.float, C.double. +C.ulonglong (unsigned long long), C.float, C.double, +C.complexfloat (complex float), and C.complexdouble (complex double). The C type void* is represented by Go's unsafe.Pointer. The C types __int128_t and __uint128_t are represented by [16]byte. diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index af2456e421..2b222d6d27 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -38,8 +38,8 @@ var nameToC = map[string]string{ "ulong": "unsigned long", "longlong": "long long", "ulonglong": "unsigned long long", - "complexfloat": "float complex", - "complexdouble": "double complex", + "complexfloat": "__complex float", + "complexdouble": "__complex double", } // cname returns the C name to use for C.s. @@ -1319,8 +1319,6 @@ var dwarfToName = map[string]string{ "long long int": "longlong", "long long unsigned int": "ulonglong", "signed char": "schar", - "float complex": "complexfloat", - "double complex": "complexdouble", } const signedDelta = 64 @@ -1690,7 +1688,7 @@ func (c *typeConv) Type(dtype dwarf.Type, pos token.Pos) *Type { } switch dtype.(type) { - case *dwarf.AddrType, *dwarf.BoolType, *dwarf.CharType, *dwarf.IntType, *dwarf.FloatType, *dwarf.UcharType, *dwarf.UintType: + case *dwarf.AddrType, *dwarf.BoolType, *dwarf.CharType, *dwarf.ComplexType, *dwarf.IntType, *dwarf.FloatType, *dwarf.UcharType, *dwarf.UintType: s := dtype.Common().Name if s != "" { if ss, ok := dwarfToName[s]; ok {