aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/memcmp-6.c
blob: d57352616cfa24cc0ea0ffd28de24f91839dc82e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* PR tree-optimization/96670 - ICE on memchr with an empty initializer
   { dg-do compile }
   { dg-options "-O -Wall -fdump-tree-optimized" } */

struct {
  int i, j;
} const s = { };

const char a[sizeof s] = { };

void memcmp_success_unused (void)
{
  int n = (char *)&s.j - (char *)&s;
  char *p = (char *)&s;
  __builtin_memcmp (p, a, n);
  __builtin_memcmp (a, p, n);
}

void memcmp_success_used (void)
{
  int n = (char *)&s.j - (char *)&s;
  char *p = (char *)&s;
  if (__builtin_memcmp (p, a, n)
      || __builtin_memcmp (a, p, n))
    __builtin_abort ();
}

void memcmp_fail_unused (void)
{
  int n = (char *)&s.j - (char *)&s;
  char *p = (char *)&s;
  __builtin_memcmp (p, a, n);
  __builtin_memcmp (a, p, n);
}

void memcmp_fail_used (void)
{
  int n = (char *)&s.j - (char *)&s;
  char *p = (char *)&s;
  if (__builtin_memcmp (p, a, n)
      || __builtin_memcmp (a, p, n))
    __builtin_abort ();
}

/* { dg-prune-output "\\\[-Wunused-value" }
   { dg-final { scan-tree-dump-not "abort" "optimized" } }
   { dg-final { scan-tree-dump-not "memcmp \\\(" "optimized" } } */