Skip to content

Commit 01a5845

Browse files
committed
fix atomic intrinsic test cases
1 parent caceac0 commit 01a5845

File tree

4 files changed

+54
-58
lines changed

4 files changed

+54
-58
lines changed

src/test/auxiliary/cci_intrinsic.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#[abi = "rust-intrinsic"]
22
extern mod rusti {
3-
fn atomic_xchng(&dst: int, src: int) -> int;
4-
fn atomic_xchng_acq(&dst: int, src: int) -> int;
5-
fn atomic_xchng_rel(&dst: int, src: int) -> int;
3+
fn atomic_xchg(dst: &mut int, src: int) -> int;
4+
fn atomic_xchg_acq(dst: &mut int, src: int) -> int;
5+
fn atomic_xchg_rel(dst: &mut int, src: int) -> int;
66

7-
fn atomic_add(&dst: int, src: int) -> int;
8-
fn atomic_add_acq(&dst: int, src: int) -> int;
9-
fn atomic_add_rel(&dst: int, src: int) -> int;
7+
fn atomic_xadd(dst: &mut int, src: int) -> int;
8+
fn atomic_xadd_acq(dst: &mut int, src: int) -> int;
9+
fn atomic_xadd_rel(dst: &mut int, src: int) -> int;
1010

11-
fn atomic_sub(&dst: int, src: int) -> int;
12-
fn atomic_sub_acq(&dst: int, src: int) -> int;
13-
fn atomic_sub_rel(&dst: int, src: int) -> int;
11+
fn atomic_xsub(dst: &mut int, src: int) -> int;
12+
fn atomic_xsub_acq(dst: &mut int, src: int) -> int;
13+
fn atomic_xsub_rel(dst: &mut int, src: int) -> int;
1414
}
1515

1616
#[inline(always)]
17-
fn atomic_xchng(&dst: int, src: int) -> int {
18-
rusti::atomic_xchng(dst, src)
19-
}
17+
fn atomic_xchg(dst: &mut int, src: int) -> int {
18+
rusti::atomic_xchg(dst, src)
19+
}

src/test/run-pass/intrinsic-atomics-cc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
// xfail-test
55

66
use cci_intrinsic;
7-
import cci_intrinsic::atomic_xchng;
7+
import cci_intrinsic::atomic_xchg;
88

99
fn main() {
1010
let mut x = 1;
11-
atomic_xchng(x, 5);
11+
atomic_xchg(&mut x, 5);
1212
assert x == 5;
1313
}
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
#[abi = "rust-intrinsic"]
22
extern mod rusti {
3-
fn atomic_xchng(&dst: int, src: int) -> int;
4-
fn atomic_xchng_acq(&dst: int, src: int) -> int;
5-
fn atomic_xchng_rel(&dst: int, src: int) -> int;
3+
fn atomic_xchg(dst: &mut int, src: int) -> int;
4+
fn atomic_xchg_acq(dst: &mut int, src: int) -> int;
5+
fn atomic_xchg_rel(dst: &mut int, src: int) -> int;
66

7-
fn atomic_add(&dst: int, src: int) -> int;
8-
fn atomic_add_acq(&dst: int, src: int) -> int;
9-
fn atomic_add_rel(&dst: int, src: int) -> int;
7+
fn atomic_xadd(dst: &mut int, src: int) -> int;
8+
fn atomic_xadd_acq(dst: &mut int, src: int) -> int;
9+
fn atomic_xadd_rel(dst: &mut int, src: int) -> int;
1010

11-
fn atomic_sub(&dst: int, src: int) -> int;
12-
fn atomic_sub_acq(&dst: int, src: int) -> int;
13-
fn atomic_sub_rel(&dst: int, src: int) -> int;
11+
fn atomic_xsub(dst: &mut int, src: int) -> int;
12+
fn atomic_xsub_acq(dst: &mut int, src: int) -> int;
13+
fn atomic_xsub_rel(dst: &mut int, src: int) -> int;
1414
}
1515

1616
fn main() {
17-
let mut x = 1;
17+
let x = ~mut 1;
1818

19-
assert rusti::atomic_xchng(x, 0) == 1;
20-
assert x == 0;
19+
assert rusti::atomic_xchg(x, 0) == 1;
20+
assert *x == 0;
2121

22-
assert rusti::atomic_xchng_acq(x, 1) == 0;
23-
assert x == 1;
22+
assert rusti::atomic_xchg_acq(x, 1) == 0;
23+
assert *x == 1;
2424

25-
assert rusti::atomic_xchng_rel(x, 0) == 1;
26-
assert x == 0;
25+
assert rusti::atomic_xchg_rel(x, 0) == 1;
26+
assert *x == 0;
2727

28-
assert rusti::atomic_add(x, 1) == 0;
29-
assert rusti::atomic_add_acq(x, 1) == 1;
30-
assert rusti::atomic_add_rel(x, 1) == 2;
31-
assert x == 3;
28+
assert rusti::atomic_xadd(x, 1) == 0;
29+
assert rusti::atomic_xadd_acq(x, 1) == 1;
30+
assert rusti::atomic_xadd_rel(x, 1) == 2;
31+
assert *x == 3;
3232

33-
assert rusti::atomic_sub(x, 1) == 3;
34-
assert rusti::atomic_sub_acq(x, 1) == 2;
35-
assert rusti::atomic_sub_rel(x, 1) == 1;
36-
assert x == 0;
33+
assert rusti::atomic_xsub(x, 1) == 3;
34+
assert rusti::atomic_xsub_acq(x, 1) == 2;
35+
assert rusti::atomic_xsub_rel(x, 1) == 1;
36+
assert *x == 0;
3737
}

src/test/run-pass/issue-2718.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mod pipes {
2-
import unsafe::{forget, reinterpret_cast};
2+
import unsafe::{forget, transmute};
33

44
enum state {
55
empty,
@@ -25,30 +25,26 @@ mod pipes {
2525

2626
#[abi = "rust-intrinsic"]
2727
mod rusti {
28-
fn atomic_xchng(&dst: int, src: int) -> int { fail; }
29-
fn atomic_xchng_acq(&dst: int, src: int) -> int { fail; }
30-
fn atomic_xchng_rel(&dst: int, src: int) -> int { fail; }
28+
fn atomic_xchg(_dst: &mut int, _src: int) -> int { fail; }
29+
fn atomic_xchg_acq(_dst: &mut int, _src: int) -> int { fail; }
30+
fn atomic_xchg_rel(_dst: &mut int, _src: int) -> int { fail; }
3131
}
3232

3333
// We should consider moving this to core::unsafe, although I
3434
// suspect graydon would want us to use void pointers instead.
35-
unsafe fn uniquify<T>(x: *T) -> ~T {
36-
unsafe { unsafe::reinterpret_cast(x) }
35+
unsafe fn uniquify<T>(+x: *T) -> ~T {
36+
unsafe { unsafe::transmute(x) }
3737
}
3838

39-
fn swap_state_acq(&dst: state, src: state) -> state {
39+
fn swap_state_acq(+dst: &mut state, src: state) -> state {
4040
unsafe {
41-
reinterpret_cast(rusti::atomic_xchng_acq(
42-
*(ptr::mut_addr_of(dst) as *mut int),
43-
src as int))
41+
transmute(rusti::atomic_xchg_acq(transmute(dst), src as int))
4442
}
4543
}
4644

47-
fn swap_state_rel(&dst: state, src: state) -> state {
45+
fn swap_state_rel(+dst: &mut state, src: state) -> state {
4846
unsafe {
49-
reinterpret_cast(rusti::atomic_xchng_rel(
50-
*(ptr::mut_addr_of(dst) as *mut int),
51-
src as int))
47+
transmute(rusti::atomic_xchg_rel(transmute(dst), src as int))
5248
}
5349
}
5450

@@ -57,7 +53,7 @@ mod pipes {
5753
let p = unsafe { uniquify(p) };
5854
assert (*p).payload == none;
5955
(*p).payload <- some(payload);
60-
let old_state = swap_state_rel((*p).state, full);
56+
let old_state = swap_state_rel(&mut (*p).state, full);
6157
match old_state {
6258
empty => {
6359
// Yay, fastpath.
@@ -82,7 +78,7 @@ mod pipes {
8278
let p = p.unwrap();
8379
let p = unsafe { uniquify(p) };
8480
loop {
85-
let old_state = swap_state_acq((*p).state,
81+
let old_state = swap_state_acq(&mut (*p).state,
8682
blocked);
8783
match old_state {
8884
empty | blocked => { task::yield(); }
@@ -101,7 +97,7 @@ mod pipes {
10197

10298
fn sender_terminate<T: send>(p: *packet<T>) {
10399
let p = unsafe { uniquify(p) };
104-
match swap_state_rel((*p).state, terminated) {
100+
match swap_state_rel(&mut (*p).state, terminated) {
105101
empty | blocked => {
106102
// The receiver will eventually clean up.
107103
unsafe { forget(p) }
@@ -118,7 +114,7 @@ mod pipes {
118114

119115
fn receiver_terminate<T: send>(p: *packet<T>) {
120116
let p = unsafe { uniquify(p) };
121-
match swap_state_rel((*p).state, terminated) {
117+
match swap_state_rel(&mut (*p).state, terminated) {
122118
empty => {
123119
// the sender will clean up
124120
unsafe { forget(p) }
@@ -179,7 +175,7 @@ mod pingpong {
179175

180176
fn liberate_ping(-p: ping) -> pipes::send_packet<pong> unsafe {
181177
let addr : *pipes::send_packet<pong> = match p {
182-
ping(x) => { unsafe::reinterpret_cast(ptr::addr_of(x)) }
178+
ping(x) => { unsafe::transmute(ptr::addr_of(x)) }
183179
};
184180
let liberated_value <- *addr;
185181
unsafe::forget(p);
@@ -188,7 +184,7 @@ mod pingpong {
188184

189185
fn liberate_pong(-p: pong) -> pipes::send_packet<ping> unsafe {
190186
let addr : *pipes::send_packet<ping> = match p {
191-
pong(x) => { unsafe::reinterpret_cast(ptr::addr_of(x)) }
187+
pong(x) => { unsafe::transmute(ptr::addr_of(x)) }
192188
};
193189
let liberated_value <- *addr;
194190
unsafe::forget(p);

0 commit comments

Comments
 (0)