msan.go 540 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 <stdint.h>
  7. void f(int32_t *p, int n) {
  8. int i;
  9. for (i = 0; i < n; i++) {
  10. p[i] = (int32_t)i;
  11. }
  12. }
  13. */
  14. import "C"
  15. import (
  16. "fmt"
  17. "os"
  18. "unsafe"
  19. )
  20. func main() {
  21. a := make([]int32, 10)
  22. C.f((*C.int32_t)(unsafe.Pointer(&a[0])), C.int(len(a)))
  23. for i, v := range a {
  24. if i != int(v) {
  25. fmt.Println("bad %d: %v\n", i, a)
  26. os.Exit(1)
  27. }
  28. }
  29. }