[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Sema / transpose-memset.c
blob7d83b8e336a0824af444283c4d09155e26199f54
1 // RUN: %clang_cc1 -Wmemset-transposed-args -verify %s
2 // RUN: %clang_cc1 -xc++ -Wmemset-transposed-args -verify %s
4 #define memset(...) __builtin_memset(__VA_ARGS__)
5 #define bzero(x,y) __builtin_memset(x, 0, y)
6 #define real_bzero(x,y) __builtin_bzero(x,y)
8 int array[10];
9 int *ptr;
11 int main(void) {
12 memset(array, sizeof(array), 0); // expected-warning{{'size' argument to memset is '0'; did you mean to transpose the last two arguments?}} expected-note{{parenthesize the third argument to silence}}
13 memset(array, sizeof(array), 0xff); // expected-warning{{setting buffer to a 'sizeof' expression; did you mean to transpose the last two arguments?}} expected-note{{cast the second argument to 'int' to silence}} expected-warning{{'memset' will always overflow; destination buffer has size 40, but size argument is 255}}
14 memset(array, sizeof(array), '\0'); // expected-warning{{'size' argument to memset is '0'; did you mean to transpose the last two arguments?}} expected-note{{parenthesize the third argument to silence}}
15 memset(ptr, sizeof(ptr), 0); // expected-warning{{'size' argument to memset is '0'; did you mean to transpose the last two arguments?}} expected-note{{parenthesize the third argument to silence}}
16 memset(ptr, sizeof(*ptr) * 10, 1); // expected-warning{{setting buffer to a 'sizeof' expression; did you mean to transpose the last two arguments?}} expected-note{{cast the second argument to 'int' to silence}}
17 memset(ptr, sizeof(ptr), '\0'); // expected-warning{{'size' argument to memset is '0'; did you mean to transpose the last two arguments?}} expected-note{{parenthesize the third argument to silence}}
18 memset(ptr, 10 * sizeof(int *), 1); // expected-warning{{setting buffer to a 'sizeof' expression; did you mean to transpose the last two arguments?}} expected-note{{cast the second argument to 'int' to silence}}
19 memset(ptr, 10 * sizeof(int *) + 10, 0xff); // expected-warning{{setting buffer to a 'sizeof' expression; did you mean to transpose the last two arguments?}} expected-note{{cast the second argument to 'int' to silence}}
20 memset(ptr, sizeof(char) * sizeof(int *), 0xff); // expected-warning{{setting buffer to a 'sizeof' expression; did you mean to transpose the last two arguments?}} expected-note{{cast the second argument to 'int' to silence}}
21 memset(array, sizeof(array), sizeof(array)); // Uh... fine I guess.
22 memset(array, 0, sizeof(array));
23 memset(ptr, 0, sizeof(int *) * 10);
24 memset(array, (int)sizeof(array), (0)); // no warning
25 memset(array, (int)sizeof(array), 32); // no warning
26 memset(array, 32, (0)); // no warning
27 memset(array, 0, 0); // no warning
29 bzero(ptr, 0); // expected-warning{{'size' argument to bzero is '0'}} expected-note{{parenthesize the second argument to silence}}
30 real_bzero(ptr, 0); // expected-warning{{'size' argument to bzero is '0'}} expected-note{{parenthesize the second argument to silence}}
33 void macros(void) {
34 #define ZERO 0
35 int array[10];
36 memset(array, 0xff, ZERO); // no warning
37 // Still emit a diagnostic for memsetting a sizeof expression:
38 memset(array, sizeof(array), ZERO); // expected-warning{{'sizeof'}} expected-note{{cast}}
39 bzero(array, ZERO); // no warning
40 real_bzero(array, ZERO); // no warning
41 #define NESTED_DONT_DIAG \
42 memset(array, 0xff, ZERO); \
43 real_bzero(array, ZERO);
45 NESTED_DONT_DIAG;
47 #define NESTED_DO_DIAG \
48 memset(array, 0xff, 0); \
49 real_bzero(array, 0)
51 NESTED_DO_DIAG; // expected-warning{{'size' argument to memset}} expected-warning{{'size' argument to bzero}} expected-note2{{parenthesize}}
53 #define FN_MACRO(p) \
54 memset(array, 0xff, p)
56 FN_MACRO(ZERO);
57 FN_MACRO(0); // FIXME: should we diagnose this?
59 __builtin_memset(array, 0, ZERO); // no warning
60 __builtin_bzero(array, ZERO);
61 __builtin_memset(array, 1, 0); // expected-warning{{'size' argument to memset}} // expected-note{{parenthesize}}
62 __builtin_bzero(array, 0); // expected-warning{{'size' argument to bzero}} // expected-note{{parenthesize}}