Skip to content

Commit 8fb2e89

Browse files
authored
Fix args: &[VaArg] name collision (#80)
`args` can create a name collision with a local variable named `args`. Rename the `args` argument to `__args`
1 parent 5d052ba commit 8fb2e89

26 files changed

Lines changed: 61 additions & 60 deletions

cpp2rust/converter/converter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,8 @@ std::optional<std::string> Converter::TryPluginConvert(clang::CallExpr *call) {
13631363

13641364
void Converter::ConvertVAArgCall(clang::CallExpr *expr) {
13651365
if (IsBuiltinVaStart(expr)) {
1366-
StrCat(ToString(expr->getArg(0)->IgnoreImpCasts()), "= VaList::new(args)");
1366+
StrCat(ToString(expr->getArg(0)->IgnoreImpCasts()),
1367+
"= VaList::new(__args)");
13671368
return;
13681369
}
13691370
if (IsBuiltinVaEnd(expr)) {
@@ -3289,7 +3290,7 @@ void Converter::ConvertFunctionParameters(clang::FunctionDecl *decl) {
32893290
StrCat(token::kComma);
32903291
}
32913292
if (decl->isVariadic()) {
3292-
StrCat("args: &[VaArg]", token::kComma);
3293+
StrCat("__args: &[VaArg]", token::kComma);
32933294
}
32943295
in_function_formals_ = false;
32953296
}

tests/unit/out/refcount/va_arg_chain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ pub fn middle_layer_1(n: i32, ap: VaList) -> i32 {
2525
extract_nth_0(_n, _ap)
2626
});
2727
}
28-
pub fn top_level_2(n: i32, args: &[VaArg]) -> i32 {
28+
pub fn top_level_2(n: i32, __args: &[VaArg]) -> i32 {
2929
let n: Value<i32> = Rc::new(RefCell::new(n));
3030
let ap: Value<VaList> = Rc::new(RefCell::new(VaList::default()));
31-
(*ap.borrow_mut()) = VaList::new(args);
31+
(*ap.borrow_mut()) = VaList::new(__args);
3232
let result: Value<i32> = Rc::new(RefCell::new(
3333
({
3434
let _n: i32 = (*n.borrow());

tests/unit/out/refcount/va_arg_concat.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ use std::io::prelude::*;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
use std::rc::{Rc, Weak};
9-
pub fn sum_ints_0(first: i32, args: &[VaArg]) -> i32 {
9+
pub fn sum_ints_0(first: i32, __args: &[VaArg]) -> i32 {
1010
let first: Value<i32> = Rc::new(RefCell::new(first));
11-
let ap: Value<VaList> = Rc::new(RefCell::new(VaList::default()));
11+
let args: Value<VaList> = Rc::new(RefCell::new(VaList::default()));
1212
let total: Value<i32> = Rc::new(RefCell::new((*first.borrow())));
13-
(*ap.borrow_mut()) = VaList::new(args);
13+
(*args.borrow_mut()) = VaList::new(__args);
1414
let val: Value<i32> = <Value<i32>>::default();
1515
'loop_: while (((({
16-
(*val.borrow_mut()) = ((*ap.borrow_mut()).arg::<i32>()).clone();
16+
(*val.borrow_mut()) = ((*args.borrow_mut()).arg::<i32>()).clone();
1717
(*val.borrow())
1818
}) != 0) as i32)
1919
!= 0)

tests/unit/out/refcount/va_arg_conditional.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use std::io::prelude::*;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
use std::rc::{Rc, Weak};
9-
pub fn conditional_log_0(verbose: i32, fmt: Ptr<u8>, args: &[VaArg]) -> i32 {
9+
pub fn conditional_log_0(verbose: i32, fmt: Ptr<u8>, __args: &[VaArg]) -> i32 {
1010
let verbose: Value<i32> = Rc::new(RefCell::new(verbose));
1111
let fmt: Value<Ptr<u8>> = Rc::new(RefCell::new(fmt));
1212
if ((*verbose.borrow()) != 0) {
1313
let ap: Value<VaList> = Rc::new(RefCell::new(VaList::default()));
14-
(*ap.borrow_mut()) = VaList::new(args);
14+
(*ap.borrow_mut()) = VaList::new(__args);
1515
let result: Value<i32> = Rc::new(RefCell::new(((*ap.borrow_mut()).arg::<i32>()).clone()));
1616
return (*result.borrow());
1717
}

tests/unit/out/refcount/va_arg_copy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use std::io::prelude::*;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
use std::rc::{Rc, Weak};
9-
pub fn sum_with_copy_0(count: i32, args: &[VaArg]) -> i32 {
9+
pub fn sum_with_copy_0(count: i32, __args: &[VaArg]) -> i32 {
1010
let count: Value<i32> = Rc::new(RefCell::new(count));
1111
let ap: Value<VaList> = Rc::new(RefCell::new(VaList::default()));
1212
let aq: Value<VaList> = Rc::new(RefCell::new(VaList::default()));
13-
(*ap.borrow_mut()) = VaList::new(args);
13+
(*ap.borrow_mut()) = VaList::new(__args);
1414
(*aq.borrow_mut()) = (*ap.borrow_mut()).clone();
1515
let sum1: Value<i32> = Rc::new(RefCell::new(0));
1616
let i: Value<i32> = Rc::new(RefCell::new(0));

tests/unit/out/refcount/va_arg_forward.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ pub fn inner_0(count: i32, ap: VaList) -> i32 {
1717
}
1818
return (*total.borrow());
1919
}
20-
pub fn outer_1(count: i32, args: &[VaArg]) -> i32 {
20+
pub fn outer_1(count: i32, __args: &[VaArg]) -> i32 {
2121
let count: Value<i32> = Rc::new(RefCell::new(count));
2222
let ap: Value<VaList> = Rc::new(RefCell::new(VaList::default()));
23-
(*ap.borrow_mut()) = VaList::new(args);
23+
(*ap.borrow_mut()) = VaList::new(__args);
2424
let result: Value<i32> = Rc::new(RefCell::new(
2525
({
2626
let _count: i32 = (*count.borrow());

tests/unit/out/refcount/va_arg_mixed_int_ptr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use std::io::prelude::*;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
use std::rc::{Rc, Weak};
9-
pub fn mixed_args_0(count: i32, args: &[VaArg]) -> i32 {
9+
pub fn mixed_args_0(count: i32, __args: &[VaArg]) -> i32 {
1010
let count: Value<i32> = Rc::new(RefCell::new(count));
1111
let ap: Value<VaList> = Rc::new(RefCell::new(VaList::default()));
12-
(*ap.borrow_mut()) = VaList::new(args);
12+
(*ap.borrow_mut()) = VaList::new(__args);
1313
let total: Value<i32> = Rc::new(RefCell::new(0));
1414
let i: Value<i32> = Rc::new(RefCell::new(0));
1515
'loop_: while ((((*i.borrow()) < (*count.borrow())) as i32) != 0) {

tests/unit/out/refcount/va_arg_mixed_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use std::io::prelude::*;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
use std::rc::{Rc, Weak};
9-
pub fn sum_mixed_0(count: i32, args: &[VaArg]) -> i32 {
9+
pub fn sum_mixed_0(count: i32, __args: &[VaArg]) -> i32 {
1010
let count: Value<i32> = Rc::new(RefCell::new(count));
1111
let ap: Value<VaList> = Rc::new(RefCell::new(VaList::default()));
12-
(*ap.borrow_mut()) = VaList::new(args);
12+
(*ap.borrow_mut()) = VaList::new(__args);
1313
let total: Value<i32> = Rc::new(RefCell::new(0));
1414
let i: Value<i32> = Rc::new(RefCell::new(0));
1515
'loop_: while ((((*i.borrow()) < (*count.borrow())) as i32) != 0) {

tests/unit/out/refcount/va_arg_printf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ pub fn logf_impl_0(fmt: Ptr<u8>, ap: VaList) -> i32 {
1515
_lhs + ((*ap.borrow_mut()).arg::<i32>()).clone()
1616
};
1717
}
18-
pub fn logf_1(fmt: Ptr<u8>, args: &[VaArg]) -> i32 {
18+
pub fn logf_1(fmt: Ptr<u8>, __args: &[VaArg]) -> i32 {
1919
let fmt: Value<Ptr<u8>> = Rc::new(RefCell::new(fmt));
2020
let ap: Value<VaList> = Rc::new(RefCell::new(VaList::default()));
21-
(*ap.borrow_mut()) = VaList::new(args);
21+
(*ap.borrow_mut()) = VaList::new(__args);
2222
let result: Value<i32> = Rc::new(RefCell::new(
2323
({
2424
let _fmt: Ptr<u8> = (*fmt.borrow()).clone();

tests/unit/out/refcount/va_arg_promotion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use std::io::prelude::*;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
use std::rc::{Rc, Weak};
9-
pub fn test_promotions_0(count: i32, args: &[VaArg]) -> i32 {
9+
pub fn test_promotions_0(count: i32, __args: &[VaArg]) -> i32 {
1010
let count: Value<i32> = Rc::new(RefCell::new(count));
1111
let ap: Value<VaList> = Rc::new(RefCell::new(VaList::default()));
12-
(*ap.borrow_mut()) = VaList::new(args);
12+
(*ap.borrow_mut()) = VaList::new(__args);
1313
let a: Value<i32> = Rc::new(RefCell::new(((*ap.borrow_mut()).arg::<i32>()).clone()));
1414
let b: Value<i32> = Rc::new(RefCell::new(((*ap.borrow_mut()).arg::<i32>()).clone()));
1515
let c: Value<f64> = Rc::new(RefCell::new(((*ap.borrow_mut()).arg::<f64>()).clone()));

0 commit comments

Comments
 (0)