summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-generic.c
blob: 3c7e001691a4b67196b60de805a288001a998e75 (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
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
73
74
75
76
77
78
79
80
81
/* { dg-do run } */
/* { dg-options "-O1 -fdump-tree-original" } */

char *buffer1;
char *buffer2;

#define SIZE 1000

int
main (void)
{
  const char* const foo1 = "hello world";

  buffer1 = __builtin_malloc (SIZE);
  __builtin_strcpy (buffer1, foo1);
  buffer2 = __builtin_malloc (SIZE);
  __builtin_strcpy (buffer2, foo1);

  /* MEMCHR.  */
  if (__builtin_memchr ("hello world", 'x', 11))
    __builtin_abort ();
  if (__builtin_memchr ("hello world", 'x', 0) != 0)
    __builtin_abort ();
  if (__builtin_memchr ("hello world", 'w', 2))
    __builtin_abort ();
  if (__builtin_memchr ("hello world", 'd', 10))
    __builtin_abort ();
  if (__builtin_memchr ("hello world", '\0', 11))
    __builtin_abort ();

  /* STRCMP.  */
  if (__builtin_strcmp ("hello", "aaaaa") <= 0)
    __builtin_abort ();
  if (__builtin_strcmp ("aaaaa", "aaaaa") != 0)
    __builtin_abort ();
  if (__builtin_strcmp ("aaaaa", "") <= 0)
    __builtin_abort ();
  if (__builtin_strcmp ("", "aaaaa") >= 0)
    __builtin_abort ();
  if (__builtin_strcmp ("ab", "ba") >= 0)
    __builtin_abort ();

  /* STRNCMP.  */
  if (__builtin_strncmp ("hello", "aaaaa", 0) != 0)
    __builtin_abort ();
  if (__builtin_strncmp ("aaaaa", "aaaaa", 100) != 0)
    __builtin_abort ();
  if (__builtin_strncmp ("aaaaa", "", 100) <= 0)
    __builtin_abort ();
  if (__builtin_strncmp ("", "aaaaa", 100) >= 0)
    __builtin_abort ();
  if (__builtin_strncmp ("ab", "ba", 1) >= 0)
    __builtin_abort ();
  if (__builtin_strncmp ("aab", "aac", 2) != 0)
    __builtin_abort ();

  /* STRCASECMP.  */
  if (__builtin_strcasecmp ("aaaaa", "aaaaa") != 0)
    __builtin_abort ();

  /* STRNCASECMP.  */
  if (__builtin_strncasecmp ("hello", "aaaaa", 0) != 0)
    __builtin_abort ();
  if (__builtin_strncasecmp ("aaaaa", "aaaaa", 100) != 0)
    __builtin_abort ();
  if (__builtin_strncasecmp ("aab", "aac", 2) != 0)
    __builtin_abort ();

  /* MEMCMP.  */
  if (__builtin_memcmp ("aaaaa", "aaaaa", 6) != 0)
    __builtin_abort ();

  return 0;
}

/* { dg-final { scan-tree-dump-not "__builtin_strcmp" "original" } } */
/* { dg-final { scan-tree-dump-not "__builtin_strcasecmp" "original" } } */
/* { dg-final { scan-tree-dump-not "__builtin_strncmp" "original" } } */
/* { dg-final { scan-tree-dump-not "__builtin_strncasecmp" "original" } } */
/* { dg-final { scan-tree-dump-not "__builtin_memchr" "original" } } */
/* { dg-final { scan-tree-dump-not "__builtin_memcmp" "original" } } */