summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis/additive-folding-range-constraints.c
diff options
context:
space:
mode:
authorJordy Rose <jediknil@belkadan.com>2010-06-18 22:49:11 +0000
committerJordy Rose <jediknil@belkadan.com>2010-06-18 22:49:11 +0000
commitc0fe8429f269cd51d80b60243d33b8f2e8b7c891 (patch)
tree58525861162e46902f0c4c4d17ac5c6619cb40ce /clang/test/Analysis/additive-folding-range-constraints.c
parented8b6b799dbadbdbaa2b58c5e255cb3e9e444552 (diff)
downloadbcm5719-llvm-c0fe8429f269cd51d80b60243d33b8f2e8b7c891.tar.gz
bcm5719-llvm-c0fe8429f269cd51d80b60243d33b8f2e8b7c891.zip
Fold additive constants, and support comparsions of the form $sym+const1 <> const2
llvm-svn: 106339
Diffstat (limited to 'clang/test/Analysis/additive-folding-range-constraints.c')
-rw-r--r--clang/test/Analysis/additive-folding-range-constraints.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/clang/test/Analysis/additive-folding-range-constraints.c b/clang/test/Analysis/additive-folding-range-constraints.c
new file mode 100644
index 00000000000..1202328e91e
--- /dev/null
+++ b/clang/test/Analysis/additive-folding-range-constraints.c
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-experimental-checks -verify -analyzer-constraints=range %s
+#include <limits.h>
+
+// These are used to trigger warnings.
+typedef typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+void free(void *);
+#define NULL ((void*)0)
+
+// Each of these adjusted ranges has an adjustment small enough to split the
+// solution range across an overflow boundary (Min for <, Max for >).
+// This corresponds to one set of branches in RangeConstraintManager.
+void smallAdjustmentGT (unsigned a) {
+ char* b = NULL;
+ if (a+2 > 1)
+ b = malloc(1);
+ if (a == UINT_MAX-1 || a == UINT_MAX)
+ return; // no-warning
+ else if (a < UINT_MAX-1)
+ free(b);
+ return; // no-warning
+}
+
+void smallAdjustmentGE (unsigned a) {
+ char* b = NULL;
+ if (a+2 >= 1)
+ b = malloc(1);
+ if (a == UINT_MAX-1)
+ return; // no-warning
+ else if (a < UINT_MAX-1 || a == UINT_MAX)
+ free(b);
+ return; // no-warning
+}
+
+void smallAdjustmentLT (unsigned a) {
+ char* b = NULL;
+ if (a+1 < 2)
+ b = malloc(1);
+ if (a == 0 || a == UINT_MAX)
+ free(b);
+ return; // no-warning
+}
+
+void smallAdjustmentLE (unsigned a) {
+ char* b = NULL;
+ if (a+1 <= 2)
+ b = malloc(1);
+ if (a == 0 || a == 1 || a == UINT_MAX)
+ free(b);
+ return; // no-warning
+}
+
+
+// Each of these adjusted ranges has an adjustment large enough to push the
+// comparison value over an overflow boundary (Min for <, Max for >).
+// This corresponds to one set of branches in RangeConstraintManager.
+void largeAdjustmentGT (unsigned a) {
+ char* b = NULL;
+ if (a-2 > UINT_MAX-1)
+ b = malloc(1);
+ if (a == 1 || a == 0)
+ free(b);
+ else if (a > 1)
+ free(b);
+ return; // no-warning
+}
+
+void largeAdjustmentGE (unsigned a) {
+ char* b = NULL;
+ if (a-2 >= UINT_MAX-1)
+ b = malloc(1);
+ if (a > 1)
+ return; // no-warning
+ else if (a == 1 || a == 0)
+ free(b);
+ return; // no-warning
+}
+
+void largeAdjustmentLT (unsigned a) {
+ char* b = NULL;
+ if (a+2 < 1)
+ b = malloc(1);
+ if (a == UINT_MAX-1 || a == UINT_MAX)
+ free(b);
+ else if (a < UINT_MAX-1)
+ return; // no-warning
+ return; // no-warning
+}
+
+void largeAdjustmentLE (unsigned a) {
+ char* b = NULL;
+ if (a+2 <= 1)
+ b = malloc(1);
+ if (a < UINT_MAX-1)
+ return; // no-warning
+ else if (a == UINT_MAX-1 || a == UINT_MAX)
+ free(b);
+ return; // no-warning
+}
OpenPOWER on IntegriCloud