blob: f1479eb8a005693fcea56d476d44454349ec4bb1 [file] [log] [blame]
Ian Lance Taylordc9755c2016-07-06 15:30:33 -07001// Copyright 2016 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
5package main
6
7// Using reflect to set a value was not seen by msan.
8
9/*
10#include <stdlib.h>
11
12extern void Go1(int*);
13extern void Go2(char*);
14
15// Use weak as a hack to permit defining a function even though we use export.
16void C1() __attribute__ ((weak));
17void C2() __attribute__ ((weak));
18
19void C1() {
20 int i;
21 Go1(&i);
22 if (i != 42) {
23 abort();
24 }
25}
26
27void C2() {
28 char a[2];
29 a[1] = 42;
30 Go2(a);
31 if (a[0] != 42) {
32 abort();
33 }
34}
35*/
36import "C"
37
38import (
39 "reflect"
40 "unsafe"
41)
42
43//export Go1
44func Go1(p *C.int) {
45 reflect.ValueOf(p).Elem().Set(reflect.ValueOf(C.int(42)))
46}
47
48//export Go2
49func Go2(p *C.char) {
50 a := (*[2]byte)(unsafe.Pointer(p))
51 reflect.Copy(reflect.ValueOf(a[:1]), reflect.ValueOf(a[1:]))
52}
53
54func main() {
55 C.C1()
56 C.C2()
57}