| 1 |
/* PR c/88065 - ICE in -Wsizeof-pointer-memaccess on an invalid strncpy |
| 2 |
PR c/87297 - ICE on strncpy with an undeclared argument |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-Wall -Wsizeof-pointer-memaccess" } */ |
| 5 |
|
| 6 |
typedef __SIZE_TYPE__ size_t; |
| 7 |
|
| 8 |
char* strncpy (char*, const char*, size_t); |
| 9 |
|
| 10 |
struct A { char a[4], b[6]; }; |
| 11 |
|
| 12 |
void test_invalid_dst (struct A *p) |
| 13 |
{ |
| 14 |
strncpy (q->a, p->b, sizeof p->b); /* { dg-error ".q. undeclared|not declared" } */ |
| 15 |
} |
| 16 |
|
| 17 |
void test_invalid_src (struct A *p) |
| 18 |
{ |
| 19 |
strncpy (p->a, q->b, sizeof p->b); /* { dg-error ".q. undeclared|not declared" } */ |
| 20 |
} |
| 21 |
|
| 22 |
void test_invalid_bound (struct A *p) |
| 23 |
{ |
| 24 |
strncpy (p->a, p->b, sizeof q->b); /* { dg-error ".q. undeclared|not declared" } */ |
| 25 |
} |
| 26 |
|
| 27 |
/* Verify the C++ front end doesn't ICE (the verifies that the fix |
| 28 |
for PR c/87297 uses error_operand_p to detect the invalid source |
| 29 |
argument rather than just checking its equality to error_mark_node. */ |
| 30 |
struct B { char a[4]; }; |
| 31 |
|
| 32 |
void test_cxx_invalid_dst (struct B *p, const char *s) |
| 33 |
{ |
| 34 |
struct T x; /* { dg-error "storage size|incomplete type|unused" } */ |
| 35 |
__builtin_strncpy (x, s, sizeof p->a); |
| 36 |
} |