Skip to content

Commit 017008d

Browse files
authored
Key unqualified dependent calls in rules (#558)
1 parent c96e373 commit 017008d

6 files changed

Lines changed: 121 additions & 2 deletions

File tree

‎cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ std::string DependentExprKey(const clang::Expr *expr) {
179179
}
180180
}
181181
if (auto lookup = llvm::dyn_cast<clang::UnresolvedLookupExpr>(callee);
182-
lookup && lookup->getQualifier() &&
183-
!llvm::isa<clang::CXXOperatorCallExpr>(call) &&
182+
lookup && !llvm::isa<clang::CXXOperatorCallExpr>(call) &&
184183
lookup->decls_begin() != lookup->decls_end()) {
185184
return RulesLoader::DeclKey(
186185
(*lookup->decls_begin())->getUnderlyingDecl());

‎rules/cctype/src.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
#include <ctype.h>
5+
6+
template <typename T1> int f1(T1 a0) { return toupper(a0); }

‎rules/cctype/tgt_unsafe.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
unsafe fn f1<T1: Into<i32>>(a0: T1) -> i32 {
5+
let __c: i32 = a0.into();
6+
if (0..=255).contains(&__c) {
7+
(__c as u8).to_ascii_uppercase() as i32
8+
} else {
9+
__c
10+
}
11+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
extern crate libcc2rs;
2+
use libcc2rs::*;
3+
use std::cell::RefCell;
4+
use std::collections::BTreeMap;
5+
use std::io::prelude::*;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::AsFd;
8+
use std::rc::{Rc, Weak};
9+
pub fn main() {
10+
__cpp2rust_init_globals();
11+
std::process::exit(main_0());
12+
}
13+
fn main_0() -> i32 {
14+
assert!(
15+
({
16+
let __c: i32 = (('a' as i8) as i32).into();
17+
if (0..=255).contains(&__c) {
18+
(__c as u8).to_ascii_uppercase() as i32
19+
} else {
20+
__c
21+
}
22+
} == (('A' as i8) as i32))
23+
);
24+
assert!(
25+
({
26+
let __c: i32 = (('Z' as i8) as i32).into();
27+
if (0..=255).contains(&__c) {
28+
(__c as u8).to_ascii_uppercase() as i32
29+
} else {
30+
__c
31+
}
32+
} == (('Z' as i8) as i32))
33+
);
34+
assert!(
35+
({
36+
let __c: i32 = (('5' as i8) as i32).into();
37+
if (0..=255).contains(&__c) {
38+
(__c as u8).to_ascii_uppercase() as i32
39+
} else {
40+
__c
41+
}
42+
} == (('5' as i8) as i32))
43+
);
44+
return 0;
45+
}
46+
pub fn __cpp2rust_init_globals() {}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
extern crate libc;
2+
use libc::*;
3+
extern crate libcc2rs;
4+
use libcc2rs::*;
5+
use std::collections::BTreeMap;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
8+
use std::rc::Rc;
9+
pub fn main() {
10+
unsafe {
11+
__cpp2rust_init_globals();
12+
std::process::exit(main_0() as i32);
13+
}
14+
}
15+
unsafe fn main_0() -> i32 {
16+
assert!(
17+
(({
18+
let __c: i32 = (('a' as libc::c_char) as i32).into();
19+
if (0..=255).contains(&__c) {
20+
(__c as u8).to_ascii_uppercase() as i32
21+
} else {
22+
__c
23+
}
24+
}) == (('A' as libc::c_char) as i32))
25+
);
26+
assert!(
27+
(({
28+
let __c: i32 = (('Z' as libc::c_char) as i32).into();
29+
if (0..=255).contains(&__c) {
30+
(__c as u8).to_ascii_uppercase() as i32
31+
} else {
32+
__c
33+
}
34+
}) == (('Z' as libc::c_char) as i32))
35+
);
36+
assert!(
37+
(({
38+
let __c: i32 = (('5' as libc::c_char) as i32).into();
39+
if (0..=255).contains(&__c) {
40+
(__c as u8).to_ascii_uppercase() as i32
41+
} else {
42+
__c
43+
}
44+
}) == (('5' as libc::c_char) as i32))
45+
);
46+
return 0;
47+
}
48+
pub unsafe fn __cpp2rust_init_globals() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <cassert>
2+
#include <cctype>
3+
4+
int main() {
5+
assert(toupper('a') == 'A');
6+
assert(toupper('Z') == 'Z');
7+
assert(toupper('5') == '5');
8+
return 0;
9+
}

0 commit comments

Comments
 (0)