131
|
1 /* PR tree-optimization/83671 - fix for false positive reported by
|
|
2 -Wstringop-overflow does not work with inlining
|
|
3 Verify that the length the empty string is folded to zero even at -O1
|
|
4 regardless of offset into it.
|
|
5 Also verify that the length of a non-empty string isn't folded given
|
|
6 a variable offset.
|
|
7 { dg-do compile }
|
|
8 { dg-options "-O1 -fdump-tree-optimized" } */
|
|
9
|
|
10 #include "strlenopt.h"
|
|
11
|
|
12 inline unsigned length (const char *s)
|
|
13 {
|
|
14 return __builtin_strlen (s);
|
|
15 }
|
|
16
|
|
17 void check_length_cst (int i)
|
|
18 {
|
|
19 unsigned len = length (&""[i]);
|
|
20
|
|
21 if (len)
|
|
22 __builtin_abort ();
|
|
23 }
|
|
24
|
|
25 void check_length_var (int i)
|
|
26 {
|
|
27 unsigned len = length (&"1"[i]);
|
|
28
|
|
29 if (len != 1)
|
|
30 __builtin_abort ();
|
|
31 }
|
|
32
|
|
33 /* { dg-final { scan-tree-dump-times "abort" 1 "optimized" } }
|
|
34 { dg-final { scan-tree-dump-times "strlen" 1 "optimized" } } */
|