1
0
mirror of https://github.com/golang/go synced 2024-10-05 09:21:22 -06:00
go/misc/cgo/testsanitizers/msan.go
Ian Lance Taylor e7ee268292 cmd/go: add -msan option
The -msan option compiles Go code to use the memory sanitizer.  This is
intended for use when linking with C/C++ code compiled with
-fsanitize=memory.  When memory blocks are passed back and forth between
C/C++ and Go, code in both languages will agree as to whether the memory
is correctly initialized or not, and will report errors for any use of
uninitialized memory.

Change-Id: I2dbdbd26951eacb7d84063cfc7297f88ffadd70c
Reviewed-on: https://go-review.googlesource.com/16169
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-10-21 20:30:23 +00:00

32 lines
380 B
Go

package main
/*
#include <stdint.h>
void f(int32_t *p, int n) {
int i;
for (i = 0; i < n; i++) {
p[i] = (int32_t)i;
}
}
*/
import "C"
import (
"fmt"
"os"
"unsafe"
)
func main() {
a := make([]int32, 10)
C.f((*C.int32_t)(unsafe.Pointer(&a[0])), C.int(len(a)))
for i, v := range a {
if i != int(v) {
fmt.Println("bad %d: %v\n", i, a)
os.Exit(1)
}
}
}