diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-07-12 00:16:25 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-07-12 00:16:25 +0000 |
commit | c36b30c92c78b95fd29fb5d9d6214d737b3bcb02 (patch) | |
tree | 715c5369b56b6b363095e1029133c079668fc9df /test/Analysis/inline.cpp | |
parent | 198871cc90375246d8692680467ff6e810edac36 (diff) |
[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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160094 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis/inline.cpp')
-rw-r--r-- | test/Analysis/inline.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/Analysis/inline.cpp b/test/Analysis/inline.cpp new file mode 100644 index 0000000000..d16eeaf619 --- /dev/null +++ b/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}} +} + |