gcc/libgo/misc/cgo/testsanitizers/msan3.go
Ian Lance Taylor 936615752a libgo: add misc/cgo files
Copy all the misc/cgo files from the gc toolchain into libgo/misc.
    
    These will be used for testing purposes by later changes to the
    gotools directory.
    
    Reviewed-on: https://go-review.googlesource.com/46721

From-SVN: r249674
2017-06-27 04:21:40 +00:00

34 lines
552 B
Go

// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
/*
extern int *GoFn(int *);
// Yes, you can have definitions if you use //export, as long as they are weak.
int f(void) __attribute__ ((weak));
int f() {
int i;
int *p = GoFn(&i);
if (*p != 12345)
return 0;
return 1;
}
*/
import "C"
//export GoFn
func GoFn(p *C.int) *C.int {
*p = C.int(12345)
return p
}
func main() {
if r := C.f(); r != 1 {
panic(r)
}
}