summaryrefslogtreecommitdiff
path: root/clang/test/Analysis/reference.cpp
diff options
context:
space:
mode:
authorZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
committerZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
commit222e2a7620e6520ffaf4fc4e69d79c18da31542e (patch)
tree7bfbc05bfa3b41c8f9d2e56d53a0bc3e310df239 /clang/test/Analysis/reference.cpp
parent3d206f03985b50beacae843d880bccdc91a9f424 (diff)
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/Analysis/reference.cpp')
-rw-r--r--clang/test/Analysis/reference.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/clang/test/Analysis/reference.cpp b/clang/test/Analysis/reference.cpp
new file mode 100644
index 0000000..5897e68
--- /dev/null
+++ b/clang/test/Analysis/reference.cpp
@@ -0,0 +1,58 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core -analyzer-store=region -analyzer-constraints=range -verify -Wno-null-dereference %s
+// XFAIL
+
+typedef typeof(sizeof(int)) size_t;
+void malloc (size_t);
+
+void f1() {
+ int const &i = 3; // <--- **FIXME** This is currently not being modeled correctly.
+ int b = i;
+
+ int *p = 0;
+
+ if (b != 3)
+ *p = 1; // no-warning
+}
+
+char* ptr();
+char& ref();
+
+// These next two tests just shouldn't crash.
+char t1 () {
+ ref() = 'c';
+ return '0';
+}
+
+// just a sanity test, the same behavior as t1()
+char t2 () {
+ *ptr() = 'c';
+ return '0';
+}
+
+// Each of the tests below is repeated with pointers as well as references.
+// This is mostly a sanity check, but then again, both should work!
+char t3 () {
+ char& r = ref();
+ r = 'c'; // no-warning
+ if (r) return r;
+ return *(char*)0; // no-warning
+}
+
+char t4 () {
+ char* p = ptr();
+ *p = 'c'; // no-warning
+ if (*p) return *p;
+ return *(char*)0; // no-warning
+}
+
+char t5 (char& r) {
+ r = 'c'; // no-warning
+ if (r) return r;
+ return *(char*)0; // no-warning
+}
+
+char t6 (char* p) {
+ *p = 'c'; // no-warning
+ if (*p) return *p;
+ return *(char*)0; // no-warning
+}