diff options
author | dim <dim@FreeBSD.org> | 2013-04-08 18:45:10 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2013-04-08 18:45:10 +0000 |
commit | c72c57c9e9b69944e3e009cd5e209634839581d3 (patch) | |
tree | 4fc2f184c499d106f29a386c452b49e5197bf63d /test/Analysis/reinterpret-cast.cpp | |
parent | 5b20025c30d23d521e12c1f33ec8fa6b821952cd (diff) | |
download | FreeBSD-src-c72c57c9e9b69944e3e009cd5e209634839581d3.zip FreeBSD-src-c72c57c9e9b69944e3e009cd5e209634839581d3.tar.gz |
Vendor import of clang trunk r178860:
http://llvm.org/svn/llvm-project/cfe/trunk@178860
Diffstat (limited to 'test/Analysis/reinterpret-cast.cpp')
-rw-r--r-- | test/Analysis/reinterpret-cast.cpp | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/test/Analysis/reinterpret-cast.cpp b/test/Analysis/reinterpret-cast.cpp index 73f2e2d..59e6a53 100644 --- a/test/Analysis/reinterpret-cast.cpp +++ b/test/Analysis/reinterpret-cast.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-ipa=inlining -verify %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -verify %s void clang_analyzer_eval(bool); @@ -18,3 +18,71 @@ 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); + } +} + +namespace rdar13249297 { + struct IntWrapperSubclass : public IntWrapper {}; + + struct IntWrapperWrapper { + IntWrapper w; + }; + + void test(IntWrapperWrapper *ww) { + reinterpret_cast<IntWrapperSubclass *>(ww)->x = 42; + clang_analyzer_eval(reinterpret_cast<IntWrapperSubclass *>(ww)->x == 42); // expected-warning{{TRUE}} + + clang_analyzer_eval(ww->w.x == 42); // expected-warning{{TRUE}} + ww->w.x = 0; + + clang_analyzer_eval(reinterpret_cast<IntWrapperSubclass *>(ww)->x == 42); // expected-warning{{FALSE}} + } +} + +namespace PR15345 { + class C {}; + + class Base { + public: + void (*f)(); + int x; + }; + + class Derived : public Base {}; + + void test() { + Derived* p; + *(reinterpret_cast<void**>(&p)) = new C; + p->f(); + + // We should still be able to do some reasoning about bindings. + p->x = 42; + clang_analyzer_eval(p->x == 42); // expected-warning{{TRUE}} + }; +} |