@@ -3968,6 +3968,14 @@ void MissingMemberFailure::diagnoseUnsafeCxxMethod(SourceLoc loc,
3968
3968
->getName ()
3969
3969
.str ();
3970
3970
3971
+ auto baseClangLoc = cxxMethod->getParent ()->getLocation ();
3972
+ auto baseSwiftLoc =
3973
+ ctx.getClangModuleLoader ()->importSourceLocation (baseClangLoc);
3974
+
3975
+ auto methodClangLoc = cxxMethod->getLocation ();
3976
+ auto methodSwiftLoc =
3977
+ ctx.getClangModuleLoader ()->importSourceLocation (methodClangLoc);
3978
+
3971
3979
// Rewrite front() and back() as first and last.
3972
3980
if ((name.getBaseIdentifier ().is (" front" ) ||
3973
3981
name.getBaseIdentifier ().is (" back" )) &&
@@ -4024,8 +4032,11 @@ void MissingMemberFailure::diagnoseUnsafeCxxMethod(SourceLoc loc,
4024
4032
name.getBaseIdentifier ().str (), returnTypeStr);
4025
4033
ctx.Diags .diagnose (loc, diag::projection_may_return_interior_ptr,
4026
4034
name.getBaseIdentifier ().str ());
4027
- ctx.Diags .diagnose (loc, diag::mark_safe_to_import,
4028
- name.getBaseIdentifier ().str ());
4035
+ ctx.Diags
4036
+ .diagnose (methodSwiftLoc, diag::mark_safe_to_import,
4037
+ name.getBaseIdentifier ().str ())
4038
+ .fixItInsert (methodSwiftLoc,
4039
+ " __attribute__((swift_attr(\" safe_to_import\" ))) " );
4029
4040
} else if (cxxMethod->getReturnType ()->isReferenceType ()) {
4030
4041
// Rewrite a call to .at(42) as a subscript.
4031
4042
if (name.getBaseIdentifier ().is (" at" ) &&
@@ -4052,8 +4063,11 @@ void MissingMemberFailure::diagnoseUnsafeCxxMethod(SourceLoc loc,
4052
4063
name.getBaseIdentifier ().str (), returnTypeStr);
4053
4064
ctx.Diags .diagnose (loc, diag::projection_may_return_interior_ptr,
4054
4065
name.getBaseIdentifier ().str ());
4055
- ctx.Diags .diagnose (loc, diag::mark_safe_to_import,
4056
- name.getBaseIdentifier ().str ());
4066
+ ctx.Diags
4067
+ .diagnose (methodSwiftLoc, diag::mark_safe_to_import,
4068
+ name.getBaseIdentifier ().str ())
4069
+ .fixItInsert (methodSwiftLoc,
4070
+ " __attribute__((swift_attr(\" safe_to_import\" ))) " );
4057
4071
}
4058
4072
} else if (cxxMethod->getReturnType ()->isRecordType ()) {
4059
4073
if (auto cxxRecord = dyn_cast<clang::CXXRecordDecl>(
@@ -4071,9 +4085,15 @@ void MissingMemberFailure::diagnoseUnsafeCxxMethod(SourceLoc loc,
4071
4085
name.getBaseIdentifier ().str (), returnTypeStr);
4072
4086
ctx.Diags .diagnose (loc, diag::projection_may_return_interior_ptr,
4073
4087
name.getBaseIdentifier ().str ());
4074
- ctx.Diags .diagnose (loc, diag::mark_safe_to_import,
4075
- name.getBaseIdentifier ().str ());
4076
- ctx.Diags .diagnose (loc, diag::mark_self_contained, returnTypeStr);
4088
+ ctx.Diags
4089
+ .diagnose (methodSwiftLoc, diag::mark_safe_to_import,
4090
+ name.getBaseIdentifier ().str ())
4091
+ .fixItInsert (methodSwiftLoc,
4092
+ " __attribute__((swift_attr(\" safe_to_import\" ))) " );
4093
+ ctx.Diags
4094
+ .diagnose (baseSwiftLoc, diag::mark_self_contained, returnTypeStr)
4095
+ .fixItInsert (baseSwiftLoc,
4096
+ " __attribute__((swift_attr(\" self_contained\" ))) " );
4077
4097
}
4078
4098
}
4079
4099
}
0 commit comments