1// RUN: %clang_cc1 -fsyntax-only -verify %s
2//
3
4typedef __SIZE_TYPE__ size_t;
5extern "C" void *memset(void *, int, size_t);
6extern "C" void *memmove(void *s1, const void *s2, size_t n);
7extern "C" void *memcpy(void *s1, const void *s2, size_t n);
8extern "C" void *memcmp(void *s1, const void *s2, size_t n);
9extern "C" int strncmp(const char *s1, const char *s2, size_t n);
10extern "C" int strncasecmp(const char *s1, const char *s2, size_t n);
11extern "C" char *strncpy(char *dst, const char *src, size_t n);
12extern "C" char *strncat(char *dst, const char *src, size_t n);
13extern "C" char *strndup(const  char *src, size_t n);
14extern "C" size_t strlcpy(char *dst, const char *src, size_t size);
15extern "C" size_t strlcat(char *dst, const char *src, size_t size);
16
17void f() {
18  char b1[80], b2[80];
19  if (memset(b1, 0, sizeof(b1) != 0)) {} // \
20    expected-warning{{size argument in 'memset' call is a comparison}} \
21    expected-note {{did you mean to compare}} \
22    expected-note {{explicitly cast the argument}}
23  if (memset(b1, 0, sizeof(b1)) != 0) {}
24
25  if (memmove(b1, b2, sizeof(b1) == 0)) {} // \
26    expected-warning{{size argument in 'memmove' call is a comparison}} \
27    expected-note {{did you mean to compare}} \
28    expected-note {{explicitly cast the argument}}
29  if (memmove(b1, b2, sizeof(b1)) == 0) {}
30
31  if (memcpy(b1, b2, sizeof(b1) < 0)) {} // \
32    expected-warning{{size argument in 'memcpy' call is a comparison}} \
33    expected-note {{did you mean to compare}} \
34    expected-note {{explicitly cast the argument}}
35  if (memcpy(b1, b2, sizeof(b1)) < 0) {}
36
37  if (memcmp(b1, b2, sizeof(b1) <= 0)) {} // \
38    expected-warning{{size argument in 'memcmp' call is a comparison}} \
39    expected-note {{did you mean to compare}} \
40    expected-note {{explicitly cast the argument}}
41  if (memcmp(b1, b2, sizeof(b1)) <= 0) {}
42
43  if (strncmp(b1, b2, sizeof(b1) > 0)) {} // \
44    expected-warning{{size argument in 'strncmp' call is a comparison}} \
45    expected-note {{did you mean to compare}} \
46    expected-note {{explicitly cast the argument}}
47  if (strncmp(b1, b2, sizeof(b1)) > 0) {}
48
49  if (strncasecmp(b1, b2, sizeof(b1) >= 0)) {} // \
50    expected-warning{{size argument in 'strncasecmp' call is a comparison}} \
51    expected-note {{did you mean to compare}} \
52    expected-note {{explicitly cast the argument}}
53  if (strncasecmp(b1, b2, sizeof(b1)) >= 0) {}
54
55  if (strncpy(b1, b2, sizeof(b1) == 0 || true)) {} // \
56    expected-warning{{size argument in 'strncpy' call is a comparison}} \
57    expected-note {{did you mean to compare}} \
58    expected-note {{explicitly cast the argument}}
59  if (strncpy(b1, b2, sizeof(b1)) == 0 || true) {}
60
61  if (strncat(b1, b2, sizeof(b1) - 1 >= 0 && true)) {} // \
62    expected-warning{{size argument in 'strncat' call is a comparison}} \
63    expected-note {{did you mean to compare}} \
64    expected-note {{explicitly cast the argument}}
65  if (strncat(b1, b2, sizeof(b1) - 1) >= 0 && true) {}
66
67  if (strndup(b1, sizeof(b1) != 0)) {} // \
68    expected-warning{{size argument in 'strndup' call is a comparison}} \
69    expected-note {{did you mean to compare}} \
70    expected-note {{explicitly cast the argument}}
71  if (strndup(b1, sizeof(b1)) != 0) {}
72
73  if (strlcpy(b1, b2, sizeof(b1) != 0)) {} // \
74    expected-warning{{size argument in 'strlcpy' call is a comparison}} \
75    expected-note {{did you mean to compare}} \
76    expected-note {{explicitly cast the argument}}
77  if (strlcpy(b1, b2, sizeof(b1)) != 0) {}
78
79  if (strlcat(b1, b2, sizeof(b1) != 0)) {} // \
80    expected-warning{{size argument in 'strlcat' call is a comparison}} \
81    expected-note {{did you mean to compare}} \
82    expected-note {{explicitly cast the argument}}
83  if (strlcat(b1, b2, sizeof(b1)) != 0) {}
84
85  if (memset(b1, 0, sizeof(b1) / 2)) {}
86  if (memset(b1, 0, sizeof(b1) >> 2)) {}
87  if (memset(b1, 0, 4 << 2)) {}
88  if (memset(b1, 0, 4 + 2)) {}
89  if (memset(b1, 0, 4 - 2)) {}
90  if (memset(b1, 0, 4 * 2)) {}
91
92  if (memset(b1, 0, (size_t)(sizeof(b1) != 0))) {}
93}
94