Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm -o %t %s |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 2 | // RUN: not grep __builtin %t |
John McCall | db7b72a | 2010-02-28 13:00:19 +0000 | [diff] [blame] | 3 | // RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple | FileCheck %s |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 4 | |
Daniel Dunbar | 23afaad | 2009-11-17 08:57:36 +0000 | [diff] [blame] | 5 | int printf(const char *, ...); |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 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 | } |
John McCall | db7b72a | 2010-02-28 13:00:19 +0000 | [diff] [blame] | 13 | void r(char *str, void *ptr) { |
| 14 | printf("%s: %p\n", str, ptr); |
| 15 | } |
| 16 | |
| 17 | int random(void); |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 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) |
John McCall | db7b72a | 2010-02-28 13:00:19 +0000 | [diff] [blame] | 23 | #define R(n,args) r(#n #args, __builtin_##n args) |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 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 | |
Daniel Dunbar | 1768a62 | 2008-10-05 06:34:45 +0000 | [diff] [blame] | 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.)); |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 62 | |
Eli Friedman | d613989 | 2009-09-01 04:19:44 +0000 | [diff] [blame] | 63 | P(isnan, (1.)); |
| 64 | |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 65 | // Bitwise & Numeric Functions |
| 66 | |
Daniel Dunbar | 1768a62 | 2008-10-05 06:34:45 +0000 | [diff] [blame] | 67 | P(abs, (N)); |
| 68 | |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 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 | |
Daniel Dunbar | f8ebb41 | 2009-02-20 06:36:40 +0000 | [diff] [blame] | 88 | // Lib functions |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 89 | int a, b, n = random(); // Avoid optimizing out. |
| 90 | char s0[10], s1[] = "Hello"; |
Daniel Dunbar | f8ebb41 | 2009-02-20 06:36:40 +0000 | [diff] [blame] | 91 | V(strcat, (s0, s1)); |
Daniel Dunbar | 7a0048b | 2009-04-09 16:42:50 +0000 | [diff] [blame] | 92 | V(strcmp, (s0, s1)); |
Daniel Dunbar | f8ebb41 | 2009-02-20 06:36:40 +0000 | [diff] [blame] | 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 |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 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, ()); |
John McCall | db7b72a | 2010-02-28 13:00:19 +0000 | [diff] [blame] | 120 | R(extract_return_addr, (&N)); |
Eli Friedman | ba68b08 | 2010-03-06 02:17:52 +0000 | [diff] [blame] | 121 | P(signbit, (1.0)); |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
Chris Lattner | b808c95 | 2009-03-22 21:56:56 +0000 | [diff] [blame] | 126 | |
| 127 | |
Chris Lattner | b808c95 | 2009-03-22 21:56:56 +0000 | [diff] [blame] | 128 | void foo() { |
| 129 | __builtin_strcat(0, 0); |
| 130 | } |
| 131 | |
John McCall | db7b72a | 2010-02-28 13:00:19 +0000 | [diff] [blame] | 132 | // CHECK: define void @bar( |
| 133 | void bar() { |
| 134 | float f; |
| 135 | double d; |
| 136 | long double ld; |
| 137 | |
| 138 | // LLVM's hex representation of float constants is really unfortunate; |
| 139 | // basically it does a float-to-double "conversion" and then prints the |
| 140 | // hex form of that. That gives us wierd artifacts like exponents |
| 141 | // that aren't numerically similar to the original exponent and |
| 142 | // significand bit-patterns that are offset by three bits (because |
| 143 | // the exponent was expanded from 8 bits to 11). |
| 144 | // |
| 145 | // 0xAE98 == 1010111010011000 |
| 146 | // 0x15D3 == 1010111010011 |
| 147 | |
| 148 | f = __builtin_huge_valf(); // CHECK: float 0x7FF0000000000000 |
| 149 | d = __builtin_huge_val(); // CHECK: double 0x7FF0000000000000 |
| 150 | ld = __builtin_huge_vall(); // CHECK: x86_fp80 0xK7FFF8000000000000000 |
| 151 | f = __builtin_nanf(""); // CHECK: float 0x7FF8000000000000 |
| 152 | d = __builtin_nan(""); // CHECK: double 0x7FF8000000000000 |
| 153 | ld = __builtin_nanl(""); // CHECK: x86_fp80 0xK7FFFC000000000000000 |
| 154 | f = __builtin_nanf("0xAE98"); // CHECK: float 0x7FF815D300000000 |
| 155 | d = __builtin_nan("0xAE98"); // CHECK: double 0x7FF800000000AE98 |
| 156 | ld = __builtin_nanl("0xAE98"); // CHECK: x86_fp80 0xK7FFFC00000000000AE98 |
| 157 | f = __builtin_nansf(""); // CHECK: float 0x7FF4000000000000 |
| 158 | d = __builtin_nans(""); // CHECK: double 0x7FF4000000000000 |
| 159 | ld = __builtin_nansl(""); // CHECK: x86_fp80 0xK7FFFA000000000000000 |
| 160 | f = __builtin_nansf("0xAE98"); // CHECK: float 0x7FF015D300000000 |
| 161 | d = __builtin_nans("0xAE98"); // CHECK: double 0x7FF000000000AE98 |
| 162 | ld = __builtin_nansl("0xAE98");// CHECK: x86_fp80 0xK7FFF800000000000AE98 |
| 163 | |
| 164 | } |
| 165 | // CHECK: } |