blob: 78c76e7e4c273b40f681f090622e8b954f0f2608 [file] [log] [blame]
Richard Trieu4e938df2011-06-17 20:35:48 +00001// RUN: %clang_cc1 -fsyntax-only -fblocks -Wnull-arithmetic -verify %s
Richard Trieu3e95ba92011-06-16 21:36:56 +00002#include <stddef.h>
3
4void f() {
5 int a;
6 bool b;
7
8 a = 0 ? NULL + a : a + NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
9 a = 0 ? NULL - a : a - NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
10 a = 0 ? NULL / a : a / NULL; // expected-warning 2{{use of NULL in arithmetic operation}} \
11 // expected-warning {{division by zero is undefined}}
12 a = 0 ? NULL * a : a * NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
13 a = 0 ? NULL >> a : a >> NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
14 a = 0 ? NULL << a : a << NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
15 a = 0 ? NULL % a : a % NULL; // expected-warning 2{{use of NULL in arithmetic operation}} \
16 expected-warning {{remainder by zero is undefined}}
17 a = 0 ? NULL & a : a & NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
18 a = 0 ? NULL | a : a | NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
19 a = 0 ? NULL ^ a : a ^ NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
20
21 // Using two NULLs should only give one error instead of two.
22 a = NULL + NULL; // expected-warning{{use of NULL in arithmetic operation}}
23 a = NULL - NULL; // expected-warning{{use of NULL in arithmetic operation}}
24 a = NULL / NULL; // expected-warning{{use of NULL in arithmetic operation}} \
25 // expected-warning{{division by zero is undefined}}
26 a = NULL * NULL; // expected-warning{{use of NULL in arithmetic operation}}
27 a = NULL >> NULL; // expected-warning{{use of NULL in arithmetic operation}}
28 a = NULL << NULL; // expected-warning{{use of NULL in arithmetic operation}}
29 a = NULL % NULL; // expected-warning{{use of NULL in arithmetic operation}} \
30 // expected-warning{{remainder by zero is undefined}}
31 a = NULL & NULL; // expected-warning{{use of NULL in arithmetic operation}}
32 a = NULL | NULL; // expected-warning{{use of NULL in arithmetic operation}}
33 a = NULL ^ NULL; // expected-warning{{use of NULL in arithmetic operation}}
34
35 a += NULL; // expected-warning{{use of NULL in arithmetic operation}}
36 a -= NULL; // expected-warning{{use of NULL in arithmetic operation}}
37 a /= NULL; // expected-warning{{use of NULL in arithmetic operation}} \
38 // expected-warning{{division by zero is undefined}}
39 a *= NULL; // expected-warning{{use of NULL in arithmetic operation}}
40 a >>= NULL; // expected-warning{{use of NULL in arithmetic operation}}
41 a <<= NULL; // expected-warning{{use of NULL in arithmetic operation}}
42 a %= NULL; // expected-warning{{use of NULL in arithmetic operation}} \
43 // expected-warning{{remainder by zero is undefined}}
44 a &= NULL; // expected-warning{{use of NULL in arithmetic operation}}
45 a |= NULL; // expected-warning{{use of NULL in arithmetic operation}}
46 a ^= NULL; // expected-warning{{use of NULL in arithmetic operation}}
47
48 b = a < NULL || NULL < a; // expected-warning 2{{use of NULL in arithmetic operation}}
49 b = a > NULL || NULL > a; // expected-warning 2{{use of NULL in arithmetic operation}}
50 b = a <= NULL || NULL <= a; // expected-warning 2{{use of NULL in arithmetic operation}}
51 b = a >= NULL || NULL >= a; // expected-warning 2{{use of NULL in arithmetic operation}}
52 b = a == NULL || NULL == a; // expected-warning 2{{use of NULL in arithmetic operation}}
53 b = a != NULL || NULL != a; // expected-warning 2{{use of NULL in arithmetic operation}}
54
55 b = &a < NULL || NULL < &a || &a > NULL || NULL > &a;
56 b = &a <= NULL || NULL <= &a || &a >= NULL || NULL >= &a;
57 b = &a == NULL || NULL == &a || &a != NULL || NULL != &a;
58
59 b = 0 == a;
60 b = 0 == &a;
61
Chandler Carruth2af68e42011-06-19 09:05:14 +000062 b = NULL < NULL || NULL > NULL;
63 b = NULL <= NULL || NULL >= NULL;
64 b = NULL == NULL || NULL != NULL;
65
Richard Trieu3e95ba92011-06-16 21:36:56 +000066 b = ((NULL)) != a; // expected-warning{{use of NULL in arithmetic operation}}
67
68 void (^c)();
69 b = c == NULL || NULL == c || c != NULL || NULL != c;
70
71 class X;
72 void (X::*d) ();
73 b = d == NULL || NULL == d || d != NULL || NULL != d;
Chandler Carruth2af68e42011-06-19 09:05:14 +000074
75 extern void e();
76 b = e == NULL || NULL == e || e != NULL || NULL != e;
77
78 int f[2];
79 b = f == NULL || NULL == f || f != NULL || NULL != f;
80 b = "f" == NULL || NULL == "f" || "f" != NULL || NULL != "f";
Richard Trieu3e95ba92011-06-16 21:36:56 +000081}