1 /* PR tree-optimization/96670 - ICE on memchr with an empty initializer
2    { dg-do compile }
3    { dg-options "-O -Wall -fdump-tree-optimized" } */
4 
5 struct {
6   int i, j;
7 } const s = { };
8 
9 const char a[sizeof s] = { };
10 
memcmp_success_unused(void)11 void memcmp_success_unused (void)
12 {
13   int n = (char *)&s.j - (char *)&s;
14   char *p = (char *)&s;
15   __builtin_memcmp (p, a, n);
16   __builtin_memcmp (a, p, n);
17 }
18 
memcmp_success_used(void)19 void memcmp_success_used (void)
20 {
21   int n = (char *)&s.j - (char *)&s;
22   char *p = (char *)&s;
23   if (__builtin_memcmp (p, a, n)
24       || __builtin_memcmp (a, p, n))
25     __builtin_abort ();
26 }
27 
memcmp_fail_unused(void)28 void memcmp_fail_unused (void)
29 {
30   int n = (char *)&s.j - (char *)&s;
31   char *p = (char *)&s;
32   __builtin_memcmp (p, a, n);
33   __builtin_memcmp (a, p, n);
34 }
35 
memcmp_fail_used(void)36 void memcmp_fail_used (void)
37 {
38   int n = (char *)&s.j - (char *)&s;
39   char *p = (char *)&s;
40   if (__builtin_memcmp (p, a, n)
41       || __builtin_memcmp (a, p, n))
42     __builtin_abort ();
43 }
44 
45 /* { dg-prune-output "\\\[-Wunused-value" }
46    { dg-final { scan-tree-dump-not "abort" "optimized" } }
47    { dg-final { scan-tree-dump-not "memcmp \\\(" "optimized" } } */
48