diff options
author | Matthew Voss <matthew.voss@sony.com> | 2018-06-12 22:22:35 +0000 |
---|---|---|
committer | Matthew Voss <matthew.voss@sony.com> | 2018-06-12 22:22:35 +0000 |
commit | e4b014451ae7dceacbfb5d0d4b4c8beb34f48158 (patch) | |
tree | 4985b1c69468d7ecfb0e28685092623520de014b /test/Analysis/loop-widening-preserve-reference-type.cpp | |
parent | 08956eb168014e72aed6dff54dcdd5607a52aa5e (diff) | |
download | clang-e4b014451ae7dceacbfb5d0d4b4c8beb34f48158.tar.gz |
[analyzer] Ensure that loop widening does not invalidate references
Loop widening can invalidate a reference. If the analyzer attempts to visit the
destructor to a non-existent reference, it will crash. This patch ensures that
the reference is preserved.
https://reviews.llvm.org/D47044
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@334554 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis/loop-widening-preserve-reference-type.cpp')
-rw-r--r-- | test/Analysis/loop-widening-preserve-reference-type.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/Analysis/loop-widening-preserve-reference-type.cpp b/test/Analysis/loop-widening-preserve-reference-type.cpp new file mode 100644 index 0000000000..b5746d1fe7 --- /dev/null +++ b/test/Analysis/loop-widening-preserve-reference-type.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-max-loop 4 -analyzer-config widen-loops=true -verify %s + +void clang_analyzer_eval(int); + +struct A { + ~A() {} +}; +struct B : public A {}; + +void invalid_type_region_access() { + const A &x = B(); + for (int i = 0; i < 10; ++i) { } + clang_analyzer_eval(&x != 0); // expected-warning{{TRUE}} +} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; comparison may be assumed to always evaluate to true}} |