@@ -2039,12 +2039,29 @@ void Converter::ConvertParamTy(clang::QualType param_type, clang::Expr *expr) {
20392039 if (param_type->isReferenceType ()) {
20402040 PushExprKind push (*this , ExprKind::AddrOf);
20412041 ConvertVarInit (param_type, expr);
2042+ } else if (FunctionPointerCastNeedsTransmute () &&
2043+ param_type->isFunctionPointerType () &&
2044+ expr->getType ()->isFunctionPointerType () &&
2045+ !IsCastRedundantInRust (expr, param_type)) {
2046+ ConvertFunctionPointerTransmute (expr, param_type);
2047+ return ;
20422048 } else {
20432049 ConvertVarInit (param_type, expr);
20442050 }
20452051 ConvertParamTyPointerCastIfNeeded (param_type, expr);
20462052}
20472053
2054+ void Converter::ConvertFunctionPointerTransmute (clang::Expr *expr,
2055+ clang::QualType type) {
2056+ StrCat (" std::mem::transmute::<" );
2057+ Convert (expr->getType ());
2058+ StrCat (' ,' );
2059+ Convert (type);
2060+ StrCat (" >(" );
2061+ Convert (expr);
2062+ StrCat (' )' );
2063+ }
2064+
20482065void Converter::ConvertParamTyPointerCastIfNeeded (clang::QualType param_type,
20492066 clang::Expr *expr) {
20502067 if (!param_type->isPointerType () || !expr->getType ()->isPointerType () ||
@@ -2625,13 +2642,7 @@ bool Converter::VisitExplicitCastExpr(clang::ExplicitCastExpr *expr) {
26252642 }
26262643 if (type->isFunctionPointerType () ||
26272644 sub_expr->getType ()->isFunctionPointerType ()) {
2628- StrCat (" std::mem::transmute::<" );
2629- Convert (sub_expr->getType ());
2630- StrCat (' ,' );
2631- Convert (type);
2632- StrCat (" >(" );
2633- Convert (sub_expr);
2634- StrCat (' )' );
2645+ ConvertFunctionPointerTransmute (sub_expr, type);
26352646 return false ;
26362647 }
26372648 if (type->isEnumeralType () && !sub_expr->getType ()->isEnumeralType ()) {
0 commit comments