summaryrefslogtreecommitdiff
path: root/clang/test/Analysis/misc-ps.c
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/misc-ps.c
parent3d206f03985b50beacae843d880bccdc91a9f424 (diff)
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/Analysis/misc-ps.c')
-rw-r--r--clang/test/Analysis/misc-ps.c128
1 files changed, 128 insertions, 0 deletions
diff --git a/clang/test/Analysis/misc-ps.c b/clang/test/Analysis/misc-ps.c
new file mode 100644
index 0000000..f81b0dd
--- /dev/null
+++ b/clang/test/Analysis/misc-ps.c
@@ -0,0 +1,128 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -disable-free -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=deadcode -verify %s
+
+int size_rdar9373039 = 1;
+int foo_rdar9373039(const char *);
+
+int rdar93730392() {
+ int x;
+ int j = 0;
+
+ for (int i = 0 ; i < size_rdar9373039 ; ++i)
+ x = 1;
+
+ int extra = (2 + foo_rdar9373039 ("Clang") + ((4 - ((unsigned int) (2 + foo_rdar9373039 ("Clang")) % 4)) % 4)) + (2 + foo_rdar9373039 ("1.0") + ((4 - ((unsigned int) (2 + foo_rdar9373039 ("1.0")) % 4)) % 4)); // expected-warning {{never read}}
+
+ for (int i = 0 ; i < size_rdar9373039 ; ++i)
+ j += x; // expected-warning {{garbage}}
+
+ return j;
+}
+
+
+int PR8962 (int *t) {
+ // This should look through the __extension__ no-op.
+ if (__extension__ (t)) return 0;
+ return *t; // expected-warning {{null pointer}}
+}
+
+int PR8962_b (int *t) {
+ // This should still ignore the nested casts
+ // which aren't handled by a single IgnoreParens()
+ if (((int)((int)t))) return 0;
+ return *t; // expected-warning {{null pointer}}
+}
+
+int PR8962_c (int *t) {
+ // If the last element in a StmtExpr was a ParenExpr, it's still live
+ if (({ (t ? (_Bool)0 : (_Bool)1); })) return 0;
+ return *t; // no-warning
+}
+
+int PR8962_d (int *t) {
+ // If the last element in a StmtExpr is an __extension__, it's still live
+ if (({ __extension__(t ? (_Bool)0 : (_Bool)1); })) return 0;
+ return *t; // no-warning
+}
+
+int PR8962_e (int *t) {
+ // Redundant casts can mess things up!
+ // Environment used to skip through NoOp casts, but LiveVariables didn't!
+ if (({ (t ? (int)(int)0L : (int)(int)1L); })) return 0;
+ return *t; // no-warning
+}
+
+int PR8962_f (int *t) {
+ // The StmtExpr isn't a block-level expression here,
+ // the __extension__ is. But the value should be attached to the StmtExpr
+ // anyway. Make sure the block-level check is /before/ IgnoreParens.
+ if ( __extension__({
+ _Bool r;
+ if (t) r = 0;
+ else r = 1;
+ r;
+ }) ) return 0;
+ return *t; // no-warning
+}
+
+// This previously crashed logic in the analyzer engine when evaluating locations.
+void rdar10308201_aux(unsigned val);
+void rdar10308201 (int valA, void *valB, unsigned valC) {
+ unsigned actual_base, lines;
+ if (valC == 0) {
+ actual_base = (unsigned)valB;
+ for (;;) {
+ if (valA & (1<<0))
+ rdar10308201_aux(actual_base);
+ }
+ }
+}
+
+typedef struct Struct103 {
+ unsigned i;
+} Struct103;
+typedef unsigned int size_t;
+void __my_memset_chk(char*, int, size_t);
+static int radar10367606(int t) {
+ Struct103 overall;
+ ((__builtin_object_size ((char *) &overall, 0) != (size_t) -1) ? __builtin___memset_chk ((char *) &overall, 0, sizeof(Struct103), __builtin_object_size ((char *) &overall, 0)) : __my_memset_chk ((char *) &overall, 0, sizeof(Struct103)));
+ return 0;
+}
+
+/* Caching out on a sink node. */
+extern int fooR10376675();
+extern int* bazR10376675();
+extern int nR10376675;
+void barR10376675(int *x) {
+ int *pm;
+ if (nR10376675 * 2) {
+ int *pk = bazR10376675();
+ pm = pk; //expected-warning {{never read}}
+ }
+ do {
+ *x = fooR10376675();
+ } while (0);
+}
+
+// Test accesses to wide character strings doesn't break the analyzer.
+typedef int wchar_t;
+struct rdar10385775 {
+ wchar_t *name;
+};
+void RDar10385775(struct rdar10385775* p) {
+ p->name = L"a";
+}
+
+// Test double loop of array and array literals. Previously this
+// resulted in a false positive uninitailized value warning.
+void rdar10686586() {
+ int array1[] = { 1, 2, 3, 0 };
+ int array2[] = { 1, 2, 3, 0 };
+ int *array[] = { array1, array2 };
+ int sum = 0;
+ for (int i = 0; i < 2; i++) {
+ for (int j = 0; j < 4; j++) {
+ sum += array[i][j]; // no-warning
+ }
+ }
+}
+