aboutsummaryrefslogtreecommitdiff
path: root/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.mm
blob: b78a67610df3c9d3b91efdd0f5309053fb5fc6ea (plain)
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
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s

#import "mock-types.h"
#import "mock-system-header.h"
#import "../../Inputs/system-header-simulator-for-objc-dealloc.h"

@interface Foo : NSObject {
  const Ref<RefCountable> _obj1;
  const RefPtr<RefCountable> _obj2;
  Ref<RefCountable> _obj3;
}

@property (nonatomic, readonly) RefPtr<RefCountable> countable;

- (void)execute;
- (RefPtr<RefCountable>)_protectedRefCountable;
@end

@implementation Foo

- (void)execute {
  self._protectedRefCountable->method();
  _obj1->method();
  _obj1.get().method();
  (*_obj2).method();
  _obj3->method();
  // expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
}

- (RefPtr<RefCountable>)_protectedRefCountable {
  return _countable;
}

@end

class RefCountedObject {
public:
  void ref() const;
  void deref() const;
  Ref<RefCountedObject> copy() const;
  void method();
};

@interface WrapperObj : NSObject

- (Ref<RefCountedObject>)_protectedWebExtensionControllerConfiguration;

@end

static void foo(WrapperObj *configuration) {
  configuration._protectedWebExtensionControllerConfiguration->copy();
}

void log(RefCountable* obj) {
  os_log_msg(os_log_create("WebKit", "DOM"), OS_LOG_TYPE_INFO, "obj: %p next: %p", obj, obj->next());
}