]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CodeGen/builtins.c
Update clang to 97654.
[FreeBSD/FreeBSD.git] / test / CodeGen / builtins.c
1 // RUN: %clang_cc1 -emit-llvm -o %t %s
2 // RUN: not grep __builtin %t
3 // RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple | FileCheck %s
4
5 int printf(const char *, ...);
6
7 void p(char *str, int x) {
8   printf("%s: %d\n", str, x);
9 }
10 void q(char *str, double x) {
11   printf("%s: %f\n", str, x);
12 }
13 void r(char *str, void *ptr) {
14   printf("%s: %p\n", str, ptr);
15 }
16
17 int random(void);
18
19 int main() {
20   int N = random();
21 #define P(n,args) p(#n #args, __builtin_##n args)
22 #define Q(n,args) q(#n #args, __builtin_##n args)
23 #define R(n,args) r(#n #args, __builtin_##n args)
24 #define V(n,args) p(#n #args, (__builtin_##n args, 0))
25   P(types_compatible_p, (int, float));
26   P(choose_expr, (0, 10, 20));
27   P(constant_p, (sizeof(10)));
28   P(expect, (N == 12, 0)); 
29   V(prefetch, (&N));
30   V(prefetch, (&N, 1));
31   V(prefetch, (&N, 1, 0));
32   
33   // Numeric Constants
34
35   Q(huge_val, ());
36   Q(huge_valf, ());
37   Q(huge_vall, ());
38   Q(inf, ());
39   Q(inff, ());
40   Q(infl, ());
41
42   // FIXME:
43   // XXX note funny semantics for the (last) argument
44   //  P(fpclassify, (FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, 1.0));
45   //  P(isinf_sign, (1.0));
46
47   Q(nan, (""));
48   Q(nanf, (""));
49   Q(nanl, (""));
50   Q(nans, (""));
51   Q(nan, ("10"));
52   Q(nanf, ("10"));
53   Q(nanl, ("10"));
54   Q(nans, ("10"));
55
56   P(isgreater, (1., 2.));
57   P(isgreaterequal, (1., 2.));
58   P(isless, (1., 2.));
59   P(islessequal, (1., 2.));
60   P(islessgreater, (1., 2.));
61   P(isunordered, (1., 2.));
62
63   P(isnan, (1.));
64
65   // Bitwise & Numeric Functions
66
67   P(abs, (N));
68
69   P(clz, (N));
70   P(clzl, (N));
71   P(clzll, (N));
72   P(ctz, (N));
73   P(ctzl, (N));
74   P(ctzll, (N));
75   P(ffs, (N));
76   P(ffsl, (N));
77   P(ffsll, (N));
78   P(parity, (N));
79   P(parityl, (N));
80   P(parityll, (N));
81   P(popcount, (N));
82   P(popcountl, (N));
83   P(popcountll, (N));
84   Q(powi, (1.2f, N));
85   Q(powif, (1.2f, N));
86   Q(powil, (1.2f, N));
87
88   // Lib functions
89   int a, b, n = random(); // Avoid optimizing out.
90   char s0[10], s1[] = "Hello";
91   V(strcat, (s0, s1));
92   V(strcmp, (s0, s1));
93   V(strncat, (s0, s1, n));
94   V(strchr, (s0, s1[0]));
95   V(strrchr, (s0, s1[0]));
96   V(strcpy, (s0, s1));
97   V(strncpy, (s0, s1, n));
98   
99   // Object size checking
100   V(__memset_chk, (s0, 0, sizeof s0, n));
101   V(__memcpy_chk, (s0, s1, sizeof s0, n));
102   V(__memmove_chk, (s0, s1, sizeof s0, n));
103   V(__mempcpy_chk, (s0, s1, sizeof s0, n));
104   V(__strncpy_chk, (s0, s1, sizeof s0, n));
105   V(__strcpy_chk, (s0, s1, n));
106   s0[0] = 0;
107   V(__strcat_chk, (s0, s1, n));
108   P(object_size, (s0, 0));
109   P(object_size, (s0, 1));
110   P(object_size, (s0, 2));
111   P(object_size, (s0, 3));
112
113   // Whatever
114
115   P(bswap32, (N));
116   P(bswap64, (N));
117   // FIXME
118   // V(clear_cache, (&N, &N+1));
119   V(trap, ());
120   R(extract_return_addr, (&N));
121
122   return 0;
123 }
124
125
126
127 void foo() {
128  __builtin_strcat(0, 0);
129 }
130
131 // CHECK: define void @bar(
132 void bar() {
133   float f;
134   double d;
135   long double ld;
136
137   // LLVM's hex representation of float constants is really unfortunate;
138   // basically it does a float-to-double "conversion" and then prints the
139   // hex form of that.  That gives us wierd artifacts like exponents
140   // that aren't numerically similar to the original exponent and
141   // significand bit-patterns that are offset by three bits (because
142   // the exponent was expanded from 8 bits to 11).
143   //
144   // 0xAE98 == 1010111010011000
145   // 0x15D3 == 1010111010011
146
147   f = __builtin_huge_valf();     // CHECK: float    0x7FF0000000000000
148   d = __builtin_huge_val();      // CHECK: double   0x7FF0000000000000
149   ld = __builtin_huge_vall();    // CHECK: x86_fp80 0xK7FFF8000000000000000
150   f = __builtin_nanf("");        // CHECK: float    0x7FF8000000000000
151   d = __builtin_nan("");         // CHECK: double   0x7FF8000000000000
152   ld = __builtin_nanl("");       // CHECK: x86_fp80 0xK7FFFC000000000000000
153   f = __builtin_nanf("0xAE98");  // CHECK: float    0x7FF815D300000000
154   d = __builtin_nan("0xAE98");   // CHECK: double   0x7FF800000000AE98
155   ld = __builtin_nanl("0xAE98"); // CHECK: x86_fp80 0xK7FFFC00000000000AE98
156   f = __builtin_nansf("");       // CHECK: float    0x7FF4000000000000
157   d = __builtin_nans("");        // CHECK: double   0x7FF4000000000000
158   ld = __builtin_nansl("");      // CHECK: x86_fp80 0xK7FFFA000000000000000
159   f = __builtin_nansf("0xAE98"); // CHECK: float    0x7FF015D300000000
160   d = __builtin_nans("0xAE98");  // CHECK: double   0x7FF000000000AE98
161   ld = __builtin_nansl("0xAE98");// CHECK: x86_fp80 0xK7FFF800000000000AE98
162
163 }
164 // CHECK: }