Debian Codegraph @

gcc/testsuite/g++.dg/warn/Wstringop-overflow-2.C

raw
1 /* PR tree-optimization/89688 - -Wstringop-overflow confused by const 2D
2 array of char
3 { dg-do compile }
4 { dg-options "-Wall -fdump-tree-gimple -fdump-tree-optimized" } */
5
6 extern "C" __SIZE_TYPE__ strlen (const char*);
7
8 const char a2[2] = { '1' };
9
10 void a2_len ()
11 {
12 if (strlen (a2) != 1)
13 __builtin_abort ();
14 }
15
16 const char a2_2[2][3] = { { '1' }, { '1', '2' } };
17
18 void a2_2_len ()
19 {
20 if (strlen (a2_2[0]) != 1) // { dg-bogus "-Wstringop-overflow" }
21 __builtin_abort ();
22
23 if (strlen (a2_2[1]) != 2) // { dg-bogus "-Wstringop-overflow" }
24 __builtin_abort ();
25 }
26
27
28 /* { dg-final { scan-tree-dump-not "abort" "optimized" } }
29 { dg-final { scan-tree-dump-not "strlen" "gimple" } } */