Skip to content

Commit f483ee5

Browse files
Check value-used pointer subtraction
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
1 parent 3c3885e commit f483ee5

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

‎tests/unit/assign_as_value.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ int main(void) {
55
char *p = buf, *q;
66
q = p += 1;
77
assert(q == buf + 1);
8+
q = p -= 1;
9+
assert(p == buf);
10+
assert(q == buf);
811

912
char out;
1013
switch (out = 'x') {

‎tests/unit/out/refcount/assign_as_value.rs‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,24 @@ fn main_0() -> i32 {
2323
}
2424
};
2525
assert!(({ (q).clone() } == { buf.decay().offset((1) as isize) }));
26+
q = {
27+
match ({ 1 }, &mut (p)) {
28+
(__tmp_2, __tmp_3) => {
29+
(*__tmp_3) = (*__tmp_3).offset(-(__tmp_2 as isize));
30+
(*__tmp_3).clone()
31+
}
32+
}
33+
};
34+
assert!(({ (p).clone() } == { buf.decay() }));
35+
assert!(({ (q).clone() } == { buf.decay() }));
2636
let mut out: i8 = 0_i8;
2737
'switch: {
2838
match {
2939
(({
3040
match ({ (('x' as i32) as i8) }, &mut (out)) {
31-
(__tmp_2, __tmp_3) => {
32-
(*__tmp_3) = __tmp_2;
33-
(*__tmp_3).clone()
41+
(__tmp_4, __tmp_5) => {
42+
(*__tmp_5) = __tmp_4;
43+
(*__tmp_5).clone()
3444
}
3545
}
3646
}) as i32)

‎tests/unit/out/unsafe/assign_as_value.rs‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,21 @@ unsafe fn main_0() -> i32 {
2323
}
2424
};
2525
assert!(((q) == (buf.as_mut_ptr().offset((1) as isize))));
26+
q = match ({ 1 }, &mut (p)) {
27+
(__tmp_2, __tmp_3) => {
28+
(*__tmp_3) = (*__tmp_3).offset(-(__tmp_2 as isize));
29+
(*__tmp_3).clone()
30+
}
31+
};
32+
assert!(((p) == (buf.as_mut_ptr())));
33+
assert!(((q) == (buf.as_mut_ptr())));
2634
let mut out: libc::c_char = (0 as libc::c_char);
2735
'switch: {
2836
match {
2937
((match ({ (('x' as i32) as libc::c_char) }, &mut (out)) {
30-
(__tmp_2, __tmp_3) => {
31-
(*__tmp_3) = __tmp_2;
32-
(*__tmp_3).clone()
38+
(__tmp_4, __tmp_5) => {
39+
(*__tmp_5) = __tmp_4;
40+
(*__tmp_5).clone()
3341
}
3442
}) as i32)
3543
} {

0 commit comments

Comments
 (0)