msan7.go 834 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. package main
  5. // Test passing C struct to exported Go function.
  6. /*
  7. #include <stdint.h>
  8. #include <stdlib.h>
  9. // T is a C struct with alignment padding after b.
  10. // The padding bytes are not considered initialized by MSAN.
  11. // It is big enough to be passed on stack in C ABI (and least
  12. // on AMD64).
  13. typedef struct { char b; uintptr_t x, y; } T;
  14. extern void F(T);
  15. // Use weak as a hack to permit defining a function even though we use export.
  16. void CF(int x) __attribute__ ((weak));
  17. void CF(int x) {
  18. T *t = malloc(sizeof(T));
  19. t->b = (char)x;
  20. t->x = x;
  21. t->y = x;
  22. F(*t);
  23. }
  24. */
  25. import "C"
  26. //export F
  27. func F(t C.T) { println(t.b, t.x, t.y) }
  28. func main() {
  29. C.CF(C.int(0))
  30. }