Skip to content

Commit 627d964

Browse files
committed
Save CallExpr instead of callee in CallInfo
1 parent 44a174e commit 627d964

4 files changed

Lines changed: 24 additions & 8 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,20 +1528,20 @@ Converter::CallInfo Converter::CollectCallInfo(clang::CallExpr *expr) {
15281528
using Kind = CallArg::Kind;
15291529

15301530
CallInfo info;
1531-
info.callee = expr->getCallee();
1531+
info.expr = expr;
1532+
auto callee = GetCallee(expr);
15321533
unsigned arg_begin = 0;
15331534
if (auto op_call = llvm::dyn_cast<clang::CXXOperatorCallExpr>(expr)) {
15341535
if (op_call->getOperator() == clang::OO_Call) {
1535-
info.callee = op_call->getArg(0);
15361536
arg_begin = 1;
15371537
}
15381538
}
15391539

1540-
const auto *function =
1541-
expr->getCalleeDecl() ? expr->getCalleeDecl()->getAsFunction() : nullptr;
1540+
auto decl = expr->getCalleeDecl();
1541+
const auto *function = decl ? decl->getAsFunction() : nullptr;
15421542
const clang::FunctionProtoType *proto = nullptr;
15431543
if (!function) {
1544-
auto callee_ty = info.callee->getType().getDesugaredType(ctx_);
1544+
auto callee_ty = callee->getType().getDesugaredType(ctx_);
15451545
if (auto ptr_ty = callee_ty->getAs<clang::PointerType>()) {
15461546
proto = ptr_ty->getPointeeType()->getAs<clang::FunctionProtoType>();
15471547
}
@@ -1658,10 +1658,14 @@ void Converter::EmitCall(CallInfo &&info) {
16581658
EmitHoistedArgs(info);
16591659

16601660
if (info.is_fn_ptr_call) {
1661-
EmitFnPtrCall(info.callee);
1661+
EmitFnPtrCall(GetCallee(info.expr));
1662+
} else if (info.is_libc_passthrough) {
1663+
auto *direct_callee = info.expr->getDirectCallee();
1664+
assert(direct_callee);
1665+
StrCat("libc::", direct_callee->getName());
16621666
} else {
16631667
PushExprKind push(*this, ExprKind::Callee);
1664-
Convert(info.callee);
1668+
Convert(GetCallee(info.expr));
16651669
}
16661670

16671671
EmitArgList(info);

cpp2rust/converter/converter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,10 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
235235
};
236236

237237
struct CallInfo {
238-
clang::Expr *callee;
238+
clang::CallExpr *expr;
239239
bool is_variadic;
240240
bool is_fn_ptr_call;
241+
bool is_libc_passthrough;
241242
std::vector<CallArg> args;
242243
std::vector<clang::Expr *> variadic_args;
243244
};

cpp2rust/converter/converter_lib.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,15 @@ BuildUnifiedArgs(clang::Expr *expr, clang::Expr **args, unsigned num_args) {
588588
return all_args;
589589
}
590590

591+
clang::Expr *GetCallee(clang::CallExpr *expr) {
592+
if (auto op_call = clang::dyn_cast<clang::CXXOperatorCallExpr>(expr)) {
593+
if (op_call->getOperator() == clang::OO_Call) {
594+
return op_call->getArg(0);
595+
}
596+
}
597+
return expr->getCallee();
598+
}
599+
591600
clang::Expr *GetCalleeOrExpr(clang::Expr *expr) {
592601
if (auto *call = clang::dyn_cast<clang::CallExpr>(expr)) {
593602
return call->getCallee();

cpp2rust/converter/converter_lib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ void ForEachTemplateArgument(
129129

130130
clang::Expr *GetCallObject(clang::CallExpr *expr);
131131

132+
clang::Expr *GetCallee(clang::CallExpr *expr);
133+
132134
clang::Expr *GetCalleeOrExpr(clang::Expr *expr);
133135

134136
bool HasReceiver(clang::Expr *expr);

0 commit comments

Comments
 (0)