xref: /aosp_15_r20/external/clang/test/Analysis/retain-release-cache-out.m (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 -analyze %s -analyzer-checker=core,osx.cocoa.RetainCount -fblocks -verify
2*67e74705SXin Li
3*67e74705SXin Li// This test is checking behavior when a single checker runs only with the core
4*67e74705SXin Li// checkers, testing that the traversal order in the CFG does not affect the
5*67e74705SXin Li// reporting of an error.
6*67e74705SXin Li
7*67e74705SXin Li#import "Inputs/system-header-simulator-objc.h"
8*67e74705SXin Li
9*67e74705SXin Livoid testDoubleRelease(BOOL z) {
10*67e74705SXin Li  id x = [[NSObject alloc] init];
11*67e74705SXin Li  if (z) {
12*67e74705SXin Li    [x release];
13*67e74705SXin Li  } else {
14*67e74705SXin Li    ;
15*67e74705SXin Li  }
16*67e74705SXin Li  [x release]; // expected-warning {{Reference-counted object is used after it is released}}
17*67e74705SXin Li}
18*67e74705SXin Li
19*67e74705SXin Livoid testDoubleRelease2(BOOL z) {
20*67e74705SXin Li  id x = [[NSObject alloc] init];
21*67e74705SXin Li  if (z) {
22*67e74705SXin Li    ;
23*67e74705SXin Li  } else {
24*67e74705SXin Li    [x release];
25*67e74705SXin Li  }
26*67e74705SXin Li  [x release]; // expected-warning {{Reference-counted object is used after it is released}}
27*67e74705SXin Li}
28