File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1524,11 +1524,9 @@ bool Converter::VisitCallExpr(clang::CallExpr *expr) {
15241524 }
15251525
15261526 if (Mapper::Contains (expr->getCallee ())) {
1527- if (auto tgt_ir = Mapper::GetExprRule (GetCalleeOrExpr (expr))) {
1528- if (tgt_ir->body .empty () && tgt_ir->is_variadic ) {
1529- ConvertGenericCallExpr (expr);
1530- return false ;
1531- }
1527+ if (Mapper::IsLibcPassthrough (GetCalleeOrExpr (expr))) {
1528+ ConvertGenericCallExpr (expr);
1529+ return false ;
15321530 }
15331531
15341532 auto **args = expr->getArgs ();
@@ -1631,12 +1629,7 @@ Converter::CallInfo Converter::CollectCallInfo(clang::CallExpr *expr) {
16311629 function ? function->getNumParams () : proto->getNumParams ();
16321630 info.is_variadic = function ? function->isVariadic () : proto->isVariadic ();
16331631 info.is_fn_ptr_call = !function;
1634- info.is_libc_passthrough = false ;
1635- if (auto tgt_ir = Mapper::GetExprRule (GetCalleeOrExpr (expr))) {
1636- if (tgt_ir->body .empty () && tgt_ir->is_variadic ) {
1637- info.is_libc_passthrough = true ;
1638- }
1639- }
1632+ info.is_libc_passthrough = Mapper::IsLibcPassthrough (GetCalleeOrExpr (expr));
16401633
16411634 for (unsigned i = 0 ; i < num_named_params && i < num_args; ++i) {
16421635 auto *arg = expr->getArg (i + arg_begin);
Original file line number Diff line number Diff line change @@ -588,6 +588,19 @@ const TranslationRule::ExprRule *GetExprRule(const clang::Expr *expr) {
588588 return search (expr);
589589}
590590
591+ bool IsLibcPassthrough (const clang::Expr *expr) {
592+ const auto *tgt_ir = GetExprRule (expr);
593+ if (tgt_ir == nullptr || !tgt_ir->body .empty () || !tgt_ir->is_extern ) {
594+ return false ;
595+ }
596+ const auto *ref =
597+ clang::dyn_cast<clang::DeclRefExpr>(expr->IgnoreParenImpCasts ());
598+ const auto *decl = ref != nullptr ? ref->getDecl () : nullptr ;
599+ return decl != nullptr &&
600+ decl->getASTContext ().getSourceManager ().isInSystemHeader (
601+ decl->getLocation ());
602+ }
603+
591604std::string MapFunctionName (const clang::FunctionDecl *decl) {
592605 assert (decl);
593606 if (!IsUserDefinedDecl (decl) &&
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ bool Contains(const clang::Expr *expr);
3030std::string Map (clang::QualType qual_type);
3131std::string MapInitializer (clang::QualType qual_type);
3232const TranslationRule::ExprRule *GetExprRule (const clang::Expr *expr);
33+ bool IsLibcPassthrough (const clang::Expr *expr);
3334std::string MapFunctionName (const clang::FunctionDecl *decl);
3435std::string InstantiateTemplate (const clang::Expr *expr, unsigned n);
3536bool ReturnsPointer (const clang::Expr *expr);
You can’t perform that action at this time.
0 commit comments