comparison gcc/testsuite/gcc.dg/builtin-stringop-chk-5.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 04ced10e8804
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Test exercising -Wrawmem-overflow and -Wstringop-overflow warnings. */ 1 /* Test exercising -Wstringop-overflow warnings. */
2 /* { dg-do compile } */ 2 /* { dg-do compile } */
3 /* { dg-options "-O2 -Wstringop-overflow=1" } */ 3 /* { dg-options "-O2 -Wstringop-overflow=1" } */
4 4
5 #define offsetof(type, mem) __builtin_offsetof (type, mem) 5 #define offsetof(type, mem) __builtin_offsetof (type, mem)
6 6
47 struct A a[2]; 47 struct A a[2];
48 48
49 memcpy (a, src, n); /* { dg-warning "writing between 8 and 32 bytes into a region of size 4 overflows the destination" } */ 49 memcpy (a, src, n); /* { dg-warning "writing between 8 and 32 bytes into a region of size 4 overflows the destination" } */
50 escape (a, src); 50 escape (a, src);
51 51
52 /* At -Wrawmem-overflow=1 the destination is considered to be 52 /* At -Wstringop-overflow=1 the destination is considered to be
53 the whole array and its size is therefore sizeof a. */ 53 the whole array and its size is therefore sizeof a. */
54 memcpy (&a[0], src, n); /* { dg-warning "writing between 8 and 32 bytes into a region of size 4 overflows the destination" } */ 54 memcpy (&a[0], src, n); /* { dg-warning "writing between 8 and 32 bytes into a region of size 4 overflows the destination" } */
55 escape (a, src); 55 escape (a, src);
56 56
57 /* Verify the same as above but by writing into the first mmeber 57 /* Verify the same as above but by writing into the first mmeber
108 108
109 n = range (8, 32); 109 n = range (8, 32);
110 110
111 struct A *a = __builtin_malloc (sizeof *a * 2); 111 struct A *a = __builtin_malloc (sizeof *a * 2);
112 112
113 memcpy (a, src, n); /* { dg-warning "writing between 8 and 32 bytes into a region of size 4 overflows the destination" "memcpy into allocated" { xfail *-*-*} } */ 113 memcpy (a, src, n); /* { dg-warning "writing between 8 and 32 bytes into a region of size 4 " "memcpy into allocated" } */
114 escape (a, src); 114 escape (a, src);
115 115
116 /* At -Wrawmem-overflow=1 the destination is considered to be 116 /* At -Wstringop-overflow=1 the destination is considered to be
117 the whole array and its size is therefore sizeof a. */ 117 the whole array and its size is therefore sizeof a. */
118 memcpy (&a[0], src, n); /* { dg-warning "writing between 8 and 32 bytes into a region of size 4 overflows the destination" "memcpy into allocated" { xfail *-*-*} } */ 118 memcpy (&a[0], src, n); /* { dg-warning "writing between 8 and 32 bytes into a region of size 4 overflows the destination" "memcpy into allocated" } */
119 escape (a, src); 119 escape (a, src);
120 120
121 /* Verify the same as above but by writing into the first mmeber 121 /* Verify the same as above but by writing into the first mmeber
122 of the first element of the array. */ 122 of the first element of the array. */
123 memcpy (&a[0].a, src, n); /* { dg-warning "writing between 8 and 32 bytes into a region of size 4 overflows the destination" "memcpy into allocated" { xfail *-*-*} } */ 123 memcpy (&a[0].a, src, n); /* { dg-warning "writing between 8 and 32 bytes into a region of size 4 overflows the destination" "memcpy into allocated" { xfail *-*-*} } */
125 125
126 n = range (12, 32); 126 n = range (12, 32);
127 127
128 struct B *b = __builtin_malloc (sizeof *b * 2); 128 struct B *b = __builtin_malloc (sizeof *b * 2);
129 129
130 memcpy (&b[0], src, n); /* { dg-warning "writing between 12 and 32 bytes into a region of size 8 overflows the destination" "memcpy into allocated" { xfail *-*-*} } */ 130 memcpy (&b[0], src, n); /* { dg-warning "writing between 12 and 32 bytes into a region of size 8 " "memcpy into allocated" } */
131 escape (b); 131 escape (b);
132 132
133 /* The following idiom of clearing multiple members of a struct is 133 /* The following idiom of clearing multiple members of a struct is
134 used in a few places in the Linux kernel. Verify that a warning 134 used in a few places in the Linux kernel. Verify that a warning
135 is issued for it when it writes past the end of the array object. */ 135 is issued for it when it writes past the end of the array object. */