summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-07-12 00:16:25 +0000
committerJordan Rose <jordan_rose@apple.com>2012-07-12 00:16:25 +0000
commitd66bee3f76382642f9236bc17af66be48489a0e1 (patch)
treedf3660f73c3d0d613451df3cf6c2a245fd5d4c43 /clang/test
parent88a0d3313b4db7e39540d07c6306b7322d8b7339 (diff)
downloadbcm5719-llvm-d66bee3f76382642f9236bc17af66be48489a0e1.tar.gz
bcm5719-llvm-d66bee3f76382642f9236bc17af66be48489a0e1.zip
[analyzer] Don't inline virtual calls unless we can devirtualize properly.
Previously we were using the static type of the base object to inline methods, whether virtual or non-virtual. Now, we try to see if the base object has a known type, and if so ask for its implementation of the method. llvm-svn: 160094
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Analysis/dynamic-cast.cpp5
-rw-r--r--clang/test/Analysis/inline.cpp45
2 files changed, 49 insertions, 1 deletions
diff --git a/clang/test/Analysis/dynamic-cast.cpp b/clang/test/Analysis/dynamic-cast.cpp
index 8e63b2bcb36..215bc497427 100644
--- a/clang/test/Analysis/dynamic-cast.cpp
+++ b/clang/test/Analysis/dynamic-cast.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-checker=core -verify %s
+// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-checker=core -analyzer-ipa=none -verify %s
class A {
public:
@@ -196,6 +196,9 @@ int testDynCastMostLikelyWillFail(C *c) {
} else {
res = 0;
}
+
+ // Note: IPA is turned off for this test because the code below shows how the
+ // dynamic_cast could succeed.
return *res; // expected-warning{{Dereference of null pointer}}
}
diff --git a/clang/test/Analysis/inline.cpp b/clang/test/Analysis/inline.cpp
new file mode 100644
index 00000000000..d16eeaf619b
--- /dev/null
+++ b/clang/test/Analysis/inline.cpp
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-ipa=inlining -verify %s
+
+void clang_analyzer_eval(bool);
+
+class A {
+public:
+ int getZero() { return 0; }
+ virtual int getNum() { return 0; }
+};
+
+void test(A &a) {
+ clang_analyzer_eval(a.getZero() == 0); // expected-warning{{TRUE}}
+ clang_analyzer_eval(a.getNum() == 0); // expected-warning{{UNKNOWN}}
+
+ A copy(a);
+ clang_analyzer_eval(copy.getZero() == 0); // expected-warning{{TRUE}}
+ clang_analyzer_eval(copy.getNum() == 0); // expected-warning{{TRUE}}
+}
+
+
+class One : public A {
+public:
+ virtual int getNum() { return 1; }
+};
+
+void testPathSensitivity(int x) {
+ A a;
+ One b;
+
+ A *ptr;
+ switch (x) {
+ case 0:
+ ptr = &a;
+ break;
+ case 1:
+ ptr = &b;
+ break;
+ default:
+ return;
+ }
+
+ // This should be true on both branches.
+ clang_analyzer_eval(ptr->getNum() == x); // expected-warning {{TRUE}}
+}
+
OpenPOWER on IntegriCloud