]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: fix C.complexfloat and C.complexdouble
authorMatthew Dempsky <mdempsky@google.com>
Wed, 25 Nov 2015 21:09:14 +0000 (13:09 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 25 Nov 2015 23:06:59 +0000 (23:06 +0000)
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 <iant@golang.org>
misc/cgo/test/issue13402.go [new file with mode: 0644]
misc/cgo/test/issue8694.go
src/cmd/cgo/doc.go
src/cmd/cgo/gcc.go

diff --git a/misc/cgo/test/issue13402.go b/misc/cgo/test/issue13402.go
new file mode 100644 (file)
index 0000000..6e3e24c
--- /dev/null
@@ -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
index 1876f782d96939905c6598d92513f185fb1d852c..ba7a344c53d9bcaca0258a7c7dd5d292b282ca78 100644 (file)
@@ -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 {
index 38667a2a5979ebd2890ae2f0a96c163a90a56183..8ec4301112baeeb0989592e3b442c1b9d31dfac2 100644 (file)
@@ -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.
 
index af2456e421bbaf429e0d060c038effca6ee02e39..2b222d6d271c34a8bf14989ab15a28f4e79147cf 100644 (file)
@@ -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 {