| 1 |
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.ForwardDeclChecker -verify %s |
| 2 |
|
| 3 |
#include "mock-types.h" |
| 4 |
#include "objc-mock-types.h" |
| 5 |
#include "mock-system-header.h" |
| 6 |
|
| 7 |
typedef struct OpaqueJSString * JSStringRef; |
| 8 |
|
| 9 |
class Obj; |
| 10 |
@class ObjCObj; |
| 11 |
|
| 12 |
Obj* provide_obj_ptr(); |
| 13 |
void receive_obj_ptr(Obj* p = nullptr); |
| 14 |
void receive_obj_ref(Obj&); |
| 15 |
void receive_obj_rref(Obj&&); |
| 16 |
sqlite3* open_db(); |
| 17 |
void close_db(sqlite3*); |
| 18 |
|
| 19 |
Obj* ptr(Obj* arg) { |
| 20 |
receive_obj_ptr(provide_obj_ptr()); |
| 21 |
// expected-warning@-1{{Call argument for parameter 'p' uses a forward declared type 'Obj *'}} |
| 22 |
auto *obj = provide_obj_ptr(); |
| 23 |
// expected-warning@-1{{Local variable 'obj' uses a forward declared type 'Obj *'}} |
| 24 |
receive_obj_ptr(arg); |
| 25 |
receive_obj_ptr(nullptr); |
| 26 |
receive_obj_ptr(); |
| 27 |
auto* db = open_db(); |
| 28 |
close_db(db); |
| 29 |
return obj; |
| 30 |
} |
| 31 |
|
| 32 |
Obj& provide_obj_ref(); |
| 33 |
void receive_obj_ref(Obj& p); |
| 34 |
|
| 35 |
Obj& ref() { |
| 36 |
receive_obj_ref(provide_obj_ref()); |
| 37 |
// expected-warning@-1{{Call argument for parameter 'p' uses a forward declared type 'Obj &'}} |
| 38 |
auto &obj = provide_obj_ref(); |
| 39 |
// expected-warning@-1{{Local variable 'obj' uses a forward declared type 'Obj &'}} |
| 40 |
return obj; |
| 41 |
} |
| 42 |
|
| 43 |
void opaque_call_arg(Obj* obj, Obj&& otherObj, const RefPtr<Obj>& safeObj, WeakPtr<Obj> weakObj, std::unique_ptr<Obj>& uniqObj) { |
| 44 |
receive_obj_ref(*obj); |
| 45 |
receive_obj_ptr(&*obj); |
| 46 |
receive_obj_rref(std::move(otherObj)); |
| 47 |
receive_obj_rref(WTF::move(otherObj)); |
| 48 |
receive_obj_ref(*safeObj.get()); |
| 49 |
receive_obj_ptr(weakObj.get()); |
| 50 |
// expected-warning@-1{{Call argument for parameter 'p' uses a forward declared type 'Obj *'}} |
| 51 |
receive_obj_ref(*uniqObj); |
| 52 |
} |
| 53 |
|
| 54 |
Obj&& provide_obj_rval(); |
| 55 |
void receive_obj_rval(Obj&& p); |
| 56 |
|
| 57 |
void rval(Obj&& arg) { |
| 58 |
receive_obj_rval(provide_obj_rval()); |
| 59 |
// expected-warning@-1{{Call argument for parameter 'p' uses a forward declared type 'Obj &&'}} |
| 60 |
auto &&obj = provide_obj_rval(); |
| 61 |
// expected-warning@-1{{Local variable 'obj' uses a forward declared type 'Obj &&'}} |
| 62 |
receive_obj_rval(std::move(arg)); |
| 63 |
receive_obj_rval(WTF::move(arg)); |
| 64 |
} |
| 65 |
|
| 66 |
ObjCObj *provide_objcobj(); |
| 67 |
void receive_objcobj(ObjCObj *p); |
| 68 |
ObjCObj *objc_ptr() { |
| 69 |
receive_objcobj(provide_objcobj()); |
| 70 |
auto *objcobj = provide_objcobj(); |
| 71 |
return objcobj; |
| 72 |
} |
| 73 |
|
| 74 |
void obj_ptr_null_callee(ObjCObj* (*cb)()) { |
| 75 |
receive_objcobj(cb()); |
| 76 |
} |
| 77 |
|
| 78 |
struct WrapperObj { |
| 79 |
Obj* ptr { nullptr }; |
| 80 |
// expected-warning@-1{{Member variable 'ptr' uses a forward declared type 'Obj *'}} |
| 81 |
|
| 82 |
WrapperObj(Obj* obj); |
| 83 |
WrapperObj(Obj& obj); |
| 84 |
WrapperObj(Obj&& obj); |
| 85 |
}; |
| 86 |
|
| 87 |
void construct_ptr(Obj&& arg) { |
| 88 |
WrapperObj wrapper1(provide_obj_ptr()); |
| 89 |
// expected-warning@-1{{Call argument for parameter 'obj' uses a forward declared type 'Obj *'}} |
| 90 |
WrapperObj wrapper2(provide_obj_ref()); |
| 91 |
// expected-warning@-1{{Call argument for parameter 'obj' uses a forward declared type 'Obj &'}} |
| 92 |
WrapperObj wrapper3(std::move(arg)); |
| 93 |
WrapperObj wrapper4(WTF::move(arg)); |
| 94 |
} |
| 95 |
|
| 96 |
JSStringRef provide_opaque_ptr(); |
| 97 |
void receive_opaque_ptr(JSStringRef); |
| 98 |
NSZone *provide_zone(); |
| 99 |
|
| 100 |
JSStringRef opaque_ptr() { |
| 101 |
receive_opaque_ptr(provide_opaque_ptr()); |
| 102 |
auto ref = provide_opaque_ptr(); |
| 103 |
return ref; |
| 104 |
} |
| 105 |
|
| 106 |
@interface AnotherObj : NSObject |
| 107 |
- (Obj *)ptr; |
| 108 |
- (Obj &)ref; |
| 109 |
- (void)objc; |
| 110 |
- (void)doMoreWork:(ObjCObj *)obj; |
| 111 |
@end |
| 112 |
|
| 113 |
@implementation AnotherObj |
| 114 |
- (Obj *)ptr { |
| 115 |
receive_obj_ptr(provide_obj_ptr()); |
| 116 |
// expected-warning@-1{{Call argument for parameter 'p' uses a forward declared type 'Obj *'}} |
| 117 |
auto *obj = provide_obj_ptr(); |
| 118 |
// expected-warning@-1{{Local variable 'obj' uses a forward declared type 'Obj *'}} |
| 119 |
return obj; |
| 120 |
} |
| 121 |
|
| 122 |
- (Obj &)ref { |
| 123 |
receive_obj_ref(provide_obj_ref()); |
| 124 |
// expected-warning@-1{{Call argument for parameter 'p' uses a forward declared type 'Obj &'}} |
| 125 |
auto &obj = provide_obj_ref(); |
| 126 |
// expected-warning@-1{{Local variable 'obj' uses a forward declared type 'Obj &'}} |
| 127 |
return obj; |
| 128 |
} |
| 129 |
|
| 130 |
- (void)objc { |
| 131 |
auto *obj = provide_objcobj(); |
| 132 |
[obj doWork]; |
| 133 |
[self doMoreWork:provide_objcobj()]; |
| 134 |
[self doMoreWork:nil]; |
| 135 |
} |
| 136 |
|
| 137 |
- (void)doMoreWork:(ObjCObj *)obj { |
| 138 |
auto array = CFArrayCreateMutable(kCFAllocatorDefault, 10); |
| 139 |
CFArrayAppendValue(array, nullptr); |
| 140 |
auto log = os_log_create("Foo", "Bar"); |
| 141 |
os_log_msg(log, OS_LOG_TYPE_DEFAULT, "Some Log"); |
| 142 |
auto *zone = provide_zone(); |
| 143 |
} |
| 144 |
|
| 145 |
@end |
| 146 |
|
| 147 |
namespace template_forward_declare { |
| 148 |
|
| 149 |
template<typename> class HashSet; |
| 150 |
|
| 151 |
template<typename T> |
| 152 |
using SingleThreadHashSet = HashSet<T>; |
| 153 |
|
| 154 |
template<typename> class HashSet { }; |
| 155 |
|
| 156 |
struct Font { }; |
| 157 |
|
| 158 |
struct ComplexTextController { |
| 159 |
SingleThreadHashSet<const Font>* fallbackFonts { nullptr }; |
| 160 |
}; |
| 161 |
|
| 162 |
} |