msan3.go 552 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2015 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. /*
  6. extern int *GoFn(int *);
  7. // Yes, you can have definitions if you use //export, as long as they are weak.
  8. int f(void) __attribute__ ((weak));
  9. int f() {
  10. int i;
  11. int *p = GoFn(&i);
  12. if (*p != 12345)
  13. return 0;
  14. return 1;
  15. }
  16. */
  17. import "C"
  18. //export GoFn
  19. func GoFn(p *C.int) *C.int {
  20. *p = C.int(12345)
  21. return p
  22. }
  23. func main() {
  24. if r := C.f(); r != 1 {
  25. panic(r)
  26. }
  27. }