1 /* Verify that strncmp equalities aren't eliminated when the trailing array
2 type referenced by a member pointer is smaller than the string in cases
3 when the pointer pointed to by the enclosing object references an object
4 sufficiently large to store a string of equal length.
6 { dg-options "-O2 -Wall -Wextra -Wno-stringop-overread -fdump-tree-optimized" } */
10 struct A1
{ char i
, a
[1]; };
17 struct A1
*p
= (struct A1
*)a
;
19 if (__builtin_strncmp (p
->a
, "01234567", 8) == 0)
21 extern void array_test (void);
31 struct A1
*q
= (struct A1
*)p
;
33 if (__builtin_strncmp (q
->a
, "0123456789", 10) == 0)
35 extern void pointer_test (void);
42 struct { char a
[9]; } b
;
45 struct A1
*p
= (struct A1
*)&b
;
47 if (__builtin_strncmp (p
->a
, "01234567", 8) == 0)
49 extern void struct_test (void);
56 struct { void *p
; } b
;
59 struct A1
*p
= (struct A1
*)b
.p
;
61 if (__builtin_strncmp (p
->a
, "0123456789", 10) == 0)
63 extern void memptr_test (void);
69 struct A2
{ char i
, a
[2]; };
76 struct A2
*p
= (struct A2
*)a
;
78 if (__builtin_strncmp (p
->a
, "0123456", 7) == 0)
80 extern void array_test (void);
90 struct A2
*q
= (struct A2
*)p
;
92 if (__builtin_strncmp (q
->a
, "0123456789", 10) == 0)
94 extern void pointer_test (void);
101 struct { char a
[8]; } b
;
104 struct A2
*p
= (struct A2
*)&b
;
106 if (__builtin_strncmp (p
->a
, "0123456", 7) == 0)
108 extern void struct_test (void);
113 void f2_memptr (void)
115 struct { void *p
; } b
;
118 struct A2
*p
= (struct A2
*)b
.p
;
120 if (__builtin_strncmp (p
->a
, "0123456789", 10) == 0)
122 extern void memptr_test (void);
127 /* { dg-final { scan-tree-dump-times "array_test" 2 "optimized" } }
128 { dg-final { scan-tree-dump-times "pointer_test" 2 "optimized" } }
129 { dg-final { scan-tree-dump-times "struct_test" 2 "optimized" } }
130 { dg-final { scan-tree-dump-times "memptr_test" 2 "optimized" } } */