blob: 97bbdc27cc4962c9b28a32552e8a3c970ae9c01c [file] [log] [blame]
Chandler Carruth7ccc95b2011-04-27 07:05:31 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3extern void *memset(void *, int, unsigned);
4
5// Several POD types that should not warn.
6struct S1 {} s1;
7struct S2 { int x; } s2;
8struct S3 { float x, y; S1 s[4]; void (*f)(S1**); } s3;
9
10// Non-POD types that should warn.
11struct X1 { X1(); } x1;
12struct X2 { ~X2(); } x2;
13struct X3 { virtual void f(); } x3;
14struct X4 : X2 {} x4;
15struct X5 : virtual S1 {} x5;
16
17void test_warn() {
18 memset(&x1, 0, sizeof x1); // \
19 // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \
20 // expected-note {{explicitly cast the pointer to silence this warning}}
21 memset(&x2, 0, sizeof x2); // \
22 // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \
23 // expected-note {{explicitly cast the pointer to silence this warning}}
24 memset(&x3, 0, sizeof x3); // \
25 // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \
26 // expected-note {{explicitly cast the pointer to silence this warning}}
27 memset(&x4, 0, sizeof x4); // \
28 // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \
29 // expected-note {{explicitly cast the pointer to silence this warning}}
30 memset(&x5, 0, sizeof x5); // \
31 // expected-warning {{destination for this memset call is a pointer to a non-POD type}} \
32 // expected-note {{explicitly cast the pointer to silence this warning}}
33}
34
Chandler Carruth134cb442011-04-27 18:48:59 +000035void test_nowarn(void *void_ptr) {
36 int i, *iptr;
37 float y;
38 char c;
39
40 memset(&i, 0, sizeof i);
41 memset(&iptr, 0, sizeof iptr);
42 memset(&y, 0, sizeof y);
43 memset(&c, 0, sizeof c);
44 memset(void_ptr, 0, 42);
Chandler Carruth7ccc95b2011-04-27 07:05:31 +000045 memset(&s1, 0, sizeof s1);
46 memset(&s2, 0, sizeof s2);
47 memset(&s3, 0, sizeof s3);
48
49 // Unevaluated code shouldn't warn.
50 (void)sizeof memset(&x1, 0, sizeof x1);
51
52 // Dead code shouldn't warn.
53 if (false) memset(&x1, 0, sizeof x1);
54}