Skip to content

Commit f41f145

Browse files
committed
Fix clash between switch arm variable and local variable (#172)
1 parent 891afa8 commit f41f145

11 files changed

Lines changed: 46 additions & 46 deletions

cpp2rust/converter/converter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3146,7 +3146,7 @@ bool Converter::ConvertSwitchCaseCondition(clang::SwitchCase *stmt) {
31463146
while (auto *sc = clang::dyn_cast<clang::SwitchCase>(cur)) {
31473147
if (auto *case_stmt = clang::dyn_cast<clang::CaseStmt>(sc)) {
31483148
if (!first) {
3149-
StrCat("|| v == ");
3149+
StrCat("|| __v == ");
31503150
}
31513151
Convert(case_stmt->getLHS());
31523152
}
@@ -3168,7 +3168,7 @@ void Converter::EmitSwitchArm(clang::CompoundStmt *body, clang::SwitchCase *sc,
31683168
if (is_default) {
31693169
StrCat("_ => {");
31703170
} else {
3171-
StrCat("v if v == ");
3171+
StrCat("__v if __v == ");
31723172
ConvertSwitchCaseCondition(sc);
31733173
}
31743174
for (auto *t : GetSwitchCaseBody(body, sc)) {

tests/unit/out/refcount/enum_int_interop.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,16 @@ pub fn classify_option_5(option: i32) -> i32 {
116116
'switch: {
117117
let __match_cond = (*option.borrow());
118118
match __match_cond {
119-
v if v == (Option::OPT_NONE as i32) => {
119+
__v if __v == (Option::OPT_NONE as i32) => {
120120
return -1_i32;
121121
}
122-
v if v == (Option::OPT_A as i32) => {
122+
__v if __v == (Option::OPT_A as i32) => {
123123
return 1;
124124
}
125-
v if v == (Option::OPT_B as i32) => {
125+
__v if __v == (Option::OPT_B as i32) => {
126126
return 2;
127127
}
128-
v if v == (Option::OPT_C as i32) => {
128+
__v if __v == (Option::OPT_C as i32) => {
129129
return 3;
130130
}
131131
_ => {
@@ -153,13 +153,13 @@ fn main_0() -> i32 {
153153
'switch: {
154154
let __match_cond = ((*c.borrow()) as i32);
155155
match __match_cond {
156-
v if v == 0 => {
156+
__v if __v == 0 => {
157157
break 'switch;
158158
}
159-
v if v == 1 => {
159+
__v if __v == 1 => {
160160
return 1;
161161
}
162-
v if v == 2 => {
162+
__v if __v == 2 => {
163163
return 2;
164164
}
165165
_ => {
@@ -215,13 +215,13 @@ fn main_0() -> i32 {
215215
'switch: {
216216
let __match_cond = ((*t.borrow()) as i32);
217217
match __match_cond {
218-
v if v == (Tag::TAG_ZERO as i32) => {
218+
__v if __v == (Tag::TAG_ZERO as i32) => {
219219
return 90;
220220
}
221-
v if v == 1 => {
221+
__v if __v == 1 => {
222222
return 91;
223223
}
224-
v if v == 2 => {
224+
__v if __v == 2 => {
225225
break 'switch;
226226
}
227227
_ => {}

tests/unit/out/refcount/enum_int_interop_c.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,16 @@ pub fn classify_option_5(option: i32) -> i32 {
106106
'switch: {
107107
let __match_cond = (*option.borrow());
108108
match __match_cond {
109-
v if v == (Option::OPT_NONE as i32) => {
109+
__v if __v == (Option::OPT_NONE as i32) => {
110110
return -1_i32;
111111
}
112-
v if v == (Option::OPT_A as i32) => {
112+
__v if __v == (Option::OPT_A as i32) => {
113113
return 1;
114114
}
115-
v if v == (Option::OPT_B as i32) => {
115+
__v if __v == (Option::OPT_B as i32) => {
116116
return 2;
117117
}
118-
v if v == (Option::OPT_C as i32) => {
118+
__v if __v == (Option::OPT_C as i32) => {
119119
return 3;
120120
}
121121
_ => {
@@ -143,13 +143,13 @@ fn main_0() -> i32 {
143143
'switch: {
144144
let __match_cond = ((*c.borrow()) as u32);
145145
match __match_cond {
146-
v if v == (0 as u32) => {
146+
__v if __v == (0 as u32) => {
147147
break 'switch;
148148
}
149-
v if v == (1 as u32) => {
149+
__v if __v == (1 as u32) => {
150150
return 1;
151151
}
152-
v if v == (2 as u32) => {
152+
__v if __v == (2 as u32) => {
153153
return 2;
154154
}
155155
_ => {
@@ -209,13 +209,13 @@ fn main_0() -> i32 {
209209
'switch: {
210210
let __match_cond = ((*t.borrow()) as u32);
211211
match __match_cond {
212-
v if v == ((Tag_enum::TAG_ZERO as i32) as u32) => {
212+
__v if __v == ((Tag_enum::TAG_ZERO as i32) as u32) => {
213213
return 90;
214214
}
215-
v if v == (1 as u32) => {
215+
__v if __v == (1 as u32) => {
216216
return 91;
217217
}
218-
v if v == (2 as u32) => {
218+
__v if __v == (2 as u32) => {
219219
break 'switch;
220220
}
221221
_ => {}

tests/unit/out/refcount/goto_cleanup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn from_switch_2(n: i32) -> i32 {
5656
'switch: {
5757
let __match_cond = (*n.borrow());
5858
match __match_cond {
59-
v if v == 1 => {
59+
__v if __v == 1 => {
6060
(*ret.borrow_mut()) = 10;
6161
goto!('out);
6262
}

tests/unit/out/refcount/goto_switch_fallthrough.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ pub fn sm_0(n: i32) -> i32 {
1313
'__entry: {
1414
*ret.borrow_mut() = 0;
1515
switch!(match (*n.borrow()) {
16-
v if v == 0 => {
16+
__v if __v == 0 => {
1717
(*ret.borrow_mut()) += 1;
1818
}
19-
v if v == 1 => {
19+
__v if __v == 1 => {
2020
(*ret.borrow_mut()) += 10;
2121
goto!('out);
2222
}

tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,29 @@ pub fn dispatch_0(option: i32, __args: &[VaArg]) -> i32 {
4040
'switch: {
4141
let __match_cond = (*option.borrow());
4242
match __match_cond {
43-
v if v == (opt::OPT_STRING_OUT as i32) => {
43+
__v if __v == (opt::OPT_STRING_OUT as i32) => {
4444
let out: Value<Ptr<Ptr<u8>>> = Rc::new(RefCell::new(
4545
((*ap.borrow_mut()).arg::<Ptr<Ptr<u8>>>()).clone(),
4646
));
4747
(*out.borrow()).write(Ptr::from_string_literal(b"hello"));
4848
(*result.borrow_mut()) = 1;
4949
break 'switch;
5050
}
51-
v if v == (opt::OPT_FILE as i32) => {
51+
__v if __v == (opt::OPT_FILE as i32) => {
5252
let f: Value<Ptr<::std::fs::File>> = Rc::new(RefCell::new(
5353
((*ap.borrow_mut()).arg::<Ptr<::std::fs::File>>()).clone(),
5454
));
5555
(*result.borrow_mut()) = ((!((*f.borrow()).is_null())) as i32).clone();
5656
break 'switch;
5757
}
58-
v if v == (opt::OPT_NODE as i32) => {
58+
__v if __v == (opt::OPT_NODE as i32) => {
5959
let n: Value<Ptr<node>> = Rc::new(RefCell::new(
6060
((*ap.borrow_mut()).arg::<Ptr<node>>()).clone(),
6161
));
6262
(*result.borrow_mut()) = (*(*(*n.borrow()).upgrade().deref()).data.borrow());
6363
break 'switch;
6464
}
65-
v if v == (opt::OPT_NODE_OUT as i32) => {
65+
__v if __v == (opt::OPT_NODE_OUT as i32) => {
6666
let out: Value<Ptr<Ptr<node>>> = Rc::new(RefCell::new(
6767
((*ap.borrow_mut()).arg::<Ptr<Ptr<node>>>()).clone(),
6868
));

tests/unit/out/unsafe/enum_int_interop_c.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,16 @@ pub unsafe fn classify_option_5(mut option: i32) -> i32 {
9898
'switch: {
9999
let __match_cond = option;
100100
match __match_cond {
101-
v if v == (Option::OPT_NONE as i32) => {
101+
__v if __v == (Option::OPT_NONE as i32) => {
102102
return -1_i32;
103103
}
104-
v if v == (Option::OPT_A as i32) => {
104+
__v if __v == (Option::OPT_A as i32) => {
105105
return 1;
106106
}
107-
v if v == (Option::OPT_B as i32) => {
107+
__v if __v == (Option::OPT_B as i32) => {
108108
return 2;
109109
}
110-
v if v == (Option::OPT_C as i32) => {
110+
__v if __v == (Option::OPT_C as i32) => {
111111
return 3;
112112
}
113113
_ => {
@@ -136,13 +136,13 @@ unsafe fn main_0() -> i32 {
136136
'switch: {
137137
let __match_cond = (c as u32);
138138
match __match_cond {
139-
v if v == (0 as u32) => {
139+
__v if __v == (0 as u32) => {
140140
break 'switch;
141141
}
142-
v if v == (1 as u32) => {
142+
__v if __v == (1 as u32) => {
143143
return 1;
144144
}
145-
v if v == (2 as u32) => {
145+
__v if __v == (2 as u32) => {
146146
return 2;
147147
}
148148
_ => {
@@ -196,13 +196,13 @@ unsafe fn main_0() -> i32 {
196196
'switch: {
197197
let __match_cond = (t as u32);
198198
match __match_cond {
199-
v if v == ((Tag_enum::TAG_ZERO as i32) as u32) => {
199+
__v if __v == ((Tag_enum::TAG_ZERO as i32) as u32) => {
200200
return 90;
201201
}
202-
v if v == (1 as u32) => {
202+
__v if __v == (1 as u32) => {
203203
return 91;
204204
}
205-
v if v == (2 as u32) => {
205+
__v if __v == (2 as u32) => {
206206
break 'switch;
207207
}
208208
_ => {}

tests/unit/out/unsafe/goto_cleanup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub unsafe fn from_switch_2(mut n: i32) -> i32 {
5353
'switch: {
5454
let __match_cond = n;
5555
match __match_cond {
56-
v if v == 1 => {
56+
__v if __v == 1 => {
5757
ret = 10;
5858
goto!('out);
5959
}

tests/unit/out/unsafe/goto_switch_fallthrough.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ pub unsafe fn sm_0(mut n: i32) -> i32 {
1212
'__entry: {
1313
ret = 0;
1414
switch!(match n {
15-
v if v == 0 => {
15+
__v if __v == 0 => {
1616
ret += 1;
1717
}
18-
v if v == 1 => {
18+
__v if __v == 1 => {
1919
ret += 10;
2020
goto!('out);
2121
}

tests/unit/out/unsafe/union_void_ptr_sized_deref.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ pub unsafe fn write_count_1(mut s: *mut Sink, mut count: i64) {
4747
'switch: {
4848
let __match_cond = ((*s).width as u32);
4949
match __match_cond {
50-
v if v == ((Width_enum::W_64 as i32) as u32) => {
50+
__v if __v == ((Width_enum::W_64 as i32) as u32) => {
5151
(*((*s).out.handle as *mut i64)) = count;
5252
break 'switch;
5353
}
54-
v if v == ((Width_enum::W_32 as i32) as u32) => {
54+
__v if __v == ((Width_enum::W_32 as i32) as u32) => {
5555
(*((*s).out.handle as *mut i32)) = (count as i32);
5656
break 'switch;
5757
}
58-
v if v == ((Width_enum::W_16 as i32) as u32) => {
58+
__v if __v == ((Width_enum::W_16 as i32) as u32) => {
5959
(*((*s).out.handle as *mut i16)) = (count as i16);
6060
break 'switch;
6161
}

0 commit comments

Comments
 (0)