summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis/inline.cpp
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-09-08 01:24:38 +0000
committerJordan Rose <jordan_rose@apple.com>2012-09-08 01:24:38 +0000
commitaaf83184803ec7e86373b516a3ee667ebe6addfd (patch)
tree74985bd297cf5904c0ef57a1cf0f1ad78954b332 /clang/test/Analysis/inline.cpp
parent88344b713370619f50e5b6eb8d07fd6c84da6c97 (diff)
downloadbcm5719-llvm-aaf83184803ec7e86373b516a3ee667ebe6addfd.tar.gz
bcm5719-llvm-aaf83184803ec7e86373b516a3ee667ebe6addfd.zip
[analyzer] Cast the result of a placement new-expression to the correct type.
This is necessary because further analysis will assume that the SVal's type matches the AST type. This caused a crash when trying to perform a derived-to-base cast on a C++ object that had been new'd to be another object type. Yet another crash in PR13763. llvm-svn: 163442
Diffstat (limited to 'clang/test/Analysis/inline.cpp')
-rw-r--r--clang/test/Analysis/inline.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/clang/test/Analysis/inline.cpp b/clang/test/Analysis/inline.cpp
index 6491b12c585..6c7cfc14e89 100644
--- a/clang/test/Analysis/inline.cpp
+++ b/clang/test/Analysis/inline.cpp
@@ -270,8 +270,13 @@ namespace OperatorNew {
namespace VirtualWithSisterCasts {
+ // This entire set of tests exercises casts from sister classes and
+ // from classes outside the hierarchy, which can very much confuse
+ // code that uses DynamicTypeInfo or needs to construct CXXBaseObjectRegions.
+ // These examples used to cause crashes in +Asserts builds.
struct Parent {
virtual int foo();
+ int x;
};
struct A : Parent {
@@ -282,20 +287,41 @@ namespace VirtualWithSisterCasts {
virtual int foo();
};
+ struct Grandchild : public A {};
+
struct Unrelated {};
void testDowncast(Parent *b) {
A *a = (A *)(void *)b;
clang_analyzer_eval(a->foo() == 42); // expected-warning{{UNKNOWN}}
+
+ a->x = 42;
+ clang_analyzer_eval(a->x == 42); // expected-warning{{TRUE}}
}
void testRelated(B *b) {
A *a = (A *)(void *)b;
clang_analyzer_eval(a->foo() == 42); // expected-warning{{UNKNOWN}}
+
+ a->x = 42;
+ clang_analyzer_eval(a->x == 42); // expected-warning{{TRUE}}
}
void testUnrelated(Unrelated *b) {
A *a = (A *)(void *)b;
clang_analyzer_eval(a->foo() == 42); // expected-warning{{UNKNOWN}}
+
+ a->x = 42;
+ clang_analyzer_eval(a->x == 42); // expected-warning{{TRUE}}
+ }
+
+ void testCastViaNew(B *b) {
+ Grandchild *g = new (b) Grandchild();
+ // FIXME: We actually now have perfect type info because of 'new'.
+ // This should be TRUE.
+ clang_analyzer_eval(g->foo() == 42); // expected-warning{{UNKNOWN}}
+
+ g->x = 42;
+ clang_analyzer_eval(g->x == 42); // expected-warning{{TRUE}}
}
}
OpenPOWER on IntegriCloud