summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorDevin Coughlin <dcoughlin@apple.com>2015-06-15 01:00:42 +0000
committerDevin Coughlin <dcoughlin@apple.com>2015-06-15 01:00:42 +0000
commit0bee1d7ff1e14fffbc6bbdf50e5324ea4c92aeef (patch)
treedbf388172bc7110d5cb8d95cb1f3d5dcb0f7cdcf /clang/test
parentb11df184ad642c8601d4073fff54974fd76b70c7 (diff)
downloadbcm5719-llvm-0bee1d7ff1e14fffbc6bbdf50e5324ea4c92aeef.tar.gz
bcm5719-llvm-0bee1d7ff1e14fffbc6bbdf50e5324ea4c92aeef.zip
[analyzer] Remove ObjCContainersChecker size information when a CFMutableArrayRef escapes
Update ObjCContainersChecker to be notified when pointers escape so it can remove size information for escaping CFMutableArrayRefs. When such pointers escape, un-analyzed code could mutate the array and cause the size information to be incorrect. rdar://problem/19406485 llvm-svn: 239709
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Analysis/CFContainers.mm22
1 files changed, 22 insertions, 0 deletions
diff --git a/clang/test/Analysis/CFContainers.mm b/clang/test/Analysis/CFContainers.mm
index b01942310f7..f315bc9f045 100644
--- a/clang/test/Analysis/CFContainers.mm
+++ b/clang/test/Analysis/CFContainers.mm
@@ -19,6 +19,7 @@ typedef struct {
} CFArrayCallBacks;
typedef const struct __CFArray * CFArrayRef;
CFArrayRef CFArrayCreate(CFAllocatorRef allocator, const void **values, CFIndex numValues, const CFArrayCallBacks *callBacks);
+typedef struct __CFArray * CFMutableArrayRef;
typedef const struct __CFString * CFStringRef;
enum {
kCFNumberSInt8Type = 1,
@@ -202,3 +203,24 @@ void TestConst(CFArrayRef A, CFIndex sIndex, void* x[]) {
void TestNullArray() {
CFArrayGetValueAtIndex(0, 0);
}
+
+void ArrayRefMutableEscape(CFMutableArrayRef a);
+void ArrayRefEscape(CFArrayRef a);
+
+void TestCFMutableArrayRefEscapeViaMutableArgument(CFMutableArrayRef a) {
+ CFIndex aLen = CFArrayGetCount(a);
+ ArrayRefMutableEscape(a);
+
+ // ArrayRefMutableEscape could mutate a to make it have
+ // at least aLen + 1 elements, so do not report an error here.
+ CFArrayGetValueAtIndex(a, aLen);
+}
+
+void TestCFMutableArrayRefEscapeViaImmutableArgument(CFMutableArrayRef a) {
+ CFIndex aLen = CFArrayGetCount(a);
+ ArrayRefEscape(a);
+
+ // ArrayRefEscape is declared to take a CFArrayRef (i.e, an immutable array)
+ // so we assume it does not change the length of a.
+ CFArrayGetValueAtIndex(a, aLen); // expected-warning {{Index is out of bounds}}
+}
OpenPOWER on IntegriCloud