summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2013-02-15 01:23:24 +0000
committerJordan Rose <jordan_rose@apple.com>2013-02-15 01:23:24 +0000
commit5bc0dd79e148171ab054d134189bb9cb37147fec (patch)
treee989f8d3a7d9fa16e57a37aaed7ba553751dd3dc /clang/test
parentf7d8d767fbbcd0d52644bdf4307c27a392855bf2 (diff)
downloadbcm5719-llvm-5bc0dd79e148171ab054d134189bb9cb37147fec.tar.gz
bcm5719-llvm-5bc0dd79e148171ab054d134189bb9cb37147fec.zip
[analyzer] Don't assert when mixing reinterpret_cast and derived-to-base casts.
This just adds a very simple check that if a DerivedToBase CastExpr is operating on a value with known C++ object type, and that type is not the base type specified in the AST, then the cast is invalid and we should return UnknownVal. In the future, perhaps we can have a checker that specifies that this is illegal, but we still shouldn't assert even if the user turns that checker off. PR14872 llvm-svn: 175239
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Analysis/reinterpret-cast.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/clang/test/Analysis/reinterpret-cast.cpp b/clang/test/Analysis/reinterpret-cast.cpp
index e82f7b68694..aaa600e4b96 100644
--- a/clang/test/Analysis/reinterpret-cast.cpp
+++ b/clang/test/Analysis/reinterpret-cast.cpp
@@ -18,3 +18,31 @@ void test(Data data) {
wrapper->set();
clang_analyzer_eval(wrapper->x == 42); // expected-warning{{TRUE}}
}
+
+namespace PR14872 {
+ class Base1 {};
+ class Derived1 : public Base1 {};
+
+ Derived1 *f1();
+
+ class Base2 {};
+ class Derived2 : public Base2 {};
+
+ void f2(Base2 *foo);
+
+ void f3(void** out)
+ {
+ Base1 *v;
+ v = f1();
+ *out = v;
+ }
+
+ void test()
+ {
+ Derived2 *p;
+ f3(reinterpret_cast<void**>(&p));
+ // Don't crash when upcasting here.
+ // In this case, 'p' actually refers to a Derived1.
+ f2(p);
+ }
+}
OpenPOWER on IntegriCloud