blob: e7055d9ad8a43a76eb620e30de40bd70f6d1097c [file] [log] [blame]
Daniel Dunbard417d962008-09-03 21:17:21 +00001// RUN: clang -emit-llvm -o %t %s &&
2// RUN: not grep __builtin %t
3
4#include <stdio.h>
5#include <math.h>
6
7void p(char *str, int x) {
8 printf("%s: %d\n", str, x);
9}
10void q(char *str, double x) {
11 printf("%s: %f\n", str, x);
12}
13
14int main() {
15 int N = random();
16#define P(n,args) p(#n #args, __builtin_##n args)
17#define Q(n,args) q(#n #args, __builtin_##n args)
18#define V(n,args) p(#n #args, (__builtin_##n args, 0))
19 P(types_compatible_p, (int, float));
20 P(choose_expr, (0, 10, 20));
21 P(constant_p, (sizeof(10)));
22 P(expect, (N == 12, 0));
23 V(prefetch, (&N));
24 V(prefetch, (&N, 1));
25 V(prefetch, (&N, 1, 0));
26
27 // Numeric Constants
28
29 Q(huge_val, ());
30 Q(huge_valf, ());
31 Q(huge_vall, ());
32 Q(inf, ());
33 Q(inff, ());
34 Q(infl, ());
35
36 // FIXME:
37 // XXX note funny semantics for the (last) argument
38 // P(fpclassify, (FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, 1.0));
39 // P(isinf_sign, (1.0));
40
Daniel Dunbar1768a622008-10-05 06:34:45 +000041 Q(nan, (""));
42 Q(nanf, (""));
43 Q(nanl, (""));
44 Q(nans, (""));
45 Q(nan, ("10"));
46 Q(nanf, ("10"));
47 Q(nanl, ("10"));
48 Q(nans, ("10"));
49
50 P(isgreater, (1., 2.));
51 P(isgreaterequal, (1., 2.));
52 P(isless, (1., 2.));
53 P(islessequal, (1., 2.));
54 P(islessgreater, (1., 2.));
55 P(isunordered, (1., 2.));
Daniel Dunbard417d962008-09-03 21:17:21 +000056
57 // Bitwise & Numeric Functions
58
Daniel Dunbar1768a622008-10-05 06:34:45 +000059 P(abs, (N));
60
Daniel Dunbard417d962008-09-03 21:17:21 +000061 P(clz, (N));
62 P(clzl, (N));
63 P(clzll, (N));
64 P(ctz, (N));
65 P(ctzl, (N));
66 P(ctzll, (N));
67 P(ffs, (N));
68 P(ffsl, (N));
69 P(ffsll, (N));
70 P(parity, (N));
71 P(parityl, (N));
72 P(parityll, (N));
73 P(popcount, (N));
74 P(popcountl, (N));
75 P(popcountll, (N));
76 Q(powi, (1.2f, N));
77 Q(powif, (1.2f, N));
78 Q(powil, (1.2f, N));
79
80 // Object size checking
81 int a, b, n = random(); // Avoid optimizing out.
82 char s0[10], s1[] = "Hello";
83 V(__memset_chk, (s0, 0, sizeof s0, n));
84 V(__memcpy_chk, (s0, s1, sizeof s0, n));
85 V(__memmove_chk, (s0, s1, sizeof s0, n));
86 V(__mempcpy_chk, (s0, s1, sizeof s0, n));
87 V(__strncpy_chk, (s0, s1, sizeof s0, n));
88 V(__strcpy_chk, (s0, s1, n));
89 s0[0] = 0;
90 V(__strcat_chk, (s0, s1, n));
91 P(object_size, (s0, 0));
92 P(object_size, (s0, 1));
93 P(object_size, (s0, 2));
94 P(object_size, (s0, 3));
95
96 // Whatever
97
98 P(bswap32, (N));
99 P(bswap64, (N));
100 // FIXME
101 // V(clear_cache, (&N, &N+1));
102 V(trap, ());
103
104 return 0;
105}
106