1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,osx -analyzer-output=text -verify %s
2 
3 // expected-no-diagnostics
4 
5 typedef void *CFTypeRef;
6 typedef struct _CFURLCacheRef *CFURLCacheRef;
7 
8 CFTypeRef CustomCFRetain(CFTypeRef);
9 void invalidate(void *);
10 struct S1 {
11   CFTypeRef s;
returnFieldAtPlus0S112   CFTypeRef returnFieldAtPlus0() {
13     return s;
14   }
15 };
16 struct S2 {
17   S1 *s1;
18 };
foo(S1 * s1)19 void foo(S1 *s1) {
20   invalidate(s1);
21   S2 s2;
22   s2.s1 = s1;
23   CustomCFRetain(s1->returnFieldAtPlus0());
24 
25   // Definitely no leak end-of-path note here. The retained pointer
26   // is still accessible through s1 and s2.
27   ((void) 0); // no-warning
28 
29   // FIXME: Ideally we need to warn after this invalidate(). The per-function
30   // retain-release contract is violated: the programmer should release
31   // the symbol after it was retained, within the same function.
32   invalidate(&s2);
33 }
34