-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[cxx-interop] Warning unannotated C++ APIs returning SWIFT_SHARED_REF… #76798
base: main
Are you sure you want to change the base?
[cxx-interop] Warning unannotated C++ APIs returning SWIFT_SHARED_REF… #76798
Conversation
@swift-ci please test |
"%0 cannot be annotated with both swift_attr('returns_retained') and swift_attr('returns_unretained') attributes", (const clang::NamedDecl*)) | ||
ERROR(both_returns_retained_returns_unretained, none, | ||
"%0 cannot be annotated with both swift_attr('returns_retained') and " | ||
"swift_attr('returns_unretained') attributes", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fahadnayyar I think we should suggest people to use the macro instead of directly using swift_attr
. What are other similar diagnostics doing?
static bool isForeignReferenceType(const clang::QualType type) { | ||
if (!type->isPointerType()) | ||
return false; | ||
|
||
auto pointeeType = | ||
dyn_cast<clang::RecordType>(type->getPointeeType().getCanonicalType()); | ||
if (pointeeType == nullptr) | ||
return false; | ||
|
||
return hasImportAsRefAttr(pointeeType->getDecl()); | ||
} | ||
|
||
static bool hasImportAsRefAttr(const clang::RecordDecl *decl) { | ||
return decl->hasAttrs() && llvm::any_of(decl->getAttrs(), [](auto *attr) { | ||
if (auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr)) | ||
return swiftAttr->getAttribute() == "import_reference" || | ||
// TODO: Remove this once libSwift hosttools no longer | ||
// requires it. | ||
swiftAttr->getAttribute() == "import_as_ref"; | ||
return false; | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like these functions are copied-and-pasted from elsewhere in ClangImporter. Let's use the existing API instead.
Adding a warning when C++ APIs (functions or methods) returning C++ foreign reference types or SWIFT_SHARED_REFERENCE types are not annotated with either of SWIFT_RETURNS_RETAINED and SWIFT_RETURNS_UNRETAINED.