blob: 165db9c267539bd7bd26d1e61d68d2a97d96c98c [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
Eli Friedmand6139892009-09-01 04:19:44 +000057 P(isnan, (1.));
58
Daniel Dunbard417d962008-09-03 21:17:21 +000059 // Bitwise & Numeric Functions
60
Daniel Dunbar1768a622008-10-05 06:34:45 +000061 P(abs, (N));
62
Daniel Dunbard417d962008-09-03 21:17:21 +000063 P(clz, (N));
64 P(clzl, (N));
65 P(clzll, (N));
66 P(ctz, (N));
67 P(ctzl, (N));
68 P(ctzll, (N));
69 P(ffs, (N));
70 P(ffsl, (N));
71 P(ffsll, (N));
72 P(parity, (N));
73 P(parityl, (N));
74 P(parityll, (N));
75 P(popcount, (N));
76 P(popcountl, (N));
77 P(popcountll, (N));
78 Q(powi, (1.2f, N));
79 Q(powif, (1.2f, N));
80 Q(powil, (1.2f, N));
81
Daniel Dunbarf8ebb412009-02-20 06:36:40 +000082 // Lib functions
Daniel Dunbard417d962008-09-03 21:17:21 +000083 int a, b, n = random(); // Avoid optimizing out.
84 char s0[10], s1[] = "Hello";
Daniel Dunbarf8ebb412009-02-20 06:36:40 +000085 V(strcat, (s0, s1));
Daniel Dunbar7a0048b2009-04-09 16:42:50 +000086 V(strcmp, (s0, s1));
Daniel Dunbarf8ebb412009-02-20 06:36:40 +000087 V(strncat, (s0, s1, n));
88 V(strchr, (s0, s1[0]));
89 V(strrchr, (s0, s1[0]));
90 V(strcpy, (s0, s1));
91 V(strncpy, (s0, s1, n));
92
93 // Object size checking
Daniel Dunbard417d962008-09-03 21:17:21 +000094 V(__memset_chk, (s0, 0, sizeof s0, n));
95 V(__memcpy_chk, (s0, s1, sizeof s0, n));
96 V(__memmove_chk, (s0, s1, sizeof s0, n));
97 V(__mempcpy_chk, (s0, s1, sizeof s0, n));
98 V(__strncpy_chk, (s0, s1, sizeof s0, n));
99 V(__strcpy_chk, (s0, s1, n));
100 s0[0] = 0;
101 V(__strcat_chk, (s0, s1, n));
102 P(object_size, (s0, 0));
103 P(object_size, (s0, 1));
104 P(object_size, (s0, 2));
105 P(object_size, (s0, 3));
106
107 // Whatever
108
109 P(bswap32, (N));
110 P(bswap64, (N));
111 // FIXME
112 // V(clear_cache, (&N, &N+1));
113 V(trap, ());
Eli Friedman3b660ef2009-05-03 19:23:23 +0000114 P(extract_return_addr, (&N));
Daniel Dunbard417d962008-09-03 21:17:21 +0000115
116 return 0;
117}
118
Chris Lattnerb808c952009-03-22 21:56:56 +0000119
120
121void strcat() {}
122
123void foo() {
124 __builtin_strcat(0, 0);
125}
126