Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/gcc.dg/Wstringop-truncation-8.c @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 /* PR tree-optimization/89644 - False-positive -Warray-bounds diagnostic | |
2 on strncpy | |
3 { dg-do compile } | |
4 { dg-options "-O2 -Wall -ftrack-macro-expansion=0" } */ | |
5 | |
6 #define NONSTR __attribute__ ((nonstring)) | |
7 | |
8 typedef __SIZE_TYPE__ size_t; | |
9 | |
10 size_t strlen (const char*); | |
11 extern char* stpncpy (char*, const char*, size_t); | |
12 extern char* strncpy (char*, const char*, size_t); | |
13 | |
14 void sink (char*, ...); | |
15 | |
16 char f0 (char *s) | |
17 { | |
18 char a[6] NONSTR = { 1, 2, 3, 4, 5, 6 }; | |
19 if (*s) | |
20 strncpy (a, s, sizeof a); /* { dg-bogus "\\\[-Warray-bounds" } */ | |
21 return a[0]; | |
22 } | |
23 | |
24 void f1 (char *s) | |
25 { | |
26 char a[6] NONSTR = { 1, 2, 3, 4, 5, 6 }; | |
27 if (*s) | |
28 strncpy (a, s, sizeof a); /* { dg-bogus "\\\[-Warray-bounds" } */ | |
29 sink (a); | |
30 } | |
31 | |
32 char f2 (void) | |
33 { | |
34 char a[6] NONSTR = { 1, 2, 3, 4, 5, 6 }; | |
35 char b[6] NONSTR = { 6, 5, 4, 3, 2, 1 }; | |
36 strncpy (a, b + 1, 5); /* { dg-bogus "\\\[-Warray-bounds" } */ | |
37 return a[0]; | |
38 } | |
39 | |
40 void f3 (void) | |
41 { | |
42 char a[6] NONSTR = { 1, 2, 3, 4, 5, 6 }; | |
43 char b[6] NONSTR = { 6, 5, 4, 3, 2, 1 }; | |
44 strncpy (a, b + 2, 4); /* { dg-bogus "\\\[-Warray-bounds" } */ | |
45 sink (a); | |
46 } | |
47 | |
48 void f4 (NONSTR char *d) | |
49 { | |
50 char b[6] NONSTR = { 6, 5, 4, 3, 2, 1 }; | |
51 strncpy (d, b + 3, 3); /* { dg-bogus "\\\[-Warray-bounds" } */ | |
52 sink (d); | |
53 } | |
54 | |
55 | |
56 char g0 (char *s) | |
57 { | |
58 char a[6] NONSTR = { 1, 2, 3, 4, 5, 6 }; | |
59 if (*s) | |
60 stpncpy (a, s, sizeof a); /* { dg-bogus "\\\[-Warray-bounds" } */ | |
61 return a[0]; | |
62 } | |
63 | |
64 void g1 (char *s) | |
65 { | |
66 char a[6] NONSTR = { 1, 2, 3, 4, 5, 6 }; | |
67 char *p = 0; | |
68 if (*s) | |
69 p = stpncpy (a, s, sizeof a); /* { dg-bogus "\\\[-Warray-bounds" } */ | |
70 sink (a, p); | |
71 } | |
72 | |
73 char g2 (void) | |
74 { | |
75 char a[6] NONSTR = { 1, 2, 3, 4, 5, 6 }; | |
76 char b[6] NONSTR = { 6, 5, 4, 3, 2, 1 }; | |
77 stpncpy (a, b + 1, 5); /* { dg-bogus "\\\[-Warray-bounds" } */ | |
78 return a[0]; | |
79 } | |
80 | |
81 void g3 (void) | |
82 { | |
83 char a[6] NONSTR = { 1, 2, 3, 4, 5, 6 }; | |
84 char b[6] NONSTR = { 6, 5, 4, 3, 2, 1 }; | |
85 char *p = stpncpy (a, b + 2, 4); /* { dg-bogus "\\\[-Warray-bounds" } */ | |
86 sink (a, p); | |
87 } | |
88 | |
89 void g4 (NONSTR char *d) | |
90 { | |
91 char b[6] NONSTR = { 6, 5, 4, 3, 2, 1 }; | |
92 char *p = stpncpy (d, b + 3, 3); /* { dg-bogus "\\\[-Warray-bounds" } */ | |
93 sink (d, p); | |
94 } |