aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/ubsan/builtin-2.c
blob: 877bd53a83c5246fc1868fafca91e05faaedf480 (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
82
83
84
85
86
87
88
89
/* PR sanitizer/115127 */
/* { dg-do run } */
/* { dg-options "-fsanitize=undefined" } */

#include <stdio.h>

__attribute__((noipa)) int
f1 (unsigned a)
{
  return __builtin_clz (a) == 0;
}

__attribute__((noipa)) int
f2 (unsigned long a)
{
  return __builtin_clzl (a) != 0;
}

__attribute__((noipa)) int
f3 (unsigned long long a)
{
  return __builtin_clzll (a) == __CHAR_BIT__ * __SIZEOF_LONG_LONG__ - 1;
}

__attribute__((noipa)) int
f4 (unsigned a)
{
  return __builtin_clz (a) != __CHAR_BIT__ * __SIZEOF_INT__ - 1;
}

__attribute__((noipa)) int
f5 (unsigned long a)
{
  return __builtin_ctzl (a) == 0;
}

__attribute__((noipa)) int
f6 (unsigned long long a)
{
  return __builtin_ctzll (a) != 0;
}

__attribute__((noipa)) int
f7 (unsigned a)
{
  return __builtin_ctz (a) == 4;
}

__attribute__((noipa)) int
f8 (unsigned long a)
{
  return __builtin_ctzl (a) != 4;
}

__attribute__((noipa)) int
f9 (unsigned long long a)
{
  return __builtin_ctzll (a) >= 4;
}

__attribute__((noipa)) int
f10 (unsigned a)
{
  return __builtin_ctz (a) < 4;
}

int
main ()
{
  fprintf (stderr, "FOO MARKER1\n");
  f1 (0);
  f2 (0);
  f3 (0);
  f4 (0);
  fprintf (stderr, "FOO MARKER2\n");
  f5 (0);
  f6 (0);
  f7 (0);
  f8 (0);
  f9 (0);
  f10 (0);
  fprintf (stderr, "FOO MARKER3\n");
}

/* { dg-output "FOO MARKER1(\n|\r\n|\r)" } */
/* { dg-output "(\[^\n\r]*runtime error: passing zero to __builtin_clz\\\(\\\), which is not a valid argument\[^\n\r]*(\n|\r\n|\r)){4}" } */
/* { dg-output "FOO MARKER2(\n|\r\n|\r)" } */
/* { dg-output "(\[^\n\r]*runtime error: passing zero to __builtin_ctz\\\(\\\), which is not a valid argument\[^\n\r]*(\n|\r\n|\r)){6}" } */
/* { dg-output "FOO MARKER3" } */