Skip to content

Commit c677560

Browse files
committed
Merge branch 'master' into issue-535
2 parents f3d9ac6 + 04c08f4 commit c677560

18 files changed

Lines changed: 119 additions & 6 deletions

File tree

‎cpp2rust/compat/arpa/inet.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@
88
#undef htonl
99
#undef htons
1010

11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
1114
uint32_t cpp2rust_ntohl(uint32_t x);
1215
uint16_t cpp2rust_ntohs(uint16_t x);
1316
uint32_t cpp2rust_htonl(uint32_t x);
1417
uint16_t cpp2rust_htons(uint16_t x);
18+
#ifdef __cplusplus
19+
}
20+
#endif
1521

1622
#define ntohl(x) cpp2rust_ntohl(x)
1723
#define ntohs(x) cpp2rust_ntohs(x)

‎cpp2rust/compat/errno.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
#undef errno
77

8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
811
int *cpp2rust_errno(void);
12+
#ifdef __cplusplus
13+
}
14+
#endif
915

1016
#define errno (*cpp2rust_errno())

‎cpp2rust/compat/sys/select.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@
88
#undef FD_ISSET
99
#undef FD_ZERO
1010

11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
1114
void cpp2rust_fd_set(int fd, fd_set *set);
1215
void cpp2rust_fd_clr(int fd, fd_set *set);
1316
int cpp2rust_fd_isset(int fd, const fd_set *set);
1417
void cpp2rust_fd_zero(fd_set *set);
18+
#ifdef __cplusplus
19+
}
20+
#endif
1521

1622
#define FD_SET(fd, set) cpp2rust_fd_set(fd, set)
1723
#define FD_CLR(fd, set) cpp2rust_fd_clr(fd, set)

‎cpp2rust/converter/rules/expr_matcher.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ using ResolvedDecl =
7575
ResolvedDecl getResolvedDecl(clang::ASTContext &ctx, const clang::Expr *expr,
7676
bool must_resolve) {
7777
expr = RuleDecls::SkipImplicit(expr);
78-
if (llvm::isa<clang::IntegerLiteral>(expr) &&
78+
if (llvm::isa<clang::IntegerLiteral, clang::AtomicExpr>(expr) &&
7979
expr->getBeginLoc().isMacroID()) {
8080
return MacroUsage{
8181
clang::Lexer::getImmediateMacroName(

‎cpp2rust/converter/rules/rule_keys.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ std::optional<ExprKey> getDeclKey(const clang::NamedDecl *decl) {
123123
std::optional<ExprKey> getExprKey(clang::ASTContext &ctx,
124124
const clang::Expr *expr) {
125125
expr = RuleDecls::SkipImplicit(expr);
126-
if (llvm::isa<clang::IntegerLiteral>(expr) &&
126+
if (llvm::isa<clang::IntegerLiteral, clang::AtomicExpr>(expr) &&
127127
expr->getBeginLoc().isMacroID()) {
128128
auto macro = clang::Lexer::getImmediateMacroName(
129129
expr->getBeginLoc(), ctx.getSourceManager(), ctx.getLangOpts());

‎cpp2rust/converter/rules/rules_loader.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ std::string DeclKey(const clang::NamedDecl *decl) {
474474

475475
std::string ExprKey(clang::ASTContext &ctx, const clang::Expr *expr) {
476476
expr = expr->IgnoreParenImpCasts();
477-
if (llvm::isa<clang::IntegerLiteral>(expr) &&
477+
if (llvm::isa<clang::IntegerLiteral, clang::AtomicExpr>(expr) &&
478478
expr->getBeginLoc().isMacroID()) {
479479
return clang::Lexer::getImmediateMacroName(
480480
expr->getBeginLoc(), ctx.getSourceManager(), ctx.getLangOpts())
@@ -523,7 +523,8 @@ std::string TypeKey(clang::QualType type) {
523523
llvm::dyn_cast<clang::TypeOfExprType>(type.getTypePtr())) {
524524
type = typeof_type->getUnderlyingExpr()->getType();
525525
}
526-
if (auto alias = type->getAs<clang::TypedefType>()) {
526+
if (auto alias = type->getAs<clang::TypedefType>();
527+
alias && !type.getCanonicalType()->getAsTagDecl()) {
527528
return DeclKey(alias->getDecl());
528529
}
529530
if (auto sugar = type->getAs<clang::PredefinedSugarType>()) {

‎cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ std::string ExprKey(clang::ASTContext &ctx, const clang::Decl *rule) {
215215

216216
std::string TypeKey(const clang::TypedefNameDecl *rule) {
217217
auto type = rule->getUnderlyingType();
218+
if (auto key = RulesLoader::TypeKey(type); !key.empty()) {
219+
return key;
220+
}
218221
if (!type->isDependentType() && type->getAs<clang::TypedefType>()) {
219222
return RulesLoader::TypeKey(type);
220223
}

‎rules/signal/src.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#define _GNU_SOURCE
66
#include <signal.h>
77

8+
typedef sig_t t1;
9+
810
int f1(int signum, const struct sigaction *act, struct sigaction *oldact) {
911
return sigaction(signum, act, oldact);
1012
}

‎rules/signal/tgt_refcount.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
use libcc2rs::*;
5+
6+
fn t1() -> FnPtr<fn(i32)> {
7+
FnPtr::null()
8+
}

‎rules/signal/tgt_unsafe.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Copyright (c) 2022-present INESC-ID.
22
// Distributed under the MIT license that can be found in the LICENSE file.
33

4+
fn t1() -> Option<unsafe fn(i32)> {
5+
None
6+
}
7+
48
unsafe fn f1(a0: i32, a1: *const ::libc::sigaction, a2: *mut ::libc::sigaction) -> i32 {
59
libc::sigaction(a0, a1, a2)
610
}

0 commit comments

Comments
 (0)