Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 4659953

Browse files
authored
[APINotes] RetainCountConvention: none overrules arc_cf_audited (#244)
rdar://problem/39619530 (cherry picked from commit e2077f7)
1 parent dd92bf3 commit 4659953

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

lib/Sema/SemaAPINotes.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ static void handleAPINotedRetainCountAttribute(Sema &S, Decl *D,
215215
return isa<CFReturnsRetainedAttr>(next) ||
216216
isa<CFReturnsNotRetainedAttr>(next) ||
217217
isa<NSReturnsRetainedAttr>(next) ||
218-
isa<NSReturnsNotRetainedAttr>(next);
218+
isa<NSReturnsNotRetainedAttr>(next) ||
219+
isa<CFAuditedTransferAttr>(next);
219220
});
220221
});
221222
}
@@ -227,8 +228,13 @@ static void handleAPINotedRetainCountConvention(
227228
return;
228229
switch (convention.getValue()) {
229230
case api_notes::RetainCountConventionKind::None:
230-
handleAPINotedRetainCountAttribute(S, D, /*shouldAddAttribute*/false,
231-
metadata);
231+
if (isa<FunctionDecl>(D)) {
232+
handleAPINotedRetainCountAttribute<CFUnknownTransferAttr>(
233+
S, D, /*shouldAddAttribute*/true, metadata);
234+
} else {
235+
handleAPINotedRetainCountAttribute(S, D, /*shouldAddAttribute*/false,
236+
metadata);
237+
}
232238
break;
233239
case api_notes::RetainCountConventionKind::CFReturnsRetained:
234240
handleAPINotedRetainCountAttribute<CFReturnsRetainedAttr>(

test/APINotes/Inputs/Frameworks/SimpleKit.framework/Headers/SimpleKit.apinotes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ Functions:
3131
Parameters:
3232
- Position: 0
3333
RetainCountConvention: CFReturnsNotRetained
34+
- Name: getCFAuditedToUnowned_DUMP
35+
RetainCountConvention: CFReturnsNotRetained
36+
- Name: getCFAuditedToOwned_DUMP
37+
RetainCountConvention: CFReturnsRetained
38+
- Name: getCFAuditedToNone_DUMP
39+
RetainCountConvention: none
3440
Classes:
3541
- Name: MethodTest
3642
Methods:

test/APINotes/Inputs/Frameworks/SimpleKit.framework/Headers/SimpleKit.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ int indirectGetCFUnownedToOwned(void **out __attribute__((cf_returns_not_retaine
1717
int indirectGetCFOwnedToNone(void **out __attribute__((cf_returns_retained)));
1818
int indirectGetCFNoneToOwned(void **out);
1919

20+
#pragma clang arc_cf_code_audited begin
21+
void *getCFAuditedToUnowned_DUMP(void);
22+
void *getCFAuditedToOwned_DUMP(void);
23+
void *getCFAuditedToNone_DUMP(void);
24+
#pragma clang arc_cf_code_audited end
25+
2026
@interface MethodTest
2127
- (id)getOwnedToUnowned __attribute__((ns_returns_retained));
2228
- (id)getUnownedToOwned __attribute__((ns_returns_not_retained));

test/APINotes/retain-count-convention.m

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// RUN: rm -rf %t && mkdir -p %t
22
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules -fdisable-module-hash -fsyntax-only -F %S/Inputs/Frameworks %s
33
// RUN: %clang_cc1 -ast-print %t/ModulesCache/SimpleKit.pcm | FileCheck %s
4+
// RUN: %clang_cc1 -ast-dump -ast-dump-filter 'DUMP' %t/ModulesCache/SimpleKit.pcm | FileCheck -check-prefix CHECK-DUMP %s
45

56
#import <SimpleKit/SimpleKit.h>
67

78
// CHECK: void *getCFOwnedToUnowned() __attribute__((cf_returns_not_retained));
89
// CHECK: void *getCFUnownedToOwned() __attribute__((cf_returns_retained));
9-
// CHECK: void *getCFOwnedToNone();
10+
// CHECK: void *getCFOwnedToNone() __attribute__((cf_unknown_transfer));
1011
// CHECK: id getObjCOwnedToUnowned() __attribute__((ns_returns_not_retained));
1112
// CHECK: id getObjCUnownedToOwned() __attribute__((ns_returns_retained));
1213
// CHECK: int indirectGetCFOwnedToUnowned(void * _Nullable *out __attribute__((cf_returns_not_retained)));
@@ -18,3 +19,20 @@
1819
// CHECK: - (id)getOwnedToUnowned __attribute__((ns_returns_not_retained));
1920
// CHECK: - (id)getUnownedToOwned __attribute__((ns_returns_retained));
2021
// CHECK: @end
22+
23+
// CHECK-DUMP-LABEL: Dumping getCFAuditedToUnowned_DUMP:
24+
// CHECK-DUMP-NEXT: FunctionDecl
25+
// CHECK-DUMP-NEXT: CFReturnsNotRetainedAttr
26+
// CHECK-DUMP-NEXT: CFAuditedTransferAttr
27+
// CHECK-DUMP-NOT: Attr
28+
29+
// CHECK-DUMP-LABEL: Dumping getCFAuditedToOwned_DUMP:
30+
// CHECK-DUMP-NEXT: FunctionDecl
31+
// CHECK-DUMP-NEXT: CFReturnsRetainedAttr
32+
// CHECK-DUMP-NEXT: CFAuditedTransferAttr
33+
// CHECK-DUMP-NOT: Attr
34+
35+
// CHECK-DUMP-LABEL: Dumping getCFAuditedToNone_DUMP:
36+
// CHECK-DUMP-NEXT: FunctionDecl
37+
// CHECK-DUMP-NEXT: CFUnknownTransferAttr
38+
// CHECK-DUMP-NOT: Attr

0 commit comments

Comments
 (0)