Anna Zaks | bfa9ab8 | 2013-01-24 23:15:30 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -verify %s |
Jordan Rose | 9f6441a | 2012-08-15 17:33:34 +0000 | [diff] [blame] | 2 | |
| 3 | void clang_analyzer_eval(bool); |
| 4 | |
| 5 | typedef struct Opaque *Data; |
| 6 | struct IntWrapper { |
| 7 | int x; |
| 8 | }; |
| 9 | |
| 10 | struct Child : public IntWrapper { |
| 11 | void set() { x = 42; } |
| 12 | }; |
| 13 | |
| 14 | void test(Data data) { |
| 15 | Child *wrapper = reinterpret_cast<Child*>(data); |
| 16 | // Don't crash when upcasting here. |
| 17 | // We don't actually know if 'data' is a Child. |
| 18 | wrapper->set(); |
| 19 | clang_analyzer_eval(wrapper->x == 42); // expected-warning{{TRUE}} |
| 20 | } |
Jordan Rose | ada0d22 | 2013-02-15 01:23:24 +0000 | [diff] [blame] | 21 | |
| 22 | namespace PR14872 { |
| 23 | class Base1 {}; |
| 24 | class Derived1 : public Base1 {}; |
| 25 | |
| 26 | Derived1 *f1(); |
| 27 | |
| 28 | class Base2 {}; |
| 29 | class Derived2 : public Base2 {}; |
| 30 | |
| 31 | void f2(Base2 *foo); |
| 32 | |
| 33 | void f3(void** out) |
| 34 | { |
| 35 | Base1 *v; |
| 36 | v = f1(); |
| 37 | *out = v; |
| 38 | } |
| 39 | |
| 40 | void test() |
| 41 | { |
| 42 | Derived2 *p; |
| 43 | f3(reinterpret_cast<void**>(&p)); |
| 44 | // Don't crash when upcasting here. |
| 45 | // In this case, 'p' actually refers to a Derived1. |
| 46 | f2(p); |
| 47 | } |
| 48 | } |