File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed
lib/StaticAnalyzer/Checkers/WebKit
test/Analysis/Checkers/WebKit Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,13 @@ bool tryToFindPtrOrigin(
91
91
continue ;
92
92
}
93
93
if (auto *call = dyn_cast<CallExpr>(E)) {
94
+ if (auto *Callee = call->getCalleeDecl ()) {
95
+ if (Callee->hasAttr <CFReturnsRetainedAttr>() ||
96
+ Callee->hasAttr <NSReturnsRetainedAttr>()) {
97
+ return callback (E, true );
98
+ }
99
+ }
100
+
94
101
if (auto *memberCall = dyn_cast<CXXMemberCallExpr>(call)) {
95
102
if (auto *decl = memberCall->getMethodDecl ()) {
96
103
std::optional<bool > IsGetterOfRefCt = isGetterOfSafePtr (decl);
Original file line number Diff line number Diff line change @@ -438,6 +438,32 @@ void use_const_local() {
438
438
439
439
} // namespace const_global
440
440
441
+ namespace ns_retained_return_value {
442
+
443
+ NSString *provideNS () NS_RETURNS_RETAINED;
444
+ CFDictionaryRef provideCF () CF_RETURNS_RETAINED;
445
+ void consumeNS (NSString *);
446
+ void consumeCF (CFDictionaryRef);
447
+
448
+ void foo () {
449
+ consumeNS (provideNS ());
450
+ consumeCF (provideCF ());
451
+ }
452
+
453
+ struct Base {
454
+ NSString *provideStr () NS_RETURNS_RETAINED;
455
+ };
456
+
457
+ struct Derived : Base {
458
+ void consumeStr (NSString *);
459
+
460
+ void foo () {
461
+ consumeStr (provideStr ());
462
+ }
463
+ };
464
+
465
+ } // namespace ns_retained_return_value
466
+
441
467
@interface TestObject : NSObject
442
468
- (void )doWork : (NSString *)msg , ...;
443
469
- (void )doWorkOnSelf ;
Original file line number Diff line number Diff line change @@ -408,6 +408,21 @@ void use_const_local() {
408
408
409
409
} // namespace const_global
410
410
411
+ namespace ns_retained_return_value {
412
+
413
+ NSString *provideNS () NS_RETURNS_RETAINED;
414
+ CFDictionaryRef provideCF () CF_RETURNS_RETAINED;
415
+ void consumeNS (NSString *);
416
+ void consumeCF (CFDictionaryRef);
417
+
418
+ unsigned foo () {
419
+ auto *string = provideNS ();
420
+ auto *dictionary = provideCF ();
421
+ return string.length + CFDictionaryGetCount (dictionary);
422
+ }
423
+
424
+ } // namespace ns_retained_return_value
425
+
411
426
bool doMoreWorkOpaque (OtherObj*);
412
427
SomeObj* provide ();
413
428
You can’t perform that action at this time.
0 commit comments