]> granicus.if.org Git - clang/commitdiff
[analyzer] Add another reinterpret_cast behavior test.
authorJordan Rose <jordan_rose@apple.com>
Thu, 21 Feb 2013 03:12:26 +0000 (03:12 +0000)
committerJordan Rose <jordan_rose@apple.com>
Thu, 21 Feb 2013 03:12:26 +0000 (03:12 +0000)
The test is similar to <rdar://problem/13239840> but doesn't actually test
the case that fails there. It's still a good test, though.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175715 91177308-0d34-0410-b5e6-96231b3b80d8

test/Analysis/reinterpret-cast.cpp

index aaa600e4b96e58c4c5334f54153728240fbb5b48..d1aed80a0c35efb52e7539eb553a910f1ee15669 100644 (file)
@@ -46,3 +46,21 @@ namespace PR14872 {
     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}}
+  }
+}