Skip to content

[cxx-interop] Disabling should be annotated with SWIFT_RETURNS_(UN)RETAINED warning #81411

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3660,6 +3660,7 @@ namespace {
unannotatedAPIWarningNeeded = false;
}

unannotatedAPIWarningNeeded = false;
if (unannotatedAPIWarningNeeded) {
HeaderLoc loc(decl->getLocation());
Impl.diagnose(loc, diag::no_returns_retained_returns_unretained,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// FRT or SWIFT_SHARED_REFERENCE type
struct FRTStruct {
// Friend function declarations
friend FRTStruct *returnInstanceOfFRTStruct(int v); // expected-warning {{'returnInstanceOfFRTStruct' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
friend FRTStruct *returnInstanceOfFRTStructWithAttrReturnsRetained(int v); // expected-warning {{'returnInstanceOfFRTStructWithAttrReturnsRetained' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
friend FRTStruct *returnInstanceOfFRTStructWithAttrReturnsUnretained(int v); // expected-warning {{'returnInstanceOfFRTStructWithAttrReturnsUnretained' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
friend FRTStruct *returnInstanceOfFRTStruct(int v);
friend FRTStruct *returnInstanceOfFRTStructWithAttrReturnsRetained(int v);
friend FRTStruct *returnInstanceOfFRTStructWithAttrReturnsUnretained(int v);
} __attribute__((swift_attr("import_reference")))
__attribute__((swift_attr("retain:retainFRTStruct")))
__attribute__((swift_attr("release:releaseFRTStruct")));
Expand Down Expand Up @@ -179,12 +179,12 @@ __attribute__((swift_attr("unsafe")));

// C++ APIs returning cxx frts (for testing diagnostics)
struct StructWithAPIsReturningCxxFrt {
static FRTStruct *_Nonnull StaticMethodReturningCxxFrt(); // expected-warning {{'StaticMethodReturningCxxFrt' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
static FRTStruct *_Nonnull StaticMethodReturningCxxFrt();
static FRTStruct *_Nonnull StaticMethodReturningCxxFrtWithAnnotation()
__attribute__((swift_attr("returns_retained")));
};

FRTStruct *_Nonnull global_function_returning_cxx_frt(); // expected-warning {{'global_function_returning_cxx_frt' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
FRTStruct *_Nonnull global_function_returning_cxx_frt();
FRTStruct *_Nonnull global_function_returning_cxx_frt_with_annotations()
__attribute__((swift_attr("returns_retained")));

Expand Down Expand Up @@ -303,7 +303,7 @@ __attribute__((swift_attr(
operator-(const FRTOverloadedOperators &other);
};

FRTOverloadedOperators *_Nonnull returnFRTOverloadedOperators(); // expected-warning {{'returnFRTOverloadedOperators' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
FRTOverloadedOperators *_Nonnull returnFRTOverloadedOperators();

void retain_FRTOverloadedOperators(FRTOverloadedOperators *_Nonnull v);
void release_FRTOverloadedOperators(FRTOverloadedOperators *_Nonnull v);
Expand Down Expand Up @@ -371,7 +371,7 @@ struct __attribute__((swift_attr("import_reference")))
__attribute__((swift_attr("retain:rretain")))
__attribute__((swift_attr("release:rrelease"))) RefType {};

RefType *returnRefType() { return new RefType(); } // expected-warning {{'returnRefType' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
RefType *returnRefType() { return new RefType(); }

struct __attribute__((swift_attr("import_reference")))
__attribute__((swift_attr("retain:dretain")))
Expand Down Expand Up @@ -420,10 +420,10 @@ __attribute__((swift_attr("retain:dRetain")))
__attribute__((swift_attr("release:dRelease"))) DerivedTypeNonDefault
: public BaseTypeNonDefault {};

BaseTypeNonDefault *createBaseTypeNonDefault() { // expected-warning {{'createBaseTypeNonDefault' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
BaseTypeNonDefault *createBaseTypeNonDefault() {
return new BaseTypeNonDefault();
}
DerivedTypeNonDefault *createDerivedTypeNonDefault() { // expected-warning {{'createDerivedTypeNonDefault' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
DerivedTypeNonDefault *createDerivedTypeNonDefault() {
return new DerivedTypeNonDefault();
}

Expand Down
36 changes: 18 additions & 18 deletions test/Interop/Cxx/foreign-reference/Inputs/inheritance.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ __attribute__((swift_attr("release:immortal"))) ImmortalRefType {};
ImmortalRefType *returnImmortalRefType() { return new ImmortalRefType(); };

struct DerivedFromImmortalRefType : ImmortalRefType {};
DerivedFromImmortalRefType *returnDerivedFromImmortalRefType() { // expected-warning {{'returnDerivedFromImmortalRefType' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
return new DerivedFromImmortalRefType();
DerivedFromImmortalRefType *returnDerivedFromImmortalRefType() {
return new DerivedFromImmortalRefType();
};

} // namespace ImmortalRefereceExample
Expand All @@ -122,7 +122,7 @@ ValueType *returnValueType() { return new ValueType(); }
struct __attribute__((swift_attr("import_reference")))
__attribute__((swift_attr("retain:ret1")))
__attribute__((swift_attr("release:rel1"))) RefType {};
RefType *returnRefType() { return new RefType(); } // expected-warning {{'returnRefType' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
RefType *returnRefType() { return new RefType(); }

struct DerivedFromValueType : ValueType {};
DerivedFromValueType *returnDerivedFromValueType() {
Expand All @@ -133,21 +133,21 @@ struct __attribute__((swift_attr("import_reference")))
__attribute__((swift_attr("retain:ret2")))
__attribute__((swift_attr("release:rel2"))) DerivedFromValueTypeAndAnnotated
: ValueType {};
DerivedFromValueTypeAndAnnotated *returnDerivedFromValueTypeAndAnnotated() { // expected-warning {{'returnDerivedFromValueTypeAndAnnotated' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
return new DerivedFromValueTypeAndAnnotated();
DerivedFromValueTypeAndAnnotated *returnDerivedFromValueTypeAndAnnotated() {
return new DerivedFromValueTypeAndAnnotated();
}

struct DerivedFromRefType final : RefType {};
DerivedFromRefType *returnDerivedFromRefType() { // expected-warning {{'returnDerivedFromRefType' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
return new DerivedFromRefType();
DerivedFromRefType *returnDerivedFromRefType() {
return new DerivedFromRefType();
}

struct __attribute__((swift_attr("import_reference")))
__attribute__((swift_attr("retain:ret3")))
__attribute__((swift_attr("release:rel3"))) DerivedFromRefTypeAndAnnotated
: RefType {};
DerivedFromRefTypeAndAnnotated *returnDerivedFromRefTypeAndAnnotated() { // expected-warning {{'returnDerivedFromRefTypeAndAnnotated' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
return new DerivedFromRefTypeAndAnnotated();
DerivedFromRefTypeAndAnnotated *returnDerivedFromRefTypeAndAnnotated() {
return new DerivedFromRefTypeAndAnnotated();
}
} // namespace ExplicitAnnotationHasPrecedence1

Expand Down Expand Up @@ -184,8 +184,8 @@ __attribute__((swift_attr("retain:retain_C")))
__attribute__((swift_attr("release:release_C"))) DerivedFromRefTypeAAndBAnnotated
: RefTypeA,
RefTypeB {};
DerivedFromRefTypeAAndBAnnotated *returnDerivedFromRefTypeAAndBAnnotated() { // expected-warning {{'returnDerivedFromRefTypeAAndBAnnotated' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
return new DerivedFromRefTypeAAndBAnnotated();
DerivedFromRefTypeAAndBAnnotated *returnDerivedFromRefTypeAAndBAnnotated() {
return new DerivedFromRefTypeAAndBAnnotated();
}
} // namespace ExplicitAnnotationHasPrecedence2

Expand All @@ -206,10 +206,10 @@ struct __attribute__((swift_attr("import_reference")))
__attribute__((swift_attr("retain:RCRetain")))
__attribute__((swift_attr("release:RCRelease"))) RefType {};

RefType *returnRefType() { return new RefType(); }; // expected-warning {{'returnRefType' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENC}}
RefType *returnRefType() { return new RefType(); };

struct DerivedFromRefType final : RefType {};
DerivedFromRefType *returnDerivedFromRefType() { // expected-warning {{'returnDerivedFromRefType' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
DerivedFromRefType *returnDerivedFromRefType() {
return new DerivedFromRefType();
};
} // namespace BasicInheritanceExample
Expand All @@ -236,7 +236,7 @@ DerivedFromBaseRef1AndBaseRef2 *returnDerivedFromBaseRef1AndBaseRef2() {
};

struct DerivedFromBaseRef3 : BaseRef3 {};
DerivedFromBaseRef3 *returnDerivedFromBaseRef3() { // expected-warning {{'returnDerivedFromBaseRef3' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
DerivedFromBaseRef3 *returnDerivedFromBaseRef3() {
return new DerivedFromBaseRef3();
};
} // namespace MultipleInheritanceExample1
Expand Down Expand Up @@ -312,7 +312,7 @@ __attribute__((swift_attr("release:samerelease"))) B2 {}; // expected-error {{m

struct D : B1, B2 {}; // expected-error {{multiple functions 'sameretain' found; there must be exactly one retain function for reference type 'D'}}
// expected-error@-1 {{multiple functions 'samerelease' found; there must be exactly one release function for reference type 'D'}}
D *returnD() { return new D(); }; // expected-warning {{'returnD' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
D *returnD() { return new D(); };
} // namespace OverloadedRetainRelease

void sameretain(OverloadedRetainRelease::B1 *v) {}
Expand All @@ -339,7 +339,7 @@ struct BVirtual : virtual A {};
struct CVirtual : virtual A {};

struct VirtualDiamond : BVirtual, CVirtual {};
VirtualDiamond *returnVirtualDiamond() { return new VirtualDiamond(); }; // expected-warning {{'returnVirtualDiamond' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
VirtualDiamond *returnVirtualDiamond() { return new VirtualDiamond(); };
} // namespace RefTypeDiamondInheritance

void retainA(RefTypeDiamondInheritance::A *a) {};
Expand All @@ -355,7 +355,7 @@ __attribute__((swift_attr("release:releaseB"))) B : A {};
struct C : A {};

struct Diamond : B, C {};
Diamond *returnDiamond() { return new Diamond(); }; // expected-warning {{'returnDiamond' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
Diamond *returnDiamond() { return new Diamond(); };

} // namespace NonRefTypeDiamondInheritance

Expand Down Expand Up @@ -384,7 +384,7 @@ __attribute__((swift_attr("retain:forestRetain"))) __attribute__((
};

class Forest : public IntrusiveRefCountedTemplate<Forest> {};
Forest *returnForest() { return new Forest(); }; // expected-warning {{'returnForest' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
Forest *returnForest() { return new Forest(); };
} // namespace InheritingTemplatedRefType

void forestRetain(InheritingTemplatedRefType::IntrusiveRefCountedTemplate<
Expand Down
2 changes: 1 addition & 1 deletion test/Interop/Cxx/objc-correctness/Inputs/cxx-frt.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void releaseCxxRefType(CxxRefType *_Nonnull b) {}

@interface Bridge : NSObject

+ (struct CxxRefType *)objCMethodReturningFRTUnannotated; // expected-warning {{'objCMethodReturningFRTUnannotated' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
+ (struct CxxRefType *)objCMethodReturningFRTUnannotated;
+ (struct CxxRefType *)objCMethodReturningFRTUnowned
__attribute__((swift_attr("returns_unretained")));
+ (struct CxxRefType *)objCMethodReturningFRTOwned
Expand Down