golang/go

cmd/cgo: C code with function taking pointer typedef leads to C compiler warning

Open

#19.832 geöffnet am 4. Apr. 2017

Auf GitHub ansehen
 (3 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Go (19.008 Forks)batch import
NeedsFixcompiler/runtimehelp wanted

Repository-Metriken

Stars
 (133.883 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

Building this file gets a warning from the C compiler:

package main

// typedef struct { int i; } *PS;
// void F(PS p) {}
import "C"

func main() {
	C.F(nil)
}

The warning I see is:

# command-line-arguments
cgo-gcc-prolog: In function ‘_cgo_0164fa09626e_Cfunc_F’:
cgo-gcc-prolog:37:2: warning: passing argument 1 of ‘F’ from incompatible pointer type [enabled by default]
/home/iant/foo8.go:4:7: note: expected ‘PS’ but argument is of type ‘struct <anonymous> *’
 // void F(PS p) {}
       ^

The code generated by cgo looks like:

CGO_NO_SANITIZE_THREAD
void
_cgo_0164fa09626e_Cfunc_F(void *v)
{
	struct {
		struct {int i; }* p0;
	} __attribute__((__packed__, __gcc_struct__)) *a = v;
	_cgo_tsan_acquire();
	F(a->p0);
	_cgo_tsan_release();
}

The C function expects PS* but we are passing struct{int i;}*. That is, we aren't using the typedef.

Changing the Go code to use C.PS(unsafe.Pointer(nil)) also fails in the same way.

Contributor Guide