Rebase.
[official-gcc.git] / gcc / testsuite / c-c++-common / asan / strlen-overflow-1.c
blobf58f5540852240c8c1cbb3dd09167c204a8c3921
1 /* { dg-do run } */
2 /* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
3 /* { dg-shouldfail "asan" } */
5 #include <sanitizer/asan_interface.h>
7 char a[2] = "0";
9 #ifdef __cplusplus
10 extern "C"
11 #endif
13 __attribute__((no_sanitize_address, noinline)) __SIZE_TYPE__
14 strlen (const char *p) {
16 __SIZE_TYPE__ n = 0;
17 for (; *p; ++n, ++p);
18 return n;
21 int main () {
22 char *p = &a[0];
23 asm ("" : "+r"(p));
24 __asan_poison_memory_region ((char *)&a[1], 1);
25 return __builtin_strlen (a);
28 /* { dg-output "READ of size 1 at 0x\[0-9a-f\]+ thread T0.*(\n|\r\n|\r)" } */
29 /* { dg-output " #0 0x\[0-9a-f\]+ (in _*main (\[^\n\r]*strlen-overflow-1.c:25|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */
30 /* { dg-output "\[^\n\r]*0x\[0-9a-f\]+ is located 1 bytes inside of global variable" } */