Skip to content

Commit f9eb263

Browse files
authored
Merge origin/master into copilot/rust-2024-compatibility-fix
2 parents 55c480d + 8009afc commit f9eb263

213 files changed

Lines changed: 662 additions & 2765 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cpp2rust/converter/converter.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,7 @@ Converter::CallInfo Converter::CollectCallInfo(clang::CallExpr *expr) {
16351635
: proto->getParamType(i),
16361636
.expr = arg,
16371637
.has_default = function && function->getParamDecl(i)->hasDefaultArg(),
1638-
.kind = Kind::Hoisted,
1638+
.kind = IsLiteral(arg) ? Kind::Inline : Kind::Hoisted,
16391639
};
16401640
bool is_materialize = clang::isa<clang::MaterializeTemporaryExpr>(arg);
16411641
if (is_materialize && ca.param_type->isLValueReferenceType()) {
@@ -2373,7 +2373,6 @@ bool Converter::ConvertIncAndDec(clang::UnaryOperator *expr) {
23732373
default:
23742374
return false;
23752375
}
2376-
std::unreachable();
23772376
}
23782377

23792378
bool Converter::VisitUnaryOperator(clang::UnaryOperator *expr) {
@@ -2840,7 +2839,7 @@ bool Converter::VisitInitListExpr(clang::InitListExpr *expr) {
28402839
if (auto arr_ty = ctx_.getAsConstantArrayType(expr->getType())) {
28412840
assert(
28422841
(arr_ty->getSize().getZExtValue() - expr->getNumInits()) &&
2843-
"Number of initializers should be less that total size of array");
2842+
"Number of initializers should be less than total size of array");
28442843
for (unsigned i = 0;
28452844
i < arr_ty->getSize().getZExtValue() - expr->getNumInits(); ++i) {
28462845
ConvertVarInit(expr->getArrayFiller()->getType(),
@@ -3028,7 +3027,7 @@ bool Converter::VisitCXXConstructExpr(clang::CXXConstructExpr *expr) {
30283027
if (ctor->isCopyOrMoveConstructor() ||
30293028
(ctor->isConvertingConstructor(false) && ctor->getNumParams() == 1 &&
30303029
ctor->getParamDecl(0)->getType()->isRValueReferenceType())) {
3031-
// Take supress before recursing into the child.
3030+
// Take suppress before recursing into the child.
30323031
bool suppress = PushSuppressIteratorClone::take(*this);
30333032
Convert(expr->getArg(0));
30343033
if (ctor->isCopyConstructor() && !suppress) {

cpp2rust/converter/converter_lib.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,14 @@ bool IsAsciiStringLiteral(const clang::StringLiteral *str) {
265265
return true;
266266
}
267267

268+
bool IsLiteral(const clang::Expr *expr) {
269+
expr = expr->IgnoreParenImpCasts();
270+
return clang::isa<clang::IntegerLiteral, clang::FloatingLiteral,
271+
clang::StringLiteral, clang::CharacterLiteral,
272+
clang::CXXBoolLiteralExpr, clang::FixedPointLiteral,
273+
clang::ImaginaryLiteral>(expr);
274+
}
275+
268276
bool IsInitExprOfStringLiteral(const clang::InitListExpr *expr) {
269277
auto type = expr->getType();
270278
return expr->getNumInits() == 1 && type->isArrayType() &&

cpp2rust/converter/converter_lib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ bool IsAsciiStringLiteral(const clang::StringLiteral *str);
7171

7272
bool IsInitExprOfStringLiteral(const clang::InitListExpr *expr);
7373

74+
bool IsLiteral(const clang::Expr *expr);
75+
7476
std::vector<clang::CXXConstructorDecl *>
7577
GetTemplateInstantiatedCtors(clang::CXXRecordDecl *decl);
7678

tests/benchmarks/out/refcount/bfs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ fn main_0() -> i32 {
225225
let pred: Value<Ptr<u32>> = Rc::new(RefCell::new(
226226
({
227227
let _graph: Ptr<Graph> = graph.as_pointer();
228-
let _start_vertex: u32 = 0_u32;
229-
BFS_0(_graph, _start_vertex)
228+
BFS_0(_graph, 0_u32)
230229
}),
231230
));
232231
let i: Value<u32> = Rc::new(RefCell::new(0_u32));

tests/benchmarks/out/refcount/fibonacci.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,5 @@ pub fn main() {
2727
std::process::exit(main_0());
2828
}
2929
fn main_0() -> i32 {
30-
return (({
31-
let _n: u64 = 46_u64;
32-
fib_0(_n)
33-
}) as i32);
30+
return (({ fib_0(46_u64) }) as i32);
3431
}

tests/benchmarks/out/unsafe/bfs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ unsafe fn main_0() -> i32 {
159159
}
160160
let mut pred: *mut u32 = (unsafe {
161161
let _graph: *const Graph = &graph as *const Graph;
162-
let _start_vertex: u32 = 0_u32;
163-
BFS_0(_graph, _start_vertex)
162+
BFS_0(_graph, 0_u32)
164163
});
165164
let mut i: u32 = 0_u32;
166165
'loop_: while ((i as u64) < (V)) {

tests/benchmarks/out/unsafe/fibonacci.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,5 @@ pub fn main() {
2828
}
2929
}
3030
unsafe fn main_0() -> i32 {
31-
return ((unsafe {
32-
let _n: u64 = 46_u64;
33-
fib_0(_n)
34-
}) as i32);
31+
return ((unsafe { fib_0(46_u64) }) as i32);
3532
}

tests/multi-file/extern_functions/out/refcount/extern_functions.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ pub fn main() {
1010
std::process::exit(main_0());
1111
}
1212
fn main_0() -> i32 {
13-
assert!(
14-
(((({
15-
let _x: i32 = 42;
16-
helper_0(_x)
17-
}) == 43) as i32)
18-
!= 0)
19-
);
13+
assert!((((({ helper_0(42,) }) == 43) as i32) != 0));
2014
return 0;
2115
}
2216
pub fn unrelated1_1() -> i32 {

tests/multi-file/extern_functions/out/unsafe/extern_functions.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ pub fn main() {
1212
}
1313
}
1414
unsafe fn main_0() -> i32 {
15-
assert!(
16-
((((unsafe {
17-
let _x: i32 = 42;
18-
helper_0(_x)
19-
}) == (43)) as i32)
20-
!= 0)
21-
);
15+
assert!(((((unsafe { helper_0(42,) }) == (43)) as i32) != 0));
2216
return 0;
2317
}
2418
pub unsafe fn unrelated1_1() -> i32 {

tests/multi-file/header_function/out/refcount/header_function.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ pub fn main() {
1010
std::process::exit(main_0());
1111
}
1212
fn main_0() -> i32 {
13-
assert!(
14-
(((({
15-
let _x: i32 = 42;
16-
helper_0(_x)
17-
}) == 43) as i32)
18-
!= 0)
19-
);
13+
assert!((((({ helper_0(42,) }) == 43) as i32) != 0));
2014
return 0;
2115
}
2216
pub fn unrelated1_1() -> i32 {

0 commit comments

Comments
 (0)