Chandler Carruth | 7ccc95b | 2011-04-27 07:05:31 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 | |
| 3 | extern void *memset(void *, int, unsigned); |
| 4 | |
| 5 | // Several POD types that should not warn. |
| 6 | struct S1 {} s1; |
| 7 | struct S2 { int x; } s2; |
| 8 | struct S3 { float x, y; S1 s[4]; void (*f)(S1**); } s3; |
| 9 | |
| 10 | // Non-POD types that should warn. |
| 11 | struct X1 { X1(); } x1; |
| 12 | struct X2 { ~X2(); } x2; |
| 13 | struct X3 { virtual void f(); } x3; |
| 14 | struct X4 : X2 {} x4; |
| 15 | struct X5 : virtual S1 {} x5; |
| 16 | |
| 17 | void 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 Carruth | 134cb44 | 2011-04-27 18:48:59 +0000 | [diff] [blame^] | 35 | void 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 Carruth | 7ccc95b | 2011-04-27 07:05:31 +0000 | [diff] [blame] | 45 | 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 | } |