blob: 8735cc613b59ca1205162f74ecd8de02024b3203 [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -emit-llvm -o %t %s &&
Daniel Dunbard417d962008-09-03 21:17:21 +00002// 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
Daniel Dunbarf8ebb412009-02-20 06:36:40 +000080 // Lib functions
Daniel Dunbard417d962008-09-03 21:17:21 +000081 int a, b, n = random(); // Avoid optimizing out.
82 char s0[10], s1[] = "Hello";
Daniel Dunbarf8ebb412009-02-20 06:36:40 +000083 V(strcat, (s0, s1));
Daniel Dunbar7a0048b2009-04-09 16:42:50 +000084 V(strcmp, (s0, s1));
Daniel Dunbarf8ebb412009-02-20 06:36:40 +000085 V(strncat, (s0, s1, n));
86 V(strchr, (s0, s1[0]));
87 V(strrchr, (s0, s1[0]));
88 V(strcpy, (s0, s1));
89 V(strncpy, (s0, s1, n));
90
91 // Object size checking
Daniel Dunbard417d962008-09-03 21:17:21 +000092 V(__memset_chk, (s0, 0, sizeof s0, n));
93 V(__memcpy_chk, (s0, s1, sizeof s0, n));
94 V(__memmove_chk, (s0, s1, sizeof s0, n));
95 V(__mempcpy_chk, (s0, s1, sizeof s0, n));
96 V(__strncpy_chk, (s0, s1, sizeof s0, n));
97 V(__strcpy_chk, (s0, s1, n));
98 s0[0] = 0;
99 V(__strcat_chk, (s0, s1, n));
100 P(object_size, (s0, 0));
101 P(object_size, (s0, 1));
102 P(object_size, (s0, 2));
103 P(object_size, (s0, 3));
104
105 // Whatever
106
107 P(bswap32, (N));
108 P(bswap64, (N));
109 // FIXME
110 // V(clear_cache, (&N, &N+1));
111 V(trap, ());
112
113 return 0;
114}
115
Chris Lattnerb808c952009-03-22 21:56:56 +0000116
117
118void strcat() {}
119
120void foo() {
121 __builtin_strcat(0, 0);
122}
123