File: memcmp-5.c

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (72 lines) | stat: -rw-r--r-- 3,013 bytes parent folder | download | duplicates (2)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* PR middle-end/78257 - missing memcmp optimization with constant arrays
   { dg-do compile }
   { dg-options "-O -Wall -fdump-tree-optimized" } */

#define A "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" \
          "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" \
          "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" \
          "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" \
          "0"

const char a257[sizeof A - 1] = A;
const char a258[sizeof A] = A;

_Static_assert (sizeof A == 258);
_Static_assert (sizeof a257 == 257);

/* Verify that initializers longer than 256 characters (an internal limit
   on the size of a buffer used to store representations in) are handled.  */

void eq_256plus (void)
{
  int n = 0;

  n += __builtin_memcmp (a257,       A,       sizeof a257);
  n += __builtin_memcmp (a257 +   1, A +   1, sizeof a257 - 1);
  n += __builtin_memcmp (a257 +   2, A +   2, sizeof a257 - 2);
  n += __builtin_memcmp (a257 + 127, A + 127, sizeof a257 - 127);
  n += __builtin_memcmp (a257 + 128, A + 128, sizeof a257 - 128);
  n += __builtin_memcmp (a257 + 255, A + 255, 2);
  n += __builtin_memcmp (a257 + 256, A + 256, 1);

  n += __builtin_memcmp (a258,       A,       sizeof a257);
  n += __builtin_memcmp (a258 +   1, A +   1, sizeof a257 - 1);
  n += __builtin_memcmp (a258 +   2, A +   2, sizeof a257 - 2);
  n += __builtin_memcmp (a258 + 127, A + 127, sizeof a257 - 127);
  n += __builtin_memcmp (a258 + 128, A + 128, sizeof a257 - 128);
  n += __builtin_memcmp (a258 + 256, A + 256, 2);
  n += __builtin_memcmp (a258 + 257, A + 257, 1);

  if (n)
    __builtin_abort ();
}

#define X "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" \
          "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" \
          "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" \
          "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" \
          "1"

void lt_256plus (void)
{
  int n = 0;

  n += 0 >  __builtin_memcmp (a257,       X,       sizeof a257);
  n += 0 >  __builtin_memcmp (a257 +   1, X +   1, sizeof a257 - 1);
  n += 0 >  __builtin_memcmp (a257 +   2, X +   2, sizeof a257 - 2);
  n += 0 >  __builtin_memcmp (a257 + 127, X + 127, sizeof a257 - 127);
  n += 0 >  __builtin_memcmp (a257 + 128, X + 128, sizeof a257 - 128);
  n += 0 >  __builtin_memcmp (a257 + 255, X + 255, 2);
  n += 0 >  __builtin_memcmp (a257 + 256, X + 256, 1);

  n += 0 >  __builtin_memcmp (a258,       X,       sizeof a258);
  n += 0 >  __builtin_memcmp (a258 +   1, X +   1, sizeof a258 - 1);
  n += 0 >  __builtin_memcmp (a258 +   2, X +   2, sizeof a258 - 2);
  n += 0 >  __builtin_memcmp (a258 + 127, X + 127, sizeof a257 - 127);
  n += 0 >  __builtin_memcmp (a258 + 128, X + 128, sizeof a257 - 128);
  n += 0 >  __builtin_memcmp (a258 + 256, X + 256, 2);
  n += 0 == __builtin_memcmp (a258 + 257, X + 257, 1);

  if (n != 14)
    __builtin_abort ();
}