]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: don't strip qualifiers from C void* pointer
authorIan Lance Taylor <iant@golang.org>
Tue, 13 Dec 2016 22:29:57 +0000 (14:29 -0800)
committerIan Lance Taylor <iant@golang.org>
Wed, 14 Dec 2016 00:59:38 +0000 (00:59 +0000)
Now that we try to handle qualifiers correctly (as of CL 33325), don't
strip them from a void* pointer. Otherwise we break a case like "const
void**", as the "const" qualifier is dropped and the resulting
"void**" triggers a warning from the C compiler.

Fixes #18298.

Change-Id: If51df1889b0f6a907715298c152e6d4584747acb
Reviewed-on: https://go-review.googlesource.com/34370
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

misc/cgo/test/issue17537.go
src/cmd/cgo/gcc.go

index debdbfe4c505b10902dc372cfc5e9f04f0643def..777104e512209892d4fa856d9d791ad972dc9a35 100644 (file)
@@ -23,6 +23,18 @@ int I17537(S17537 *p);
 const int F17537(const char **p) {
        return **p;
 }
+
+// Calling this function used to trigger an error from the C compiler
+// (issue 18298).
+void F18298(const void *const *p) {
+}
+
+// Test that conversions between typedefs work as they used to.
+typedef const void *T18298_1;
+struct S18298 { int i; };
+typedef const struct S18298 *T18298_2;
+void G18298(T18298_1 t) {
+}
 */
 import "C"
 
@@ -39,4 +51,8 @@ func test17537(t *testing.T) {
        if got, want := C.F17537(&p), C.int(17); got != want {
                t.Errorf("got %d, want %d", got, want)
        }
+
+       C.F18298(nil)
+       var v18298 C.T18298_2
+       C.G18298(C.T18298_1(v18298))
 }
index d6c23a70eb33639dd662f4dab0df6f4a50d54064..5ea2d941ca2ea9f9609c2c3531f7373ebd31aeb4 100644 (file)
@@ -1729,6 +1729,15 @@ func (c *typeConv) Type(dtype dwarf.Type, pos token.Pos) *Type {
                if _, ok := base(dt.Type).(*dwarf.VoidType); ok {
                        t.Go = c.goVoidPtr
                        t.C.Set("void*")
+                       dq := dt.Type
+                       for {
+                               if d, ok := dq.(*dwarf.QualType); ok {
+                                       t.C.Set(d.Qual + " " + t.C.String())
+                                       dq = d.Type
+                               } else {
+                                       break
+                               }
+                       }
                        break
                }