diff options
author | George Karpenkov <ekarpenkov@apple.com> | 2018-11-30 20:43:42 +0000 |
---|---|---|
committer | George Karpenkov <ekarpenkov@apple.com> | 2018-11-30 20:43:42 +0000 |
commit | be3f4bd36bc95163088b63063e157e54c99a5b53 (patch) | |
tree | 8c84e493d7061eae878a199f53d05d9a3aa74cb1 /clang/test/Analysis | |
parent | e64fe2abaeaa045af3d36804e3da17efc94ba7de (diff) | |
download | bcm5719-llvm-be3f4bd36bc95163088b63063e157e54c99a5b53.tar.gz bcm5719-llvm-be3f4bd36bc95163088b63063e157e54c99a5b53.zip |
Revert "Reverting r347949-r347951 because they broke the test bots."
This reverts commit 5bad6129c012fbf186eb055be49344e790448ecc.
Hopefully fixing the issue which was breaking the bots.
llvm-svn: 348030
Diffstat (limited to 'clang/test/Analysis')
-rw-r--r-- | clang/test/Analysis/osobject-retain-release.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/test/Analysis/osobject-retain-release.cpp b/clang/test/Analysis/osobject-retain-release.cpp index ca5dfbf707c..1b54008e4bd 100644 --- a/clang/test/Analysis/osobject-retain-release.cpp +++ b/clang/test/Analysis/osobject-retain-release.cpp @@ -11,9 +11,12 @@ struct OSMetaClass; #define OSDynamicCast(type, inst) \ ((type *) OSMetaClassBase::safeMetaCast((inst), OSTypeID(type))) +using size_t = decltype(sizeof(int)); + struct OSObject { virtual void retain(); virtual void release() {}; + virtual void free(); virtual ~OSObject(){} unsigned int foo() { return 42; } @@ -23,6 +26,9 @@ struct OSObject { static OSObject *getObject(); static OSObject *GetObject(); + + static void * operator new(size_t size); + static const OSMetaClass * const metaClass; }; @@ -62,6 +68,34 @@ struct OSMetaClassBase { static OSObject *safeMetaCast(const OSObject *inst, const OSMetaClass *meta); }; +void check_free_no_error() { + OSArray *arr = OSArray::withCapacity(10); + arr->retain(); + arr->retain(); + arr->retain(); + arr->free(); +} + +void check_free_use_after_free() { + OSArray *arr = OSArray::withCapacity(10); // expected-note{{Call to method 'OSArray::withCapacity' returns an OSObject of type OSArray with a +1 retain count}} + arr->retain(); // expected-note{{Reference count incremented. The object now has a +2 retain count}} + arr->free(); // expected-note{{Object released}} + arr->retain(); // expected-warning{{Reference-counted object is used after it is released}} + // expected-note@-1{{Reference-counted object is used after it is released}} +} + +unsigned int check_leak_explicit_new() { + OSArray *arr = new OSArray; // expected-note{{Operator new returns an OSObject of type OSArray with a +1 retain count}} + return arr->getCount(); // expected-note{{Object leaked: allocated object of type OSArray is not referenced later in this execution path and has a retain count of +1}} + // expected-warning@-1{{Potential leak of an object of type OSArray}} +} + +unsigned int check_leak_factory() { + OSArray *arr = OSArray::withCapacity(10); // expected-note{{Call to method 'OSArray::withCapacity' returns an OSObject of type OSArray with a +1 retain count}} + return arr->getCount(); // expected-note{{Object leaked: object allocated and stored into 'arr' is not referenced later in this execution path and has a retain count of +1}} + // expected-warning@-1{{Potential leak of an object stored into 'arr'}} +} + void check_get_object() { OSObject::getObject(); } |