Tom Care | db2fa8a | 2010-07-06 21:43:29 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -Wunused-variable -analyze -analyzer-idempotent-operation -analyzer-store=basic -analyzer-constraints=range |
| 2 | |
| 3 | // Basic tests |
| 4 | |
| 5 | extern void test(int i); |
| 6 | |
| 7 | void basic() { |
| 8 | int x = 10, zero = 0, one = 1; |
| 9 | |
| 10 | // x op x |
| 11 | x = x; // expected-warning {{idempotent operation; both operands are always equal in value}} |
| 12 | test(x - x); // expected-warning {{idempotent operation; both operands are always equal in value}} |
| 13 | x -= x; // expected-warning {{idempotent operation; both operands are always equal in value}} |
| 14 | x = 10; // no-warning |
| 15 | test(x / x); // expected-warning {{idempotent operation; both operands are always equal in value}} |
| 16 | x /= x; // expected-warning {{idempotent operation; both operands are always equal in value}} |
| 17 | x = 10; // no-warning |
| 18 | test(x & x); // expected-warning {{idempotent operation; both operands are always equal in value}} |
| 19 | x &= x; // expected-warning {{idempotent operation; both operands are always equal in value}} |
| 20 | test(x | x); // expected-warning {{idempotent operation; both operands are always equal in value}} |
| 21 | x |= x; // expected-warning {{idempotent operation; both operands are always equal in value}} |
| 22 | |
| 23 | // x op 1 |
| 24 | test(x * one); // expected-warning {{idempotent operation; the right operand is always 1}} |
| 25 | x *= one; // expected-warning {{idempotent operation; the right operand is always 1}} |
| 26 | test(x / one); // expected-warning {{idempotent operation; the right operand is always 1}} |
| 27 | x /= one; // expected-warning {{idempotent operation; the right operand is always 1}} |
| 28 | |
| 29 | // 1 op x |
| 30 | test(one * x); // expected-warning {{idempotent operation; the left operand is always 1}} |
| 31 | |
| 32 | // x op 0 |
| 33 | test(x + zero); // expected-warning {{idempotent operation; the right operand is always 0}} |
| 34 | test(x - zero); // expected-warning {{idempotent operation; the right operand is always 0}} |
| 35 | test(x * zero); // expected-warning {{idempotent operation; the right operand is always 0}} |
| 36 | test(x & zero); // expected-warning {{idempotent operation; the right operand is always 0}} |
| 37 | test(x | zero); // expected-warning {{idempotent operation; the right operand is always 0}} |
| 38 | test(x ^ zero); // expected-warning {{idempotent operation; the right operand is always 0}} |
| 39 | test(x << zero); // expected-warning {{idempotent operation; the right operand is always 0}} |
| 40 | test(x >> zero); // expected-warning {{idempotent operation; the right operand is always 0}} |
| 41 | |
| 42 | // 0 op x |
| 43 | test(zero + x); // expected-warning {{idempotent operation; the left operand is always 0}} |
| 44 | test(zero - x); // expected-warning {{idempotent operation; the left operand is always 0}} |
| 45 | test(zero / x); // expected-warning {{idempotent operation; the left operand is always 0}} |
| 46 | test(zero * x); // expected-warning {{idempotent operation; the left operand is always 0}} |
| 47 | test(zero & x); // expected-warning {{idempotent operation; the left operand is always 0}} |
| 48 | test(zero | x); // expected-warning {{idempotent operation; the left operand is always 0}} |
| 49 | test(zero ^ x); // expected-warning {{idempotent operation; the left operand is always 0}} |
| 50 | test(zero << x); // expected-warning {{idempotent operation; the left operand is always 0}} |
| 51 | test(zero >> x); // expected-warning {{idempotent operation; the left operand is always 0}} |
| 52 | } |