blob: 78c76e7e4c273b40f681f090622e8b954f0f2608 [file] [log] [blame]
// RUN: %clang_cc1 -fsyntax-only -fblocks -Wnull-arithmetic -verify %s
#include <stddef.h>
void f() {
int a;
bool b;
a = 0 ? NULL + a : a + NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
a = 0 ? NULL - a : a - NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
a = 0 ? NULL / a : a / NULL; // expected-warning 2{{use of NULL in arithmetic operation}} \
// expected-warning {{division by zero is undefined}}
a = 0 ? NULL * a : a * NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
a = 0 ? NULL >> a : a >> NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
a = 0 ? NULL << a : a << NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
a = 0 ? NULL % a : a % NULL; // expected-warning 2{{use of NULL in arithmetic operation}} \
expected-warning {{remainder by zero is undefined}}
a = 0 ? NULL & a : a & NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
a = 0 ? NULL | a : a | NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
a = 0 ? NULL ^ a : a ^ NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
// Using two NULLs should only give one error instead of two.
a = NULL + NULL; // expected-warning{{use of NULL in arithmetic operation}}
a = NULL - NULL; // expected-warning{{use of NULL in arithmetic operation}}
a = NULL / NULL; // expected-warning{{use of NULL in arithmetic operation}} \
// expected-warning{{division by zero is undefined}}
a = NULL * NULL; // expected-warning{{use of NULL in arithmetic operation}}
a = NULL >> NULL; // expected-warning{{use of NULL in arithmetic operation}}
a = NULL << NULL; // expected-warning{{use of NULL in arithmetic operation}}
a = NULL % NULL; // expected-warning{{use of NULL in arithmetic operation}} \
// expected-warning{{remainder by zero is undefined}}
a = NULL & NULL; // expected-warning{{use of NULL in arithmetic operation}}
a = NULL | NULL; // expected-warning{{use of NULL in arithmetic operation}}
a = NULL ^ NULL; // expected-warning{{use of NULL in arithmetic operation}}
a += NULL; // expected-warning{{use of NULL in arithmetic operation}}
a -= NULL; // expected-warning{{use of NULL in arithmetic operation}}
a /= NULL; // expected-warning{{use of NULL in arithmetic operation}} \
// expected-warning{{division by zero is undefined}}
a *= NULL; // expected-warning{{use of NULL in arithmetic operation}}
a >>= NULL; // expected-warning{{use of NULL in arithmetic operation}}
a <<= NULL; // expected-warning{{use of NULL in arithmetic operation}}
a %= NULL; // expected-warning{{use of NULL in arithmetic operation}} \
// expected-warning{{remainder by zero is undefined}}
a &= NULL; // expected-warning{{use of NULL in arithmetic operation}}
a |= NULL; // expected-warning{{use of NULL in arithmetic operation}}
a ^= NULL; // expected-warning{{use of NULL in arithmetic operation}}
b = a < NULL || NULL < a; // expected-warning 2{{use of NULL in arithmetic operation}}
b = a > NULL || NULL > a; // expected-warning 2{{use of NULL in arithmetic operation}}
b = a <= NULL || NULL <= a; // expected-warning 2{{use of NULL in arithmetic operation}}
b = a >= NULL || NULL >= a; // expected-warning 2{{use of NULL in arithmetic operation}}
b = a == NULL || NULL == a; // expected-warning 2{{use of NULL in arithmetic operation}}
b = a != NULL || NULL != a; // expected-warning 2{{use of NULL in arithmetic operation}}
b = &a < NULL || NULL < &a || &a > NULL || NULL > &a;
b = &a <= NULL || NULL <= &a || &a >= NULL || NULL >= &a;
b = &a == NULL || NULL == &a || &a != NULL || NULL != &a;
b = 0 == a;
b = 0 == &a;
b = NULL < NULL || NULL > NULL;
b = NULL <= NULL || NULL >= NULL;
b = NULL == NULL || NULL != NULL;
b = ((NULL)) != a; // expected-warning{{use of NULL in arithmetic operation}}
void (^c)();
b = c == NULL || NULL == c || c != NULL || NULL != c;
class X;
void (X::*d) ();
b = d == NULL || NULL == d || d != NULL || NULL != d;
extern void e();
b = e == NULL || NULL == e || e != NULL || NULL != e;
int f[2];
b = f == NULL || NULL == f || f != NULL || NULL != f;
b = "f" == NULL || NULL == "f" || "f" != NULL || NULL != "f";
}