summaryrefslogtreecommitdiffstats
path: root/test/Sema/tautological-unsigned-zero-compare.c
blob: 039d8f885e81a8cefb22ffeeea831495ac0156b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// RUN: %clang_cc1 -fsyntax-only -DTEST -verify %s
// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare -verify %s

unsigned value(void);

int main() {
  unsigned un = value();

#ifdef TEST
  if (un < 0) // expected-warning {{comparison of unsigned expression < 0 is always false}}
    return 0;
  if (un >= 0) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
    return 0;
  if (0 <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
    return 0;
  if (0 > un) // expected-warning {{comparison of 0 > unsigned expression is always false}}
    return 0;
  if (un < 0U) // expected-warning {{comparison of unsigned expression < 0 is always false}}
    return 0;
  if (un >= 0U) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
    return 0;
  if (0U <= un) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
    return 0;
  if (0U > un) // expected-warning {{comparison of 0 > unsigned expression is always false}}
    return 0;
#else
// expected-no-diagnostics
  if (un < 0)
    return 0;
  if (un >= 0)
    return 0;
  if (0 <= un)
    return 0;
  if (0 > un)
    return 0;
  if (un < 0U)
    return 0;
  if (un >= 0U)
    return 0;
  if (0U <= un)
    return 0;
  if (0U > un)
    return 0;
#endif

  return 1;
}