diff options
| author | Jordan Rose <jordan_rose@apple.com> | 2012-09-10 21:27:35 +0000 |
|---|---|---|
| committer | Jordan Rose <jordan_rose@apple.com> | 2012-09-10 21:27:35 +0000 |
| commit | 1e0e4001c83db629cfb0f38157379fa09bef6cb4 (patch) | |
| tree | 1efd546bd0d1fa836b6a716858ffdb590432b1f5 /clang/test | |
| parent | ca1e27be0deda2a163bb7817fcd80c29d415544f (diff) | |
| download | bcm5719-llvm-1e0e4001c83db629cfb0f38157379fa09bef6cb4.tar.gz bcm5719-llvm-1e0e4001c83db629cfb0f38157379fa09bef6cb4.zip | |
[analyzer] For now, don't inline C++ standard library functions.
This is a (heavy-handed) solution to PR13724 -- until we know we can do
a good job inlining the STL, it's best to be consistent and not generate
more false positives than we did before. We can selectively whitelist
certain parts of the 'std' namespace that are known to be safe.
This is controlled by analyzer config option 'c++-stdlib-inlining', which
can be set to "true" or "false".
This commit also adds control for whether or not to inline any templated
functions (member or non-member), under the config option
'c++-template-inlining'. This option is currently on by default.
llvm-svn: 163548
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/Analysis/inlining/stl.cpp | 29 | ||||
| -rw-r--r-- | clang/test/Analysis/system-header-simulator-cxx.h | 57 | ||||
| -rw-r--r-- | clang/test/Analysis/temp-obj-dtors-cfg-output.cpp | 2 | ||||
| -rw-r--r-- | clang/test/Analysis/templates.cpp | 8 |
4 files changed, 94 insertions, 2 deletions
diff --git a/clang/test/Analysis/inlining/stl.cpp b/clang/test/Analysis/inlining/stl.cpp new file mode 100644 index 00000000000..d9b3e02e79e --- /dev/null +++ b/clang/test/Analysis/inlining/stl.cpp @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-ipa=dynamic -verify %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-ipa=dynamic -analyzer-config c++-stdlib-inlining=true -DINLINE=1 -verify %s + +#include "../system-header-simulator-cxx.h" + +void clang_analyzer_eval(bool); + +void testVector(std::vector<int> &nums) { + if (nums.begin()) return; + if (nums.end()) return; + + clang_analyzer_eval(nums.size() == 0); +#if INLINE + // expected-warning@-2 {{TRUE}} +#else + // expected-warning@-4 {{UNKNOWN}} +#endif +} + +void testException(std::exception e) { + // Notice that the argument is NOT passed by reference, so we can devirtualize. + const char *x = e.what(); + clang_analyzer_eval(x == 0); +#if INLINE + // expected-warning@-2 {{TRUE}} +#else + // expected-warning@-4 {{UNKNOWN}} +#endif +} diff --git a/clang/test/Analysis/system-header-simulator-cxx.h b/clang/test/Analysis/system-header-simulator-cxx.h new file mode 100644 index 00000000000..e762d0a1bdf --- /dev/null +++ b/clang/test/Analysis/system-header-simulator-cxx.h @@ -0,0 +1,57 @@ +#pragma clang system_header + +namespace std { + template <class T1, class T2> + struct pair { + T1 first; + T2 second; + + pair() : first(), second() {} + pair(const T1 &a, const T2 &b) : first(a), second(b) {} + + template<class U1, class U2> + pair(const pair<U1, U2> &other) : first(other.first), second(other.second) {} + }; + + typedef __typeof__(sizeof(int)) size_t; + + template<typename T> + class vector { + T *_start; + T *_finish; + T *_end_of_storage; + public: + vector() : _start(0), _finish(0), _end_of_storage(0) {} + ~vector(); + + size_t size() const { + return size_t(_finish - _start); + } + + void push_back(); + T pop_back(); + + T &operator[](size_t n) { + return _start[n]; + } + + const T &operator[](size_t n) const { + return _start[n]; + } + + T *begin() { return _start; } + const T *begin() const { return _start; } + + T *end() { return _finish; } + const T *end() const { return _finish; } + }; + + class exception { + public: + exception() throw(); + virtual ~exception() throw(); + virtual const char *what() const throw() { + return 0; + } + }; +} diff --git a/clang/test/Analysis/temp-obj-dtors-cfg-output.cpp b/clang/test/Analysis/temp-obj-dtors-cfg-output.cpp index d13083ddf01..c8844754bef 100644 --- a/clang/test/Analysis/temp-obj-dtors-cfg-output.cpp +++ b/clang/test/Analysis/temp-obj-dtors-cfg-output.cpp @@ -1,5 +1,5 @@ // RUN: rm -f %t -// RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpCFG -analyzer-config cfg-temporary-dtors=1 %s > %t 2>&1 +// RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpCFG -analyzer-config cfg-temporary-dtors=true %s > %t 2>&1 // RUN: FileCheck --input-file=%t %s // XPASS: * diff --git a/clang/test/Analysis/templates.cpp b/clang/test/Analysis/templates.cpp index 671aa785820..faa5c1a7620 100644 --- a/clang/test/Analysis/templates.cpp +++ b/clang/test/Analysis/templates.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -fblocks -verify %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -fblocks -analyzer-config c++-template-inlining=false -DNO_INLINE -verify %s void clang_analyzer_eval(bool); @@ -39,6 +40,11 @@ inline unsigned array_lengthof(T (&)[N]) { void testNonTypeTemplateInstantiation() { const char *S[] = { "a", "b" }; - clang_analyzer_eval(array_lengthof(S) == 2); // expected-warning{{TRUE}} + clang_analyzer_eval(array_lengthof(S) == 2); +#ifndef NO_INLINE + // expected-warning@-2 {{TRUE}} +#else + // expected-warning@-4 {{UNKNOWN}} +#endif } |

