blob: 9ed1c0b3b5672f2cc72fad02f5424f33e7b66f1a [file] [log] [blame]
Artem Dergachevbbc6d682018-11-30 03:27:50 +00001// RUN: %clang_analyze_cc1 -analyzer-checker=core,osx -analyzer-output=text -verify %s
2
3// expected-no-diagnostics
4
5typedef void *CFTypeRef;
6typedef struct _CFURLCacheRef *CFURLCacheRef;
7
8CFTypeRef CustomCFRetain(CFTypeRef);
9void invalidate(void *);
10struct S1 {
11 CFTypeRef s;
12 CFTypeRef returnFieldAtPlus0() {
13 return s;
14 }
15};
16struct S2 {
17 S1 *s1;
18};
19void 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}