brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.2 KiB · 8aad838 Raw
156 lines · plain
1// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.ForwardDeclChecker -verify %s2 3#include "mock-types.h"4#include "objc-mock-types.h"5#include "mock-system-header.h"6 7typedef struct OpaqueJSString * JSStringRef;8 9class Obj;10@class ObjCObj;11 12Obj* provide_obj_ptr();13void receive_obj_ptr(Obj* p = nullptr);14void receive_obj_ref(Obj&);15void receive_obj_rref(Obj&&);16sqlite3* open_db();17void close_db(sqlite3*);18 19Obj* 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 32Obj& provide_obj_ref();33void receive_obj_ref(Obj& p);34 35Obj& 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 43void 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_ref(*safeObj.get());48  receive_obj_ptr(weakObj.get());49  // expected-warning@-1{{Call argument for parameter 'p' uses a forward declared type 'Obj *'}}50  receive_obj_ref(*uniqObj);51}52 53Obj&& provide_obj_rval();54void receive_obj_rval(Obj&& p);55 56void rval(Obj&& arg) {57  receive_obj_rval(provide_obj_rval());58  // expected-warning@-1{{Call argument for parameter 'p' uses a forward declared type 'Obj &&'}}59  auto &&obj = provide_obj_rval();60  // expected-warning@-1{{Local variable 'obj' uses a forward declared type 'Obj &&'}}61  receive_obj_rval(std::move(arg));62}63 64ObjCObj *provide_objcobj();65void receive_objcobj(ObjCObj *p);66ObjCObj *objc_ptr() {67  receive_objcobj(provide_objcobj());68  auto *objcobj = provide_objcobj();69  return objcobj;70}71 72struct WrapperObj {73  Obj* ptr { nullptr };74  // expected-warning@-1{{Member variable 'ptr' uses a forward declared type 'Obj *'}}75 76  WrapperObj(Obj* obj);77  WrapperObj(Obj& obj);78  WrapperObj(Obj&& obj);79};80 81void construct_ptr(Obj&& arg) {82  WrapperObj wrapper1(provide_obj_ptr());83  // expected-warning@-1{{Call argument for parameter 'obj' uses a forward declared type 'Obj *'}}84  WrapperObj wrapper2(provide_obj_ref());85  // expected-warning@-1{{Call argument for parameter 'obj' uses a forward declared type 'Obj &'}}86  WrapperObj wrapper3(std::move(arg));87}88 89JSStringRef provide_opaque_ptr();90void receive_opaque_ptr(JSStringRef);91NSZone *provide_zone();92 93JSStringRef opaque_ptr() {94  receive_opaque_ptr(provide_opaque_ptr());95  auto ref = provide_opaque_ptr();96  return ref;97}98 99@interface AnotherObj : NSObject100- (Obj *)ptr;101- (Obj &)ref;102- (void)objc;103- (void)doMoreWork:(ObjCObj *)obj;104@end105 106@implementation AnotherObj107- (Obj *)ptr {108  receive_obj_ptr(provide_obj_ptr());109  // expected-warning@-1{{Call argument for parameter 'p' uses a forward declared type 'Obj *'}}110  auto *obj = provide_obj_ptr();111  // expected-warning@-1{{Local variable 'obj' uses a forward declared type 'Obj *'}}112  return obj;113}114 115- (Obj &)ref {116  receive_obj_ref(provide_obj_ref());117  // expected-warning@-1{{Call argument for parameter 'p' uses a forward declared type 'Obj &'}}118  auto &obj = provide_obj_ref();119  // expected-warning@-1{{Local variable 'obj' uses a forward declared type 'Obj &'}}120  return obj;121}122 123- (void)objc {124  auto *obj = provide_objcobj();125  [obj doWork];126  [self doMoreWork:provide_objcobj()];127  [self doMoreWork:nil];128}129 130- (void)doMoreWork:(ObjCObj *)obj {131  auto array = CFArrayCreateMutable(kCFAllocatorDefault, 10);132  CFArrayAppendValue(array, nullptr);133  auto log = os_log_create("Foo", "Bar");134  os_log_msg(log, OS_LOG_TYPE_DEFAULT, "Some Log");135  auto *zone = provide_zone();136}137 138@end139 140namespace template_forward_declare {141 142template<typename> class HashSet;143 144template<typename T>145using SingleThreadHashSet = HashSet<T>;146 147template<typename> class HashSet { };148 149struct Font { };150 151struct ComplexTextController {152    SingleThreadHashSet<const Font>* fallbackFonts { nullptr };153};154 155}156