File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ #![ feature( core_intrinsics) ] // for `volatile_set_memory`
2
+
1
3
#[ repr( C ) ]
2
4
#[ derive( Copy , Clone ) ]
3
5
struct Foo {
@@ -42,4 +44,42 @@ fn main() {
42
44
assert_eq ! ( w[ idx] . b, 0xcdcdcdcdcdcdcdcd ) ;
43
45
assert_eq ! ( w[ idx] . c, 0xcdcdcdcdcdcdcdcd ) ;
44
46
}
47
+
48
+ // -----
49
+ // `std::intrinsics::volatile_set_memory` should behave identically
50
+
51
+ let mut v: [ u64 ; LENGTH ] = [ 0 ; LENGTH ] ;
52
+
53
+ for idx in 0 ..LENGTH {
54
+ assert_eq ! ( v[ idx] , 0 ) ;
55
+ }
56
+
57
+ unsafe {
58
+ let p = v. as_mut_ptr ( ) ;
59
+ :: std:: intrinsics:: volatile_set_memory ( p, 0xab , LENGTH ) ;
60
+ }
61
+
62
+ for idx in 0 ..LENGTH {
63
+ assert_eq ! ( v[ idx] , 0xabababababababab ) ;
64
+ }
65
+
66
+ // -----
67
+
68
+ let mut w: [ Foo ; LENGTH ] = [ Foo { a : 0 , b : 0 , c : 0 } ; LENGTH ] ;
69
+ for idx in 0 ..LENGTH {
70
+ assert_eq ! ( w[ idx] . a, 0 ) ;
71
+ assert_eq ! ( w[ idx] . b, 0 ) ;
72
+ assert_eq ! ( w[ idx] . c, 0 ) ;
73
+ }
74
+
75
+ unsafe {
76
+ let p = w. as_mut_ptr ( ) ;
77
+ :: std:: intrinsics:: volatile_set_memory ( p, 0xcd , LENGTH ) ;
78
+ }
79
+
80
+ for idx in 0 ..LENGTH {
81
+ assert_eq ! ( w[ idx] . a, 0xcdcdcdcdcdcdcdcd ) ;
82
+ assert_eq ! ( w[ idx] . b, 0xcdcdcdcdcdcdcdcd ) ;
83
+ assert_eq ! ( w[ idx] . c, 0xcdcdcdcdcdcdcdcd ) ;
84
+ }
45
85
}
You can’t perform that action at this time.
0 commit comments