DeallocMissingRelease.m 20.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
// RUN: %clang_analyze_cc1 -analyzer-checker=osx.cocoa.Dealloc -fblocks -triple x86_64-apple-ios4.0 -DMACOS=0 -verify %s
// RUN: %clang_analyze_cc1 -analyzer-checker=osx.cocoa.Dealloc -fblocks -triple x86_64-apple-macosx10.6.0 -DMACOS=1 -verify %s
// RUN: %clang_analyze_cc1 -analyzer-checker=osx.cocoa.Dealloc -fblocks -triple x86_64-apple-darwin10 -fobjc-arc -fobjc-runtime-has-weak -verify %s

#include "Inputs/system-header-simulator-for-objc-dealloc.h"

#define NON_ARC !__has_feature(objc_arc)

#if NON_ARC
#define WEAK_ON_ARC
#else
#define WEAK_ON_ARC __weak
#endif

// No diagnostics expected under ARC.
#if !NON_ARC
  // expected-no-diagnostics
#endif

// Do not warn about missing release in -dealloc for ivars.

@interface MyIvarClass1 : NSObject {
  NSObject *_ivar;
}
@end

@implementation MyIvarClass1
- (instancetype)initWithIvar:(NSObject *)ivar
{
  self = [super init];
  if (!self)
    return nil;
#if NON_ARC
  _ivar = [ivar retain];
#endif
  return self;
}
- (void)dealloc
{
#if NON_ARC
  [super dealloc];
#endif
}
@end

@interface MyIvarClass2 : NSObject {
  NSObject *_ivar;
}
- (NSObject *)ivar;
- (void)setIvar:(NSObject *)ivar;
@end

@implementation MyIvarClass2
- (instancetype)init
{
  self = [super init];
  return self;
}
- (void)dealloc
{
#if NON_ARC
  [super dealloc];
#endif
}
- (NSObject *)ivar
{
  return _ivar;
}
- (void)setIvar:(NSObject *)ivar
{
#if NON_ARC
  [_ivar release];
  _ivar = [ivar retain];
#else
 _ivar = ivar;
#endif
}
@end

// Warn about missing release in -dealloc for properties.

@interface MyPropertyClass1 : NSObject
@property (copy) NSObject *ivar;
@end

@implementation MyPropertyClass1
- (void)dealloc
{
#if NON_ARC
  [super dealloc]; // expected-warning {{The '_ivar' ivar in 'MyPropertyClass1' was copied by a synthesized property but not released before '[super dealloc]'}}
#endif
}
@end

@interface MyPropertyClass2 : NSObject
@property (retain) NSObject *ivar;
@end

@implementation MyPropertyClass2
- (void)dealloc
{
#if NON_ARC
  [super dealloc]; // expected-warning {{The '_ivar' ivar in 'MyPropertyClass2' was retained by a synthesized property but not released before '[super dealloc]'}}
#endif
}
@end

@interface MyPropertyClass3 : NSObject {
  NSObject *_ivar;
}
@property (retain) NSObject *ivar;
@end

@implementation MyPropertyClass3
@synthesize ivar = _ivar;
- (void)dealloc
{
#if NON_ARC
  [super dealloc]; // expected-warning {{The '_ivar' ivar in 'MyPropertyClass3' was retained by a synthesized property but not released before '[super dealloc]'}}
#endif
}

@end

@interface MyPropertyClass4 : NSObject {
  void (^_blockPropertyIvar)(void);
}
@property (copy) void (^blockProperty)(void);
@property (copy) void (^blockProperty2)(void);
@property (copy) void (^blockProperty3)(void);

@end

@implementation MyPropertyClass4
@synthesize blockProperty = _blockPropertyIvar;
- (void)dealloc
{
#if NON_ARC
  [_blockProperty2 release];
  Block_release(_blockProperty3);

  [super dealloc]; // expected-warning {{The '_blockPropertyIvar' ivar in 'MyPropertyClass4' was copied by a synthesized property but not released before '[super dealloc]'}}
#endif
}
@end

@interface MyPropertyClass5 : NSObject {
  WEAK_ON_ARC NSObject *_ivar;
}
@property (weak) NSObject *ivar;
@end

@implementation MyPropertyClass5
@synthesize ivar = _ivar;
- (void)dealloc
{
#if NON_ARC
  [super dealloc]; // no-warning because it is a weak property
#endif
}
@end

@interface MyPropertyClassWithReturnInDealloc : NSObject {
  NSObject *_ivar;
}
@property (retain) NSObject *ivar;
@end

@implementation MyPropertyClassWithReturnInDealloc
@synthesize ivar = _ivar;
- (void)dealloc
{
  return;
#if NON_ARC
  // expected-warning@-2{{The '_ivar' ivar in 'MyPropertyClassWithReturnInDealloc' was retained by a synthesized property but not released before '[super dealloc]'}}
  [super dealloc];
#endif
}
@end

@interface MyPropertyClassWithReleaseInOtherInstance : NSObject {
  NSObject *_ivar;
  MyPropertyClassWithReleaseInOtherInstance *_other;
}
@property (retain) NSObject *ivar;

-(void)releaseIvars;
@end

@implementation MyPropertyClassWithReleaseInOtherInstance
@synthesize ivar = _ivar;

-(void)releaseIvars; {
#if NON_ARC
  [_ivar release];
#endif
}

- (void)dealloc
{
  [_other releaseIvars];
#if NON_ARC
  [super dealloc]; // expected-warning {{The '_ivar' ivar in 'MyPropertyClassWithReleaseInOtherInstance' was retained by a synthesized property but not released before '[super dealloc]'}}
#endif
}
@end

@interface MyPropertyClassWithNeitherReturnNorSuperDealloc : NSObject {
  NSObject *_ivar;
}
@property (retain) NSObject *ivar;
@end

@implementation MyPropertyClassWithNeitherReturnNorSuperDealloc
@synthesize ivar = _ivar;
- (void)dealloc
{
}
#if NON_ARC
  // expected-warning@-2 {{method possibly missing a [super dealloc] call}} (From Sema)
  // expected-warning@-3{{The '_ivar' ivar in 'MyPropertyClassWithNeitherReturnNorSuperDealloc' was retained by a synthesized property but not released before '[super dealloc]'}}
#endif
@end

// <rdar://problem/6380411>: 'myproperty' has kind 'assign' and thus the
//  assignment through the setter does not perform a release.

@interface MyObject : NSObject {
  id __unsafe_unretained _myproperty;
}
@property(assign) id myproperty;
@end

@implementation MyObject
@synthesize myproperty=_myproperty; // no-warning
- (void)dealloc {
  // Don't claim that myproperty is released since it the property
  // has the 'assign' attribute.
  self.myproperty = 0; // no-warning
#if NON_ARC
  [super dealloc];
#endif
}
@end

@interface ClassWithControlFlowInRelease : NSObject {
  BOOL _ivar1;
}
@property (retain) NSObject *ivar2;
@end

@implementation ClassWithControlFlowInRelease
- (void)dealloc; {
  if (_ivar1) {
    // We really should warn because there is a path through -dealloc on which
    // _ivar2 is not released.
#if NON_ARC
    [_ivar2 release];
#endif
  }

#if NON_ARC
  [super dealloc]; // expected-warning {{The '_ivar2' ivar in 'ClassWithControlFlowInRelease' was retained by a synthesized property but not released before '[super dealloc]'}}
#endif
}
@end

// Don't warn when the property is nil'd out in -dealloc

@interface ClassWithNildOutProperty : NSObject
@property (retain) NSObject *ivar;
@property (assign) int *intPtrProp;
@end

@implementation ClassWithNildOutProperty
- (void)dealloc; {
  self.ivar = nil;

  // Make sure to handle setting a non-retainable property to 0.
  self.intPtrProp = 0;
#if NON_ARC
  [super dealloc];  // no-warning
#endif
}
@end

// Do warn when the ivar but not the property is nil'd out in -dealloc

@interface ClassWithNildOutIvar : NSObject
@property (retain) NSObject *ivar;
@end

@implementation ClassWithNildOutIvar
- (void)dealloc; {
  // Oops. Meant self.ivar = nil
  _ivar = nil;

#if NON_ARC
  [super dealloc]; // expected-warning {{The '_ivar' ivar in 'ClassWithNildOutIvar' was retained by a synthesized property but not released before '[super dealloc]'}}
#endif
}
@end

// Do warn when the ivar is updated to a different value that is then
// released.

@interface ClassWithUpdatedIvar : NSObject
@property (retain) NSObject *ivar;
@end

@implementation ClassWithUpdatedIvar
- (void)dealloc; {
  _ivar = [[NSObject alloc] init];

#if NON_ARC
  [_ivar release];
#endif

#if NON_ARC
  [super dealloc]; // expected-warning {{The '_ivar' ivar in 'ClassWithUpdatedIvar' was retained by a synthesized property but not released before '[super dealloc]'}}
#endif
}
@end


// Don't warn when the property is nil'd out with a setter in -dealloc

@interface ClassWithNildOutPropertyViaSetter : NSObject
@property (retain) NSObject *ivar;
@end

@implementation ClassWithNildOutPropertyViaSetter
- (void)dealloc; {
  [self setIvar:nil];

#if NON_ARC
  [super dealloc];  // no-warning
#endif
}
@end


// Don't warn about missing releases when -dealloc helpers are called.

@interface ClassWithDeallocHelpers : NSObject
@property (retain) NSObject *ivarReleasedInMethod;
@property (retain) NSObject *propNilledOutInMethod;

@property (retain) NSObject *ivarReleasedInFunction;
@property (retain) NSObject *propNilledOutInFunction;

@property (retain) NSObject *ivarNeverReleased;
- (void)invalidateInMethod;
@end

void ReleaseValueHelper(NSObject *iv) {
#if NON_ARC
  [iv release];
#endif
}

void NilOutPropertyHelper(ClassWithDeallocHelpers *o) {
  o.propNilledOutInFunction = nil;
}

@implementation ClassWithDeallocHelpers
- (void)invalidateInMethod {
#if NON_ARC
  [_ivarReleasedInMethod release];
#endif
  self.propNilledOutInMethod = nil;
}

- (void)dealloc; {
  ReleaseValueHelper(_ivarReleasedInFunction);
  NilOutPropertyHelper(self);

  [self invalidateInMethod];
#if NON_ARC
  [super dealloc]; // expected-warning {{The '_ivarNeverReleased' ivar in 'ClassWithDeallocHelpers' was retained by a synthesized property but not released before '[super dealloc]'}}
#endif
}
@end


// Don't warn when self in -dealloc escapes.

@interface ClassWhereSelfEscapesViaMethodCall : NSObject
@property (retain) NSObject *ivar;  // no-warning
@end

@interface ClassWhereSelfEscapesViaMethodCall (Other)
- (void)invalidate; // In other translation unit.
@end

@implementation ClassWhereSelfEscapesViaMethodCall
- (void)dealloc; {
  [self invalidate];
#if NON_ARC
  [super dealloc];
#endif
} // no-warning
@end

@interface ClassWhereSelfEscapesViaPropertyAccess : NSObject
@property (retain) NSObject *ivar;
@end

@interface ClassWhereSelfEscapesViaPropertyAccess (Other)
// The implementation of this property is unknown and therefore could
// release ivar.
@property (retain) NSObject *otherIvar;
@end

@implementation ClassWhereSelfEscapesViaPropertyAccess
- (void)dealloc; {
  self.otherIvar = nil;
#if NON_ARC
  [super dealloc];
#endif
} // no-warning
@end

// Don't treat self as escaping when setter called on *synthesized*
// property.

@interface ClassWhereSelfEscapesViaSynthesizedPropertyAccess : NSObject
@property (retain) NSObject *ivar;
@property (retain) NSObject *otherIvar;
@end

@implementation ClassWhereSelfEscapesViaSynthesizedPropertyAccess
- (void)dealloc; {
  self.otherIvar = nil;
#if NON_ARC
  [super dealloc];  // expected-warning {{The '_ivar' ivar in 'ClassWhereSelfEscapesViaSynthesizedPropertyAccess' was retained by a synthesized property but not released before '[super dealloc]'}}
#endif
}
@end


// Don't treat calls to system headers as escapes

@interface ClassWhereSelfEscapesViaCallToSystem : NSObject
@property (retain) NSObject *ivar1;
@property (retain) NSObject *ivar2;
@property (retain) NSObject *ivar3;
@property (retain) NSObject *ivar4;
@property (retain) NSObject *ivar5;
@property (retain) NSObject *ivar6;
@end

@implementation ClassWhereSelfEscapesViaCallToSystem
- (void)dealloc; {
#if NON_ARC
  [_ivar2 release];
  if (_ivar3) {
    [_ivar3 release];
  }
#endif

  [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget:self];
  [[NSNotificationCenter defaultCenter] removeObserver:self];

#if NON_ARC
  [_ivar4 release];

  if (_ivar5) {
    [_ivar5 release];
  }
#endif

  [[NSNotificationCenter defaultCenter] removeObserver:self];

#if NON_ARC
  if (_ivar6) {
    [_ivar6 release];
  }

  [super dealloc];  // expected-warning {{The '_ivar1' ivar in 'ClassWhereSelfEscapesViaCallToSystem' was retained by a synthesized property but not released before '[super dealloc]'}}
#endif
}
@end

// Don't warn when value escapes.

@interface ClassWhereIvarValueEscapes : NSObject
@property (retain) NSObject *ivar;
@end

void ReleaseMe(id arg);

@implementation ClassWhereIvarValueEscapes
- (void)dealloc; {

  ReleaseMe(_ivar);

#if NON_ARC
  [super dealloc];
#endif
} // no-warning
@end

// Don't warn when value is known to be nil.

@interface ClassWhereIvarIsNil : NSObject
@property (retain) NSObject *ivarIsNil;
@end

@implementation ClassWhereIvarIsNil
- (void)dealloc; {

#if NON_ARC
  if (_ivarIsNil)
    [_ivarIsNil release];

  [super dealloc];
#endif
} // no-warning
@end


// Don't warn for non-retainable properties.

@interface ClassWithNonRetainableProperty : NSObject
@property (assign) int *ivar;  // no-warning
@end

@implementation ClassWithNonRetainableProperty
- (void)dealloc; {
#if NON_ARC
  [super dealloc];
#endif
} // no-warning
@end


@interface SuperClassOfClassWithInlinedSuperDealloc : NSObject
@property (retain) NSObject *propInSuper;
@end

@implementation SuperClassOfClassWithInlinedSuperDealloc
- (void)dealloc {
#if NON_ARC
  [super dealloc]; // expected-warning {{The '_propInSuper' ivar in 'SuperClassOfClassWithInlinedSuperDealloc' was retained by a synthesized property but not released before '[super dealloc]'}}
#endif
}
@end

@interface ClassWithInlinedSuperDealloc : SuperClassOfClassWithInlinedSuperDealloc
@property (retain) NSObject *propInSub;
@end

@implementation ClassWithInlinedSuperDealloc
- (void)dealloc {
#if NON_ARC
  [super dealloc]; // expected-warning {{The '_propInSub' ivar in 'ClassWithInlinedSuperDealloc' was retained by a synthesized property but not released before '[super dealloc]'}}
#endif
}
@end


@interface SuperClassOfClassWithInlinedSuperDeallocAndInvalidation : NSObject
@property (retain) NSObject *propInSuper;

- (void)invalidate;
@end

@implementation SuperClassOfClassWithInlinedSuperDeallocAndInvalidation

- (void)invalidate {
#if NON_ARC
  [_propInSuper release];
#endif
  _propInSuper = nil;
}

- (void)dealloc {
  [self invalidate];
#if NON_ARC
  [super dealloc]; // no-warning
#endif
}
@end

@interface ClassWithInlinedSuperDeallocAndInvalidation : SuperClassOfClassWithInlinedSuperDeallocAndInvalidation
@property (retain) NSObject *propInSub;
@end

@implementation ClassWithInlinedSuperDeallocAndInvalidation

- (void)invalidate {
#if NON_ARC
  [_propInSub release];
#endif
  [super invalidate];
}

- (void)dealloc {
#if NON_ARC
  [super dealloc]; // no-warning
#endif
}
@end


@interface SuperClassOfClassThatEscapesBeforeInliningSuper : NSObject
@property (retain) NSObject *propInSuper;
@end

@implementation SuperClassOfClassThatEscapesBeforeInliningSuper

- (void)dealloc {

#if NON_ARC
  [super dealloc]; // expected-warning {{The '_propInSuper' ivar in 'SuperClassOfClassThatEscapesBeforeInliningSuper' was retained by a synthesized property but not released before '[super dealloc]'}}
#endif
}
@end

@interface ClassThatEscapesBeforeInliningSuper : SuperClassOfClassThatEscapesBeforeInliningSuper
@property (retain) NSObject *propInSub;
@end

@interface ClassThatEscapesBeforeInliningSuper (Other)
- (void)invalidate; // No implementation in translation unit.
@end

@implementation ClassThatEscapesBeforeInliningSuper
- (void)dealloc {
  [self invalidate];

#if NON_ARC
  [super dealloc]; // no-warning
#endif
}
@end


#if NON_ARC
@interface ReleaseIvarInField : NSObject {
  int _tag;
  union {
    NSObject *field1;
    NSObject *field2;
  } _someUnion;

  struct {
    NSObject *field1;
  } _someStruct;
}
@end

@implementation ReleaseIvarInField
- (void)dealloc {
  if (_tag) {
    [_someUnion.field1 release];
  } else {
    [_someUnion.field2 release];
  }

  [_someStruct.field1 release];
  [super dealloc];
}
@end
#endif

struct SomeStruct {
  int f;
};
@interface ZeroOutStructWithSetter : NSObject
  @property(assign) struct SomeStruct s;
@end

@implementation ZeroOutStructWithSetter
- (void)dealloc {
  struct SomeStruct zeroedS;
  zeroedS.f = 0;

  self.s = zeroedS;
#if NON_ARC
  [super dealloc];
#endif
}
@end

#if NON_ARC
@interface ReleaseIvarInArray : NSObject {
  NSObject *_array[3];
}
@end

@implementation ReleaseIvarInArray
- (void)dealloc {
  for (int i = 0; i < 3; i++) {
    [_array[i] release];
  }
  [super dealloc];
}
@end
#endif

// Don't warn about missing releases for subclasses of SenTestCase or
// for classes that are not subclasses of NSObject.

@interface SenTestCase : NSObject {}
@end

@interface MyClassTest : SenTestCase
@property (retain) NSObject *ivar;
@end

@implementation MyClassTest
-(void)tearDown {
#if NON_ARC
  [_ivar release];
#endif
}

-(void)dealloc; {
#if NON_ARC
  [super dealloc]; // no-warning
#endif
}
@end

@interface XCTestCase : NSObject {}
@end

@interface MyClassXCTest : XCTestCase
@property (retain) NSObject *ivar;
@end

@implementation MyClassXCTest
-(void)tearDown {
#if NON_ARC
  [_ivar release];
#endif
}

-(void)dealloc; {
#if NON_ARC
  [super dealloc]; // no-warning
#endif
}
@end


__attribute__((objc_root_class))
@interface NonNSObjectMissingDealloc
@property (retain) NSObject *ivar;
@end
@implementation NonNSObjectMissingDealloc
-(void)dealloc; {

}
@end

// Warn about calling -dealloc rather than release by mistake.

@interface CallDeallocOnRetainPropIvar : NSObject {
  NSObject *okToDeallocDirectly;
}

@property (retain) NSObject *ivar;
@end

@implementation CallDeallocOnRetainPropIvar
- (void)dealloc
{
#if NON_ARC
  // Only warn for synthesized ivars.
  [okToDeallocDirectly dealloc]; // no-warning
  [_ivar dealloc];  // expected-warning {{'_ivar' should be released rather than deallocated}}

  [super dealloc];
#endif
}
@end

// CIFilter special cases.
// By design, -[CIFilter dealloc] releases (by calling -setValue: forKey: with
// 'nil') all ivars (even in its *subclasses*) with names starting with
// 'input' or that are backed by properties with names starting with 'input'.
// The Dealloc checker needs to take particular care to not warn about missing
// releases in this case -- if the user adds a release quiet the
// warning it may result in an over release.

@interface ImmediateSubCIFilter : CIFilter {
  NSObject *inputIvar;
  NSObject *nonInputIvar;
  NSObject *notPrefixedButBackingPrefixedProperty;
  NSObject *inputPrefixedButBackingNonPrefixedProperty;
}

@property(retain) NSObject *inputIvar;
@property(retain) NSObject *nonInputIvar;
@property(retain) NSObject *inputAutoSynthesizedIvar;
@property(retain) NSObject *inputExplicitlySynthesizedToNonPrefixedIvar;
@property(retain) NSObject *nonPrefixedPropertyBackedByExplicitlySynthesizedPrefixedIvar;

@end

@implementation ImmediateSubCIFilter
@synthesize inputIvar = inputIvar;
@synthesize nonInputIvar = nonInputIvar;
@synthesize inputExplicitlySynthesizedToNonPrefixedIvar = notPrefixedButBackingPrefixedProperty;
@synthesize nonPrefixedPropertyBackedByExplicitlySynthesizedPrefixedIvar = inputPrefixedButBackingNonPrefixedProperty;

- (void)dealloc {
#if NON_ARC
  // We don't want warnings here for:
  // inputIvar
  // inputAutoSynthesizedIvar
  // inputExplicitlySynthesizedToNonPrefixedIvar
  // inputPrefixedButBackingNonPrefixedProperty
  [super dealloc];
  // expected-warning@-1 {{The 'nonInputIvar' ivar in 'ImmediateSubCIFilter' was retained by a synthesized property but not released before '[super dealloc]'}}
#endif
}
@end

@interface SubSubCIFilter : CIFilter {
  NSObject *inputIvarInSub;
}

@property(retain) NSObject *inputIvarInSub;
@end

@implementation SubSubCIFilter
@synthesize inputIvarInSub = inputIvarInSub;

- (void)dealloc {
// Don't warn about inputIvarInSub.
#if NON_ARC
  [super dealloc];
#endif
}
@end
@interface OverreleasingCIFilter : CIFilter {
  NSObject *inputIvar;
}

@property(retain) NSObject *inputIvar;
@end

@implementation OverreleasingCIFilter
@synthesize inputIvar = inputIvar;

- (void)dealloc {
#if NON_ARC
  // This is an over release because CIFilter's dealloc will also release it.
  [inputIvar release]; // expected-warning {{The 'inputIvar' ivar in 'OverreleasingCIFilter' will be released by '-[CIFilter dealloc]' but also released here}}
  [super dealloc]; // no-warning
  #endif
}
@end


@interface NotMissingDeallocCIFilter : CIFilter {
  NSObject *inputIvar;
}

@property(retain) NSObject *inputIvar;
@end

@implementation NotMissingDeallocCIFilter // no-warning
@synthesize inputIvar = inputIvar;
@end


@interface ClassWithRetainPropWithIBOutletIvarButNoSetter : NSObject {
  // On macOS, the nib-loading code will set the ivar directly without
  // retaining value (unike iOS, where it is retained). This means that
  // on macOS we should not warn about a missing release for a property backed
  // by an IBOutlet ivar when that property does not have a setter.
  IBOutlet NSObject *ivarForOutlet;
}

@property (readonly, retain) NSObject *ivarForOutlet;
@end

@implementation ClassWithRetainPropWithIBOutletIvarButNoSetter

@synthesize ivarForOutlet;
- (void)dealloc {

#if NON_ARC
  [super dealloc];
#if !MACOS
// expected-warning@-2{{The 'ivarForOutlet' ivar in 'ClassWithRetainPropWithIBOutletIvarButNoSetter' was retained by a synthesized property but not released before '[super dealloc]'}}
#endif
#endif
}

@end

@interface ClassWithRetainPropWithIBOutletIvarAndShadowingReadWrite : NSObject {
  IBOutlet NSObject *ivarForOutlet;
}

@property (readonly, retain) NSObject *ivarForOutlet;

@end

@interface ClassWithRetainPropWithIBOutletIvarAndShadowingReadWrite ()

// Since there is a shadowing readwrite property, there will be a retaining
// setter and so the ivar will be retained by nib-loading code even on
// macOS and therefore must be released.
@property (readwrite, retain) NSObject *ivarForOutlet;
@end

@implementation ClassWithRetainPropWithIBOutletIvarAndShadowingReadWrite

@synthesize ivarForOutlet;
- (void)dealloc {

#if NON_ARC
  [super dealloc];
// expected-warning@-1{{The 'ivarForOutlet' ivar in 'ClassWithRetainPropWithIBOutletIvarAndShadowingReadWrite' was retained by a synthesized property but not released before '[super dealloc]'}}
#endif
}

@end