summaryrefslogtreecommitdiffstats
path: root/test/Analysis/idempotent-operations.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/Analysis/idempotent-operations.c')
-rw-r--r--test/Analysis/idempotent-operations.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/test/Analysis/idempotent-operations.c b/test/Analysis/idempotent-operations.c
index 5c9a59d..b47394c 100644
--- a/test/Analysis/idempotent-operations.c
+++ b/test/Analysis/idempotent-operations.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-check-objc-mem -analyzer-check-idempotent-operations -verify %s
+// RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-check-objc-mem -analyzer-checker=core.experimental.IdempotentOps -verify %s
// Basic tests
@@ -187,3 +187,50 @@ int false7() {
return a;
}
+
+// Check truncations do not flag as self-assignments
+void false8() {
+ int a = 10000000;
+ a = (short)a; // no-warning
+ test(a);
+}
+
+// This test case previously flagged a warning at 'b == c' because the
+// analyzer previously allowed 'UnknownVal' as the index for ElementRegions.
+typedef struct RDar8431728_F {
+ int RDar8431728_A;
+ unsigned char *RDar8431728_B;
+ int RDar8431728_E[6];
+} RDar8431728_D;
+static inline int RDar8431728_C(RDar8431728_D * s, int n,
+ unsigned char **RDar8431728_B_ptr) {
+ int xy, wrap, pred, a, b, c;
+
+ xy = s->RDar8431728_E[n];
+ wrap = s->RDar8431728_A;
+
+ a = s->RDar8431728_B[xy - 1];
+ b = s->RDar8431728_B[xy - 1 - wrap];
+ c = s->RDar8431728_B[xy - wrap];
+
+ if (b == c) { // no-warning
+ pred = a;
+ } else {
+ pred = c;
+ }
+
+ *RDar8431728_B_ptr = &s->RDar8431728_B[xy];
+
+ return pred;
+}
+
+// <rdar://problem/8601243> - Don't warn on pointer arithmetic. This
+// is often idiomatic.
+unsigned rdar8601243_aux(unsigned n);
+void rdar8601243() {
+ char arr[100];
+ char *start = arr;
+ start = start + rdar8601243_aux(sizeof(arr) - (arr - start)); // no-warning
+ (void) start;
+}
+
OpenPOWER on IntegriCloud