aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2012-08-19 10:33:04 +0000
committerDimitry Andric <dim@FreeBSD.org>2012-08-19 10:33:04 +0000
commit657bc3d9848e3be92029b2416031340988cd0111 (patch)
tree5b9c2fa9d79942fbdce3d618e37e27c18263af9a /test/Analysis
parent56d91b49b13fe55c918afbda19f6165b5fbff87a (diff)
downloadsrc-657bc3d9848e3be92029b2416031340988cd0111.tar.gz
src-657bc3d9848e3be92029b2416031340988cd0111.zip
Vendor import of clang trunk r162107:vendor/clang/clang-trunk-r162107
Notes
Notes: svn path=/vendor/clang/dist/; revision=239392 svn path=/vendor/clang/clang-trunk-r162107/; revision=239393; tag=vendor/clang/clang-trunk-r162107
Diffstat (limited to 'test/Analysis')
-rw-r--r--test/Analysis/CFNumber.c6
-rw-r--r--test/Analysis/CheckNSError.m4
-rw-r--r--test/Analysis/array-struct.c2
-rw-r--r--test/Analysis/ctor-inlining.mm48
-rw-r--r--test/Analysis/dtor.cpp54
-rw-r--r--test/Analysis/func.c14
-rw-r--r--test/Analysis/html-diags.c6
-rw-r--r--test/Analysis/inline.cpp27
-rw-r--r--test/Analysis/inlining/DynDispatchBifurcate.m10
-rw-r--r--test/Analysis/inlining/InlineObjCClassMethod.m30
-rw-r--r--test/Analysis/inlining/dyn-dispatch-bifurcate.cpp17
-rw-r--r--test/Analysis/keychainAPI.m6
-rw-r--r--test/Analysis/malloc-annotations.c4
-rw-r--r--test/Analysis/malloc.c6
-rw-r--r--test/Analysis/method-call-path-notes.cpp85
-rw-r--r--test/Analysis/method-call.cpp20
-rw-r--r--test/Analysis/misc-ps-region-store.m2
-rw-r--r--test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m4
-rw-r--r--test/Analysis/ptr-arith.c6
-rw-r--r--test/Analysis/reinterpret-cast.cpp20
-rw-r--r--test/Analysis/security-syntax-checks.m8
-rw-r--r--test/Analysis/sizeofpointer.c2
-rw-r--r--test/Analysis/stack-addr-ps.cpp2
-rw-r--r--test/Analysis/stream.c16
-rw-r--r--test/Analysis/variadic-method-types.m2
25 files changed, 353 insertions, 48 deletions
diff --git a/test/Analysis/CFNumber.c b/test/Analysis/CFNumber.c
index fbbe4d15f49f..537e49785130 100644
--- a/test/Analysis/CFNumber.c
+++ b/test/Analysis/CFNumber.c
@@ -17,11 +17,11 @@ typedef const struct __CFNumber * CFNumberRef;
extern CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr);
CFNumberRef f1(unsigned char x) {
- return CFNumberCreate(0, kCFNumberSInt16Type, &x); // expected-warning{{An 8 bit integer is used to initialize a CFNumber object that represents a 16 bit integer. 8 bits of the CFNumber value will be garbage.}}
+ return CFNumberCreate(0, kCFNumberSInt16Type, &x); // expected-warning{{An 8 bit integer is used to initialize a CFNumber object that represents a 16 bit integer. 8 bits of the CFNumber value will be garbage}}
}
__attribute__((cf_returns_retained)) CFNumberRef f2(unsigned short x) {
- return CFNumberCreate(0, kCFNumberSInt8Type, &x); // expected-warning{{A 16 bit integer is used to initialize a CFNumber object that represents an 8 bit integer. 8 bits of the input integer will be lost.}}
+ return CFNumberCreate(0, kCFNumberSInt8Type, &x); // expected-warning{{A 16 bit integer is used to initialize a CFNumber object that represents an 8 bit integer. 8 bits of the input integer will be lost}}
}
// test that the attribute overrides the naming convention.
@@ -30,5 +30,5 @@ __attribute__((cf_returns_not_retained)) CFNumberRef CreateNum(unsigned char x)
}
CFNumberRef f3(unsigned i) {
- return CFNumberCreate(0, kCFNumberLongType, &i); // expected-warning{{A 32 bit integer is used to initialize a CFNumber object that represents a 64 bit integer.}}
+ return CFNumberCreate(0, kCFNumberLongType, &i); // expected-warning{{A 32 bit integer is used to initialize a CFNumber object that represents a 64 bit integer}}
}
diff --git a/test/Analysis/CheckNSError.m b/test/Analysis/CheckNSError.m
index d35b686ef1d9..cdec1d50f2ca 100644
--- a/test/Analysis/CheckNSError.m
+++ b/test/Analysis/CheckNSError.m
@@ -23,7 +23,7 @@ extern NSString * const NSXMLParserErrorDomain ;
@implementation A
- (void)myMethodWhichMayFail:(NSError **)error { // expected-warning {{Method accepting NSError** should have a non-void return value to indicate whether or not an error occurred}}
- *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // expected-warning {{Potential null dereference.}}
+ *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // expected-warning {{Potential null dereference}}
}
- (BOOL)myMethodWhichMayFail2:(NSError **)error { // no-warning
@@ -36,7 +36,7 @@ struct __CFError {};
typedef struct __CFError* CFErrorRef;
void foo(CFErrorRef* error) { // expected-warning {{Function accepting CFErrorRef* should have a non-void return value to indicate whether or not an error occurred}}
- *error = 0; // expected-warning {{Potential null dereference.}}
+ *error = 0; // expected-warning {{Potential null dereference}}
}
int f1(CFErrorRef* error) {
diff --git a/test/Analysis/array-struct.c b/test/Analysis/array-struct.c
index c5bdb86a14ed..1b36190729b5 100644
--- a/test/Analysis/array-struct.c
+++ b/test/Analysis/array-struct.c
@@ -151,7 +151,7 @@ struct s3 p[1];
// an ElementRegion of type 'char'. Then load a nonloc::SymbolVal from it and
// assigns to 'a'.
void f16(struct s3 *p) {
- struct s3 a = *((struct s3*) ((char*) &p[0])); // expected-warning{{Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption.}}
+ struct s3 a = *((struct s3*) ((char*) &p[0])); // expected-warning{{Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption}}
}
void inv(struct s1 *);
diff --git a/test/Analysis/ctor-inlining.mm b/test/Analysis/ctor-inlining.mm
index 54d51b46dc5e..fe4781c16e28 100644
--- a/test/Analysis/ctor-inlining.mm
+++ b/test/Analysis/ctor-inlining.mm
@@ -39,3 +39,51 @@ void testNonPODCopyConstructor() {
clang_analyzer_eval(b.x == 42); // expected-warning{{TRUE}}
}
+
+namespace ConstructorVirtualCalls {
+ class A {
+ public:
+ int *out1, *out2, *out3;
+
+ virtual int get() { return 1; }
+
+ A(int *out1) {
+ *out1 = get();
+ }
+ };
+
+ class B : public A {
+ public:
+ virtual int get() { return 2; }
+
+ B(int *out1, int *out2) : A(out1) {
+ *out2 = get();
+ }
+ };
+
+ class C : public B {
+ public:
+ virtual int get() { return 3; }
+
+ C(int *out1, int *out2, int *out3) : B(out1, out2) {
+ *out3 = get();
+ }
+ };
+
+ void test() {
+ int a, b, c;
+
+ C obj(&a, &b, &c);
+ clang_analyzer_eval(a == 1); // expected-warning{{TRUE}}
+ clang_analyzer_eval(b == 2); // expected-warning{{TRUE}}
+ clang_analyzer_eval(c == 3); // expected-warning{{TRUE}}
+
+ clang_analyzer_eval(obj.get() == 3); // expected-warning{{TRUE}}
+
+ // Sanity check for devirtualization.
+ A *base = &obj;
+ clang_analyzer_eval(base->get() == 3); // expected-warning{{TRUE}}
+ }
+}
+
+
diff --git a/test/Analysis/dtor.cpp b/test/Analysis/dtor.cpp
index 620994858c7c..1f45925561c9 100644
--- a/test/Analysis/dtor.cpp
+++ b/test/Analysis/dtor.cpp
@@ -173,3 +173,57 @@ void testDefaultArg() {
// Force a bug to be emitted.
*(char *)0 = 1; // expected-warning{{Dereference of null pointer}}
}
+
+
+namespace DestructorVirtualCalls {
+ class A {
+ public:
+ int *out1, *out2, *out3;
+
+ virtual int get() { return 1; }
+
+ ~A() {
+ *out1 = get();
+ }
+ };
+
+ class B : public A {
+ public:
+ virtual int get() { return 2; }
+
+ ~B() {
+ *out2 = get();
+ }
+ };
+
+ class C : public B {
+ public:
+ virtual int get() { return 3; }
+
+ ~C() {
+ *out3 = get();
+ }
+ };
+
+ void test() {
+ int a, b, c;
+
+ // New scope for the C object.
+ {
+ C obj;
+ clang_analyzer_eval(obj.get() == 3); // expected-warning{{TRUE}}
+
+ // Sanity check for devirtualization.
+ A *base = &obj;
+ clang_analyzer_eval(base->get() == 3); // expected-warning{{TRUE}}
+
+ obj.out1 = &a;
+ obj.out2 = &b;
+ obj.out3 = &c;
+ }
+
+ clang_analyzer_eval(a == 1); // expected-warning{{TRUE}}
+ clang_analyzer_eval(b == 2); // expected-warning{{TRUE}}
+ clang_analyzer_eval(c == 3); // expected-warning{{TRUE}}
+ }
+}
diff --git a/test/Analysis/func.c b/test/Analysis/func.c
index b6cebde81091..709ebf779376 100644
--- a/test/Analysis/func.c
+++ b/test/Analysis/func.c
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core -analyzer-store=region -verify %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core,debug.ExprInspection -analyzer-store=region -verify %s
+
+void clang_analyzer_eval(int);
void f(void) {
void (*p)(void);
@@ -13,3 +15,13 @@ void g(void (*fp)(void));
void f2() {
g(f);
}
+
+void f3(void (*f)(void), void (*g)(void)) {
+ clang_analyzer_eval(!f); // expected-warning{{UNKNOWN}}
+ f();
+ clang_analyzer_eval(!f); // expected-warning{{FALSE}}
+
+ clang_analyzer_eval(!g); // expected-warning{{UNKNOWN}}
+ (*g)();
+ clang_analyzer_eval(!g); // expected-warning{{FALSE}}
+}
diff --git a/test/Analysis/html-diags.c b/test/Analysis/html-diags.c
index b9361f72c64c..7c15df65d750 100644
--- a/test/Analysis/html-diags.c
+++ b/test/Analysis/html-diags.c
@@ -1,6 +1,6 @@
-// RUN: mkdir %t.dir
-// RUN: %clang_cc1 -analyze -analyzer-output=html -analyzer-checker=core -o %t.dir %s
-// RUN: rm -fR %t.dir
+// RUN: mkdir %T/dir
+// RUN: %clang_cc1 -analyze -analyzer-output=html -analyzer-checker=core -o %T/dir %s
+// RUN: rm -fR %T/dir
// Currently this test mainly checks that the HTML diagnostics doesn't crash
// when handling macros will calls with macros. We should actually validate
diff --git a/test/Analysis/inline.cpp b/test/Analysis/inline.cpp
index 4eaed9fed13c..6b9a885f50f3 100644
--- a/test/Analysis/inline.cpp
+++ b/test/Analysis/inline.cpp
@@ -166,3 +166,30 @@ namespace PR13569_virtual {
x.interface();
}
}
+
+namespace Invalidation {
+ struct X {
+ void touch(int &x) const {
+ x = 0;
+ }
+
+ void touch2(int &x) const;
+
+ virtual void touchV(int &x) const {
+ x = 0;
+ }
+
+ virtual void touchV2(int &x) const;
+
+ int test() const {
+ // We were accidentally not invalidating under -analyzer-ipa=inlining
+ // at one point for virtual methods with visible definitions.
+ int a, b, c, d;
+ touch(a);
+ touch2(b);
+ touchV(c);
+ touchV2(d);
+ return a + b + c + d; // no-warning
+ }
+ };
+}
diff --git a/test/Analysis/inlining/DynDispatchBifurcate.m b/test/Analysis/inlining/DynDispatchBifurcate.m
index e78b90bb8c1f..6637dfdba571 100644
--- a/test/Analysis/inlining/DynDispatchBifurcate.m
+++ b/test/Analysis/inlining/DynDispatchBifurcate.m
@@ -160,17 +160,17 @@ int testCallToPublicAPICat(PublicSubClass *p) {
// weither they are "public" or private.
int testPublicProperty(PublicClass *p) {
int x = 0;
- [p setValue3:0];
- if ([p value3] != 0)
- return 5/x; // expected-warning {{Division by zero}} // TODO: no warning, we should always inline the property.
- return 5/[p value3];// expected-warning {{Division by zero}}
+ p.value3 = 0;
+ if (p.value3 != 0)
+ return 5/x;
+ return 5/p.value3;// expected-warning {{Division by zero}}
}
int testExtension(PublicClass *p) {
int x = 0;
[p setValue2:0];
if ([p value2] != 0)
- return 5/x; // expected-warning {{Division by zero}} // TODO: no warning, we should always inline the property.
+ return 5/x; // expected-warning {{Division by zero}}
return 5/[p value2]; // expected-warning {{Division by zero}}
}
diff --git a/test/Analysis/inlining/InlineObjCClassMethod.m b/test/Analysis/inlining/InlineObjCClassMethod.m
index 7e8b51fe0be0..814d437a52d0 100644
--- a/test/Analysis/inlining/InlineObjCClassMethod.m
+++ b/test/Analysis/inlining/InlineObjCClassMethod.m
@@ -179,3 +179,33 @@ int foo2() {
int y = [MyParentSelf testSelf];
return 5/y; // Should warn here.
}
+
+// TODO: We do not inline 'getNum' in the following case, where the value of
+// 'self' in call '[self getNum]' is available and evaualtes to
+// 'SelfUsedInParentChild' if it's called from fooA.
+// Self region should get created before we call foo and yje call to super
+// should keep it live.
+@interface SelfUsedInParent : NSObject
++ (int)getNum;
++ (int)foo;
+@end
+@implementation SelfUsedInParent
++ (int)getNum {return 5;}
++ (int)foo {
+ return [self getNum];
+}
+@end
+@interface SelfUsedInParentChild : SelfUsedInParent
++ (int)getNum;
++ (int)fooA;
+@end
+@implementation SelfUsedInParentChild
++ (int)getNum {return 0;}
++ (int)fooA {
+ return [super foo];
+}
+@end
+int checkSelfUsedInparentClassMethod() {
+ return 5/[SelfUsedInParentChild fooA];
+}
+
diff --git a/test/Analysis/inlining/dyn-dispatch-bifurcate.cpp b/test/Analysis/inlining/dyn-dispatch-bifurcate.cpp
new file mode 100644
index 000000000000..fa473aebce32
--- /dev/null
+++ b/test/Analysis/inlining/dyn-dispatch-bifurcate.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-ipa=dynamic-bifurcate -verify %s
+
+void clang_analyzer_eval(bool);
+
+class A {
+public:
+ virtual int get() { return 0; }
+};
+
+void testBifurcation(A *a) {
+ clang_analyzer_eval(a->get() == 0); // expected-warning{{TRUE}} expected-warning{{UNKNOWN}}
+}
+
+void testKnown() {
+ A a;
+ clang_analyzer_eval(a.get() == 0); // expected-warning{{TRUE}}
+}
diff --git a/test/Analysis/keychainAPI.m b/test/Analysis/keychainAPI.m
index cb4f72c9c454..585a32ddc342 100644
--- a/test/Analysis/keychainAPI.m
+++ b/test/Analysis/keychainAPI.m
@@ -76,7 +76,7 @@ void errRetVal() {
UInt32 length;
void *outData;
st = SecKeychainItemCopyContent(2, ptr, ptr, &length, &outData);
- if (st == GenericError) // expected-warning{{Allocated data is not released: missing a call to 'SecKeychainItemFreeContent'.}}
+ if (st == GenericError) // expected-warning{{Allocated data is not released: missing a call to 'SecKeychainItemFreeContent'}}
SecKeychainItemFreeContent(ptr, outData); // expected-warning{{Only call free if a valid (non-NULL) buffer was returned}}
}
@@ -220,7 +220,7 @@ int foo(CFTypeRef keychainOrArray, SecProtocolType protocol,
if (st == noErr)
SecKeychainItemFreeContent(ptr, outData[3]);
}
- if (length) { // expected-warning{{Allocated data is not released: missing a call to 'SecKeychainItemFreeContent'.}}
+ if (length) { // expected-warning{{Allocated data is not released: missing a call to 'SecKeychainItemFreeContent'}}
length++;
}
return 0;
@@ -318,7 +318,7 @@ void radar10508828_2() {
UInt32 pwdLen = 0;
void* pwdBytes = 0;
OSStatus rc = SecKeychainFindGenericPassword(0, 3, "foo", 3, "bar", &pwdLen, &pwdBytes, 0);
- SecKeychainItemFreeContent(0, pwdBytes); // expected-warning {{Only call free if a valid (non-NULL) buffer was returned.}}
+ SecKeychainItemFreeContent(0, pwdBytes); // expected-warning {{Only call free if a valid (non-NULL) buffer was returned}}
}
//Example from bug 10797.
diff --git a/test/Analysis/malloc-annotations.c b/test/Analysis/malloc-annotations.c
index 1dc0f7837bad..9c040b688d2b 100644
--- a/test/Analysis/malloc-annotations.c
+++ b/test/Analysis/malloc-annotations.c
@@ -208,11 +208,11 @@ void f7_realloc() {
}
void PR6123() {
- int *x = malloc(11); // expected-warning{{Cast a region whose size is not a multiple of the destination type size.}}
+ int *x = malloc(11); // expected-warning{{Cast a region whose size is not a multiple of the destination type size}}
}
void PR7217() {
- int *buf = malloc(2); // expected-warning{{Cast a region whose size is not a multiple of the destination type size.}}
+ int *buf = malloc(2); // expected-warning{{Cast a region whose size is not a multiple of the destination type size}}
buf[1] = 'c'; // not crash
}
diff --git a/test/Analysis/malloc.c b/test/Analysis/malloc.c
index f60271f39f4c..e3d92d9ad671 100644
--- a/test/Analysis/malloc.c
+++ b/test/Analysis/malloc.c
@@ -260,11 +260,11 @@ void f7_realloc() {
}
void PR6123() {
- int *x = malloc(11); // expected-warning{{Cast a region whose size is not a multiple of the destination type size.}}
+ int *x = malloc(11); // expected-warning{{Cast a region whose size is not a multiple of the destination type size}}
}
void PR7217() {
- int *buf = malloc(2); // expected-warning{{Cast a region whose size is not a multiple of the destination type size.}}
+ int *buf = malloc(2); // expected-warning{{Cast a region whose size is not a multiple of the destination type size}}
buf[1] = 'c'; // not crash
}
@@ -389,7 +389,7 @@ void mallocEscapeMalloc() {
void mallocMalloc() {
int *p = malloc(12);
- p = malloc(12); // expected-warning 2 {{Memory is never released; potential leak}}
+ p = malloc(12); // expected-warning {{Memory is never released; potential leak}}
}
void mallocFreeMalloc() {
diff --git a/test/Analysis/method-call-path-notes.cpp b/test/Analysis/method-call-path-notes.cpp
index fbf0cae7d8a6..17034b9b0001 100644
--- a/test/Analysis/method-call-path-notes.cpp
+++ b/test/Analysis/method-call-path-notes.cpp
@@ -36,6 +36,11 @@ void test_ic_member_ptr() {
(p->*bar)(); // expected-warning {{Called C++ object pointer is null}} expected-note{{Called C++ object pointer is null}}
}
+void test_cast(const TestInstanceCall *p) {
+ if (!p) // expected-note {{Assuming pointer value is null}} expected-note {{Taking true branch}}
+ const_cast<TestInstanceCall *>(p)->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note {{Called C++ object pointer is null}}
+}
+
// CHECK: <?xml version="1.0" encoding="UTF-8"?>
// CHECK: <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
// CHECK: <plist version="1.0">
@@ -659,6 +664,86 @@ void test_ic_member_ptr() {
// CHECK: <key>file</key><integer>0</integer>
// CHECK: </dict>
// CHECK: </dict>
+// CHECK: <dict>
+// CHECK: <key>path</key>
+// CHECK: <array>
+// CHECK: <dict>
+// CHECK: <key>kind</key><string>control</string>
+// CHECK: <key>edges</key>
+// CHECK: <array>
+// CHECK: <dict>
+// CHECK: <key>start</key>
+// CHECK: <array>
+// CHECK: <dict>
+// CHECK: <key>line</key><integer>40</integer>
+// CHECK: <key>col</key><integer>3</integer>
+// CHECK: <key>file</key><integer>0</integer>
+// CHECK: </dict>
+// CHECK: <dict>
+// CHECK: <key>line</key><integer>40</integer>
+// CHECK: <key>col</key><integer>4</integer>
+// CHECK: <key>file</key><integer>0</integer>
+// CHECK: </dict>
+// CHECK: </array>
+// CHECK: <key>end</key>
+// CHECK: <array>
+// CHECK: <dict>
+// CHECK: <key>line</key><integer>41</integer>
+// CHECK: <key>col</key><integer>5</integer>
+// CHECK: <key>file</key><integer>0</integer>
+// CHECK: </dict>
+// CHECK: <dict>
+// CHECK: <key>line</key><integer>41</integer>
+// CHECK: <key>col</key><integer>14</integer>
+// CHECK: <key>file</key><integer>0</integer>
+// CHECK: </dict>
+// CHECK: </array>
+// CHECK: </dict>
+// CHECK: </array>
+// CHECK: </dict>
+// CHECK: <dict>
+// CHECK: <key>kind</key><string>event</string>
+// CHECK: <key>location</key>
+// CHECK: <dict>
+// CHECK: <key>line</key><integer>41</integer>
+// CHECK: <key>col</key><integer>5</integer>
+// CHECK: <key>file</key><integer>0</integer>
+// CHECK: </dict>
+// CHECK: <key>ranges</key>
+// CHECK: <array>
+// CHECK: <array>
+// CHECK: <dict>
+// CHECK: <key>line</key><integer>41</integer>
+// CHECK: <key>col</key><integer>5</integer>
+// CHECK: <key>file</key><integer>0</integer>
+// CHECK: </dict>
+// CHECK: <dict>
+// CHECK: <key>line</key><integer>41</integer>
+// CHECK: <key>col</key><integer>37</integer>
+// CHECK: <key>file</key><integer>0</integer>
+// CHECK: </dict>
+// CHECK: </array>
+// CHECK: </array>
+// CHECK: <key>depth</key><integer>0</integer>
+// CHECK: <key>extended_message</key>
+// CHECK: <string>Called C++ object pointer is null</string>
+// CHECK: <key>message</key>
+// CHECK: <string>Called C++ object pointer is null</string>
+// CHECK: </dict>
+// CHECK: </array>
+// CHECK: <key>description</key><string>Called C++ object pointer is null</string>
+// CHECK: <key>category</key><string>Logic error</string>
+// CHECK: <key>type</key><string>Called C++ object pointer is null</string>
+// CHECK: <key>issue_context_kind</key><string>function</string>
+// CHECK: <key>issue_context</key><string>test_cast</string>
+// CHECK: <key>issue_hash</key><integer>2</integer>
+// CHECK: <key>location</key>
+// CHECK: <dict>
+// CHECK: <key>line</key><integer>41</integer>
+// CHECK: <key>col</key><integer>5</integer>
+// CHECK: <key>file</key><integer>0</integer>
+// CHECK: </dict>
+// CHECK: </dict>
// CHECK: </array>
// CHECK: </dict>
// CHECK: </plist>
diff --git a/test/Analysis/method-call.cpp b/test/Analysis/method-call.cpp
index 91da532456d7..912062739c34 100644
--- a/test/Analysis/method-call.cpp
+++ b/test/Analysis/method-call.cpp
@@ -1,25 +1,37 @@
// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-ipa=inlining -analyzer-store region -verify %s
-// XFAIL: *
void clang_analyzer_eval(bool);
+
struct A {
int x;
A(int a) { x = a; }
int getx() const { return x; }
};
+void testNullObject(A *a) {
+ clang_analyzer_eval(a); // expected-warning{{UNKNOWN}}
+ (void)a->getx(); // assume we know what we're doing
+ clang_analyzer_eval(a); // expected-warning{{TRUE}}
+}
+
+
+// FIXME: These require constructor inlining to be enabled.
+
void f1() {
A x(3);
- clang_analyzer_eval(x.getx() == 3); // expected-warning{{TRUE}}
+ // should be TRUE
+ clang_analyzer_eval(x.getx() == 3); // expected-warning{{UNKNOWN}}
}
void f2() {
const A &x = A(3);
- clang_analyzer_eval(x.getx() == 3); // expected-warning{{TRUE}}
+ // should be TRUE
+ clang_analyzer_eval(x.getx() == 3); // expected-warning{{UNKNOWN}}
}
void f3() {
const A &x = (A)3;
- clang_analyzer_eval(x.getx() == 3); // expected-warning{{TRUE}}
+ // should be TRUE
+ clang_analyzer_eval(x.getx() == 3); // expected-warning{{UNKNOWN}}
}
diff --git a/test/Analysis/misc-ps-region-store.m b/test/Analysis/misc-ps-region-store.m
index 88860bbe10d3..2b481c4a558b 100644
--- a/test/Analysis/misc-ps-region-store.m
+++ b/test/Analysis/misc-ps-region-store.m
@@ -299,7 +299,7 @@ void test_handle_array_wrapper_helper();
int test_handle_array_wrapper() {
struct ArrayWrapper x;
test_handle_array_wrapper_helper(&x);
- struct WrappedStruct *p = (struct WrappedStruct*) x.y; // expected-warning{{Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption.}}
+ struct WrappedStruct *p = (struct WrappedStruct*) x.y; // expected-warning{{Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption}}
return p->z; // no-warning
}
diff --git a/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m b/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m
index e4d5aaf82b2d..7cf2aee35fc0 100644
--- a/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m
+++ b/test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m
@@ -80,11 +80,11 @@ int handleVoidInComma() {
int marker(void) { // control reaches end of non-void function
}
+// CHECK-darwin8: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage
// CHECK-darwin8: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage
-// CHECK-darwin8: warning: The receiver of message 'unsignedLongLongM' is nil and returns a value of type 'unsigned long long' that will be garbage
// CHECK-darwin8: warning: The receiver of message 'doubleM' is nil and returns a value of type 'double' that will be garbage
+// CHECK-darwin8: warning: The receiver of message 'unsignedLongLongM' is nil and returns a value of type 'unsigned long long' that will be garbage
// CHECK-darwin8: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage
-// CHECK-darwin8: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage
// CHECK-darwin9-NOT: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage
// CHECK-darwin9-NOT: warning: The receiver of message 'unsignedLongLongM' is nil and returns a value of type 'unsigned long long' that will be garbage
diff --git a/test/Analysis/ptr-arith.c b/test/Analysis/ptr-arith.c
index 6567000c735f..884ae5b9bbcd 100644
--- a/test/Analysis/ptr-arith.c
+++ b/test/Analysis/ptr-arith.c
@@ -36,7 +36,7 @@ domain_port (const char *domain_b, const char *domain_e,
void f3() {
int x, y;
- int d = &y - &x; // expected-warning{{Subtraction of two pointers that do not point to the same memory chunk may cause incorrect result.}}
+ int d = &y - &x; // expected-warning{{Subtraction of two pointers that do not point to the same memory chunk may cause incorrect result}}
int a[10];
int *p = &a[2];
@@ -46,13 +46,13 @@ void f3() {
void f4() {
int *p;
- p = (int*) 0x10000; // expected-warning{{Using a fixed address is not portable because that address will probably not be valid in all environments or platforms.}}
+ p = (int*) 0x10000; // expected-warning{{Using a fixed address is not portable because that address will probably not be valid in all environments or platforms}}
}
void f5() {
int x, y;
int *p;
- p = &x + 1; // expected-warning{{Pointer arithmetic done on non-array variables means reliance on memory layout, which is dangerous.}}
+ p = &x + 1; // expected-warning{{Pointer arithmetic done on non-array variables means reliance on memory layout, which is dangerous}}
int a[10];
p = a + 1; // no-warning
diff --git a/test/Analysis/reinterpret-cast.cpp b/test/Analysis/reinterpret-cast.cpp
new file mode 100644
index 000000000000..73f2e2de7381
--- /dev/null
+++ b/test/Analysis/reinterpret-cast.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-ipa=inlining -verify %s
+
+void clang_analyzer_eval(bool);
+
+typedef struct Opaque *Data;
+struct IntWrapper {
+ int x;
+};
+
+struct Child : public IntWrapper {
+ void set() { x = 42; }
+};
+
+void test(Data data) {
+ Child *wrapper = reinterpret_cast<Child*>(data);
+ // Don't crash when upcasting here.
+ // We don't actually know if 'data' is a Child.
+ wrapper->set();
+ clang_analyzer_eval(wrapper->x == 42); // expected-warning{{TRUE}}
+}
diff --git a/test/Analysis/security-syntax-checks.m b/test/Analysis/security-syntax-checks.m
index f4ccefe58cdb..1df8a408a697 100644
--- a/test/Analysis/security-syntax-checks.m
+++ b/test/Analysis/security-syntax-checks.m
@@ -46,7 +46,7 @@ int getpw(unsigned int uid, char *buf);
void test_getpw() {
char buff[1024];
- getpw(2, buff); // expected-warning{{The getpw() function is dangerous as it may overflow the provided buffer. It is obsoleted by getpwuid().}}
+ getpw(2, buff); // expected-warning{{The getpw() function is dangerous as it may overflow the provided buffer. It is obsoleted by getpwuid()}}
}
// <rdar://problem/6337132> CWE-273: Failure to Check Whether Privileges Were
@@ -138,7 +138,7 @@ void test_strcpy() {
char x[4];
char *y;
- strcpy(x, y); //expected-warning{{Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119.}}
+ strcpy(x, y); //expected-warning{{Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119}}
}
//===----------------------------------------------------------------------===
@@ -162,7 +162,7 @@ void test_strcat() {
char x[4];
char *y;
- strcat(x, y); //expected-warning{{Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119.}}
+ strcat(x, y); //expected-warning{{Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119}}
}
//===----------------------------------------------------------------------===
@@ -173,7 +173,7 @@ typedef __int32_t pid_t;
pid_t vfork(void);
void test_vfork() {
- vfork(); //expected-warning{{Call to function 'vfork' is insecure as it can lead to denial of service situations in the parent process.}}
+ vfork(); //expected-warning{{Call to function 'vfork' is insecure as it can lead to denial of service situations in the parent process}}
}
//===----------------------------------------------------------------------===
diff --git a/test/Analysis/sizeofpointer.c b/test/Analysis/sizeofpointer.c
index 0c86de88ae28..aa85fc002aa1 100644
--- a/test/Analysis/sizeofpointer.c
+++ b/test/Analysis/sizeofpointer.c
@@ -4,5 +4,5 @@ struct s {
};
int f(struct s *p) {
- return sizeof(p); // expected-warning{{The code calls sizeof() on a pointer type. This can produce an unexpected result.}}
+ return sizeof(p); // expected-warning{{The code calls sizeof() on a pointer type. This can produce an unexpected result}}
}
diff --git a/test/Analysis/stack-addr-ps.cpp b/test/Analysis/stack-addr-ps.cpp
index b21a03dc38a4..cbdb143c1857 100644
--- a/test/Analysis/stack-addr-ps.cpp
+++ b/test/Analysis/stack-addr-ps.cpp
@@ -87,6 +87,6 @@ struct TS {
// rdar://11345441
int* f5() {
- int& i = i; // expected-warning {{Assigned value is garbage or undefined}} expected-note {{binding reference variable 'i' here}}
+ int& i = i; // expected-warning {{Assigned value is garbage or undefined}} expected-note {{binding reference variable 'i' here}} expected-warning{{variable 'i' is uninitialized when used within its own initialization}}
return &i; // expected-warning {{address of stack memory associated with local variable 'i' returned}}
}
diff --git a/test/Analysis/stream.c b/test/Analysis/stream.c
index e68835e5cfc4..4a095cffd028 100644
--- a/test/Analysis/stream.c
+++ b/test/Analysis/stream.c
@@ -16,25 +16,25 @@ extern void rewind (FILE *__stream);
void f1(void) {
FILE *p = fopen("foo", "r");
char buf[1024];
- fread(buf, 1, 1, p); // expected-warning {{Stream pointer might be NULL.}}
+ fread(buf, 1, 1, p); // expected-warning {{Stream pointer might be NULL}}
fclose(p);
}
void f2(void) {
FILE *p = fopen("foo", "r");
- fseek(p, 1, SEEK_SET); // expected-warning {{Stream pointer might be NULL.}}
+ fseek(p, 1, SEEK_SET); // expected-warning {{Stream pointer might be NULL}}
fclose(p);
}
void f3(void) {
FILE *p = fopen("foo", "r");
- ftell(p); // expected-warning {{Stream pointer might be NULL.}}
+ ftell(p); // expected-warning {{Stream pointer might be NULL}}
fclose(p);
}
void f4(void) {
FILE *p = fopen("foo", "r");
- rewind(p); // expected-warning {{Stream pointer might be NULL.}}
+ rewind(p); // expected-warning {{Stream pointer might be NULL}}
fclose(p);
}
@@ -43,26 +43,26 @@ void f5(void) {
if (!p)
return;
fseek(p, 1, SEEK_SET); // no-warning
- fseek(p, 1, 3); // expected-warning {{The whence argument to fseek() should be SEEK_SET, SEEK_END, or SEEK_CUR.}}
+ fseek(p, 1, 3); // expected-warning {{The whence argument to fseek() should be SEEK_SET, SEEK_END, or SEEK_CUR}}
fclose(p);
}
void f6(void) {
FILE *p = fopen("foo", "r");
fclose(p);
- fclose(p); // expected-warning {{Try to close a file Descriptor already closed. Cause undefined behaviour.}}
+ fclose(p); // expected-warning {{Try to close a file Descriptor already closed. Cause undefined behaviour}}
}
void f7(void) {
FILE *p = tmpfile();
- ftell(p); // expected-warning {{Stream pointer might be NULL.}}
+ ftell(p); // expected-warning {{Stream pointer might be NULL}}
fclose(p);
}
void f8(int c) {
FILE *p = fopen("foo.c", "r");
if(c)
- return; // expected-warning {{Opened File never closed. Potential Resource leak.}}
+ return; // expected-warning {{Opened File never closed. Potential Resource leak}}
fclose(p);
}
diff --git a/test/Analysis/variadic-method-types.m b/test/Analysis/variadic-method-types.m
index 4d0f6bc3f75a..9f90e5ff343d 100644
--- a/test/Analysis/variadic-method-types.m
+++ b/test/Analysis/variadic-method-types.m
@@ -74,7 +74,7 @@ void f(id a, id<P> b, C* c, C<P> *d, FooType fooType, BarType barType) {
[NSArray arrayWithObjects:@"Hello", a, b, c, d, nil];
[NSArray arrayWithObjects:@"Foo", ^{}, nil];
- [NSArray arrayWithObjects:@"Foo", "Bar", "Baz", nil]; // expected-warning 2 {{Argument to 'NSArray' method 'arrayWithObjects:' should be an Objective-C pointer type, not 'char *'}}
+ [NSArray arrayWithObjects:@"Foo", "Bar", "Baz", nil]; // expected-warning {{Argument to 'NSArray' method 'arrayWithObjects:' should be an Objective-C pointer type, not 'char *'}}
[NSDictionary dictionaryWithObjectsAndKeys:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSDictionary' method 'dictionaryWithObjectsAndKeys:' should be an Objective-C pointer type, not 'char *'}}
[NSSet setWithObjects:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSSet' method 'setWithObjects:' should be an Objective-C pointer type, not 'char *'}}
[NSOrderedSet orderedSetWithObjects:@"Foo", "Bar", nil]; // expected-warning {{Argument to 'NSOrderedSet' method 'orderedSetWithObjects:' should be an Objective-C pointer type, not 'char *'}}