|
| 1 | +/* Test to exercise attribute "nonstring". |
| 2 | + { dg-do compile } |
| 3 | + { dg-options "-O2 -Wattributes -Wstringop-truncation -ftrack-macro-expansion=0" } */ |
| 4 | + |
| 5 | +#define ATTR(list) __attribute__ (list) |
| 6 | +#define NONSTR ATTR ((nonstring)) |
| 7 | +#define strncpy(d, s, n) (__builtin_strncpy ((d), (s), (n)), sink (d)) |
| 8 | + |
| 9 | +void sink (void*); |
| 10 | + |
| 11 | +/* Global string with an known bound. */ |
| 12 | +extern char gns3[][3] NONSTR; |
| 13 | + |
| 14 | +/* Global non-string pointers. */ |
| 15 | +extern NONSTR char (*pns_1)[1]; |
| 16 | +extern char (* NONSTR pns_2)[2]; |
| 17 | +extern char (*pns_3)[3] NONSTR; |
| 18 | + |
| 19 | +struct MemArrays |
| 20 | +{ |
| 21 | + NONSTR char ma3[2][3]; |
| 22 | + char NONSTR ma4[3][4]; |
| 23 | + char ma5[4][5] NONSTR; |
| 24 | +}; |
| 25 | + |
| 26 | + |
| 27 | +void test_array (const char *s, unsigned n) |
| 28 | +{ |
| 29 | + const char s7[] = "1234567"; |
| 30 | + |
| 31 | + strncpy (gns3[2], "", 0); |
| 32 | + strncpy (gns3[2], "a", 1); |
| 33 | + strncpy (gns3[2], "a", 2); |
| 34 | + strncpy (gns3[2], "a", 3); |
| 35 | + strncpy (gns3[2], "ab", 3); |
| 36 | + strncpy (gns3[2], "abc", 3); |
| 37 | +} |
| 38 | + |
| 39 | + |
| 40 | +void test_pointer (const char *s, unsigned n) |
| 41 | +{ |
| 42 | + const char s7[] = "1234567"; |
| 43 | + |
| 44 | + strncpy (*pns_1, "a", 1); |
| 45 | + strncpy (*pns_2, "ab", 2); |
| 46 | + strncpy (*pns_3, "abc", 3); |
| 47 | + strncpy (*pns_3, s7, 3); |
| 48 | + |
| 49 | + strncpy (*pns_1, s, 1); |
| 50 | + strncpy (*pns_2, s, 1); |
| 51 | + strncpy (*pns_3, s, 1); |
| 52 | + |
| 53 | + strncpy (*pns_1, s, n); |
| 54 | + strncpy (*pns_2, s, n); |
| 55 | + strncpy (*pns_3, s, n); |
| 56 | +} |
| 57 | + |
| 58 | + |
| 59 | +void test_member_array (struct MemArrays *p, const char *s, unsigned n) |
| 60 | +{ |
| 61 | + const char s7[] = "1234567"; |
| 62 | + |
| 63 | + strncpy (p->ma3[1], "", 0); |
| 64 | + strncpy (p->ma3[1], "a", 1); |
| 65 | + strncpy (p->ma4[2], "ab", 2); |
| 66 | + strncpy (p->ma5[3], "abc", 3); |
| 67 | + |
| 68 | + strncpy (p->ma3[1], s, 1); |
| 69 | + strncpy (p->ma4[2], s, 1); |
| 70 | + strncpy (p->ma5[3], s, 1); |
| 71 | + |
| 72 | + strncpy (p->ma3[1], s7, n); |
| 73 | + strncpy (p->ma4[2], s7, n); |
| 74 | + strncpy (p->ma5[3], s7, n); |
| 75 | +} |
0 commit comments