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
5 int printf(const char *, ...);
7 void p(char *str, int x) {
8 printf("%s: %d\n", str, x);
10 void q(char *str, double x) {
11 printf("%s: %f\n", str, x);
13 void r(char *str, void *ptr) {
14 printf("%s: %p\n", str, ptr);
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));
31 V(prefetch, (&N, 1, 0));
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));
56 P(isgreater, (1., 2.));
57 P(isgreaterequal, (1., 2.));
59 P(islessequal, (1., 2.));
60 P(islessgreater, (1., 2.));
61 P(isunordered, (1., 2.));
65 // Bitwise & Numeric Functions
89 int a, b, n = random(); // Avoid optimizing out.
90 char s0[10], s1[] = "Hello";
93 V(strncat, (s0, s1, n));
94 V(strchr, (s0, s1[0]));
95 V(strrchr, (s0, s1[0]));
97 V(strncpy, (s0, s1, n));
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));
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));
118 // V(clear_cache, (&N, &N+1));
120 R(extract_return_addr, (&N));
128 __builtin_strcat(0, 0);
131 // CHECK: define void @bar(
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).
144 // 0xAE98 == 1010111010011000
145 // 0x15D3 == 1010111010011
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