msan2.go 644 B

1234567891011121314151617181920212223242526272829303132333435
  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. #include <string.h>
  7. #include <stdint.h>
  8. #include <stdlib.h>
  9. void f(int32_t *p, int n) {
  10. int32_t * volatile q = (int32_t *)malloc(sizeof(int32_t) * n);
  11. memcpy(p, q, n * sizeof(*p));
  12. free(q);
  13. }
  14. void g(int32_t *p, int n) {
  15. if (p[4] != 1) {
  16. abort();
  17. }
  18. }
  19. */
  20. import "C"
  21. import (
  22. "unsafe"
  23. )
  24. func main() {
  25. a := make([]int32, 10)
  26. C.f((*C.int32_t)(unsafe.Pointer(&a[0])), C.int(len(a)))
  27. a[4] = 1
  28. C.g((*C.int32_t)(unsafe.Pointer(&a[0])), C.int(len(a)))
  29. }