diff options
author | Ismail Pazarbasi <ismail.pazarbasi@gmail.com> | 2015-09-22 19:33:15 +0000 |
---|---|---|
committer | Ismail Pazarbasi <ismail.pazarbasi@gmail.com> | 2015-09-22 19:33:15 +0000 |
commit | d60db64e7dd4b430d74d883dfa8cb84c22c336c0 (patch) | |
tree | cc31d47025ed6cf6beab9114796bb44c204b759d /clang/test/Analysis/dtor.cpp | |
parent | 66aa3a7f9e250d623bf89e11c32b56c47f025676 (diff) | |
download | bcm5719-llvm-d60db64e7dd4b430d74d883dfa8cb84c22c336c0.tar.gz bcm5719-llvm-d60db64e7dd4b430d74d883dfa8cb84c22c336c0.zip |
Analyzer: Teach analyzer how to handle TypeTraitExpr
Summary:
`TypeTraitExpr`s are not supported by the ExprEngine today. Analyzer
creates a sink, and aborts the block. Therefore, certain bugs that
involve type traits intrinsics cannot be detected (see PR24710).
This patch creates boolean `SVal`s for `TypeTraitExpr`s, which are
evaluated by the compiler.
Test within the patch is a summary of PR24710.
Reviewers: zaks.anna, dcoughlin, krememek
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D12482
llvm-svn: 248314
Diffstat (limited to 'clang/test/Analysis/dtor.cpp')
-rw-r--r-- | clang/test/Analysis/dtor.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/clang/test/Analysis/dtor.cpp b/clang/test/Analysis/dtor.cpp index bb1e6254fb7..c67722283ff 100644 --- a/clang/test/Analysis/dtor.cpp +++ b/clang/test/Analysis/dtor.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config c++-inlining=destructors,cfg-temporary-dtors=true -Wno-null-dereference -Wno-inaccessible-base -verify %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection,cplusplus -analyzer-config c++-inlining=destructors,cfg-temporary-dtors=true -Wno-null-dereference -Wno-inaccessible-base -verify %s void clang_analyzer_eval(bool); void clang_analyzer_checkInlined(bool); @@ -505,3 +505,38 @@ namespace Incomplete { class Foo; // expected-note{{forward declaration}} void f(Foo *foo) { delete foo; } // expected-warning{{deleting pointer to incomplete type}} } + +namespace TypeTraitExpr { +template <bool IsSimple, typename T> +struct copier { + static void do_copy(T *dest, const T *src, unsigned count); +}; +template <typename T, typename U> +void do_copy(T *dest, const U *src, unsigned count) { + const bool IsSimple = __is_trivial(T) && __is_same(T, U); + copier<IsSimple, T>::do_copy(dest, src, count); +} +struct NonTrivial { + int *p; + NonTrivial() : p(new int[1]) { p[0] = 0; } + NonTrivial(const NonTrivial &other) { + p = new int[1]; + do_copy(p, other.p, 1); + } + NonTrivial &operator=(const NonTrivial &other) { + p = other.p; + return *this; + } + ~NonTrivial() { + delete[] p; // expected-warning {{free released memory}} + } +}; + +void f() { + NonTrivial nt1; + NonTrivial nt2(nt1); + nt1 = nt2; + clang_analyzer_eval(__is_trivial(NonTrivial)); // expected-warning{{FALSE}} + clang_analyzer_eval(__alignof(NonTrivial) > 0); // expected-warning{{TRUE}} +} +} |