1// Copyright 2020 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5package main 6 7// Test passing C struct to exported Go function. 8 9/* 10#include <stdint.h> 11#include <stdlib.h> 12 13// T is a C struct with alignment padding after b. 14// The padding bytes are not considered initialized by MSAN. 15// It is big enough to be passed on stack in C ABI (and least 16// on AMD64). 17typedef struct { char b; uintptr_t x, y; } T; 18 19extern void F(T); 20 21// Use weak as a hack to permit defining a function even though we use export. 22void CF(int x) __attribute__ ((weak)); 23void CF(int x) { 24 T *t = malloc(sizeof(T)); 25 t->b = (char)x; 26 t->x = x; 27 t->y = x; 28 F(*t); 29} 30*/ 31import "C" 32 33//export F 34func F(t C.T) { println(t.b, t.x, t.y) } 35 36func main() { 37 C.CF(C.int(0)) 38} 39