[analyzer] Tighten up safety in the use of lazy bindings.
- When deciding if we can reuse a lazy binding, make sure to check if there
are additional bindings in the sub-region.
- When reading from a lazy binding, don't accidentally strip off casts or
base object regions. This slows down lazy binding reading a bit but is
necessary for type sanity when treating one class as another.
A bit of minor refactoring allowed these two checks to be unified in a nice
early-return-using helper function.
<rdar://problem/13239840>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175703 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Analysis/array-struct-region.c b/test/Analysis/array-struct-region.c
index dfb4cf1..6817124 100644
--- a/test/Analysis/array-struct-region.c
+++ b/test/Analysis/array-struct-region.c
@@ -285,6 +285,13 @@
clang_analyzer_eval(s3.data[0] == 'a'); // expected-warning{{TRUE}}
clang_analyzer_eval(s3.data[1] == 'b'); // expected-warning{{TRUE}}
clang_analyzer_eval(s3.data[2] == 'c'); // expected-warning{{TRUE}}
+
+ s3.data[0] = 'z';
+ ShortString s4 = s3;
+
+ clang_analyzer_eval(s4.data[0] == 'z'); // expected-warning{{TRUE}}
+ clang_analyzer_eval(s4.data[1] == 'b'); // expected-warning{{TRUE}}
+ clang_analyzer_eval(s4.data[2] == 'c'); // expected-warning{{TRUE}}
}
void testArrayStructCopyNested() {
diff --git a/test/Analysis/derived-to-base.cpp b/test/Analysis/derived-to-base.cpp
index 80dbc17..6e4a3fa 100644
--- a/test/Analysis/derived-to-base.cpp
+++ b/test/Analysis/derived-to-base.cpp
@@ -303,4 +303,33 @@
}
#endif
}
+
+#if CONSTRUCTORS
+ namespace Nested {
+ struct NonTrivialCopy {
+ int padding;
+ NonTrivialCopy() {}
+ NonTrivialCopy(const NonTrivialCopy &) {}
+ };
+
+ struct FullyDerived : private NonTrivialCopy, public Derived {
+ int z;
+ };
+
+ struct Wrapper {
+ FullyDerived d;
+ int zz;
+
+ Wrapper(const FullyDerived &d) : d(d), zz(0) {}
+ };
+
+ void test5() {
+ Wrapper w((FullyDerived()));
+ w.d.x = 1;
+
+ Wrapper w2(w);
+ clang_analyzer_eval(getX(w2.d) == 1); // expected-warning{{TRUE}}
+ }
+ }
+#endif
}