Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -emit-llvm -o %t %s |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 2 | // RUN: not grep __builtin %t |
| 3 | |
Daniel Dunbar | 23afaad | 2009-11-17 08:57:36 +0000 | [diff] [blame] | 4 | int printf(const char *, ...); |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 5 | |
| 6 | void p(char *str, int x) { |
| 7 | printf("%s: %d\n", str, x); |
| 8 | } |
| 9 | void q(char *str, double x) { |
| 10 | printf("%s: %f\n", str, x); |
| 11 | } |
| 12 | |
| 13 | int main() { |
| 14 | int N = random(); |
| 15 | #define P(n,args) p(#n #args, __builtin_##n args) |
| 16 | #define Q(n,args) q(#n #args, __builtin_##n args) |
| 17 | #define V(n,args) p(#n #args, (__builtin_##n args, 0)) |
| 18 | P(types_compatible_p, (int, float)); |
| 19 | P(choose_expr, (0, 10, 20)); |
| 20 | P(constant_p, (sizeof(10))); |
| 21 | P(expect, (N == 12, 0)); |
| 22 | V(prefetch, (&N)); |
| 23 | V(prefetch, (&N, 1)); |
| 24 | V(prefetch, (&N, 1, 0)); |
| 25 | |
| 26 | // Numeric Constants |
| 27 | |
| 28 | Q(huge_val, ()); |
| 29 | Q(huge_valf, ()); |
| 30 | Q(huge_vall, ()); |
| 31 | Q(inf, ()); |
| 32 | Q(inff, ()); |
| 33 | Q(infl, ()); |
| 34 | |
| 35 | // FIXME: |
| 36 | // XXX note funny semantics for the (last) argument |
| 37 | // P(fpclassify, (FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, 1.0)); |
| 38 | // P(isinf_sign, (1.0)); |
| 39 | |
Daniel Dunbar | 1768a62 | 2008-10-05 06:34:45 +0000 | [diff] [blame] | 40 | Q(nan, ("")); |
| 41 | Q(nanf, ("")); |
| 42 | Q(nanl, ("")); |
| 43 | Q(nans, ("")); |
| 44 | Q(nan, ("10")); |
| 45 | Q(nanf, ("10")); |
| 46 | Q(nanl, ("10")); |
| 47 | Q(nans, ("10")); |
| 48 | |
| 49 | P(isgreater, (1., 2.)); |
| 50 | P(isgreaterequal, (1., 2.)); |
| 51 | P(isless, (1., 2.)); |
| 52 | P(islessequal, (1., 2.)); |
| 53 | P(islessgreater, (1., 2.)); |
| 54 | P(isunordered, (1., 2.)); |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 55 | |
Eli Friedman | d613989 | 2009-09-01 04:19:44 +0000 | [diff] [blame] | 56 | P(isnan, (1.)); |
| 57 | |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 58 | // Bitwise & Numeric Functions |
| 59 | |
Daniel Dunbar | 1768a62 | 2008-10-05 06:34:45 +0000 | [diff] [blame] | 60 | P(abs, (N)); |
| 61 | |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 62 | P(clz, (N)); |
| 63 | P(clzl, (N)); |
| 64 | P(clzll, (N)); |
| 65 | P(ctz, (N)); |
| 66 | P(ctzl, (N)); |
| 67 | P(ctzll, (N)); |
| 68 | P(ffs, (N)); |
| 69 | P(ffsl, (N)); |
| 70 | P(ffsll, (N)); |
| 71 | P(parity, (N)); |
| 72 | P(parityl, (N)); |
| 73 | P(parityll, (N)); |
| 74 | P(popcount, (N)); |
| 75 | P(popcountl, (N)); |
| 76 | P(popcountll, (N)); |
| 77 | Q(powi, (1.2f, N)); |
| 78 | Q(powif, (1.2f, N)); |
| 79 | Q(powil, (1.2f, N)); |
| 80 | |
Daniel Dunbar | f8ebb41 | 2009-02-20 06:36:40 +0000 | [diff] [blame] | 81 | // Lib functions |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 82 | int a, b, n = random(); // Avoid optimizing out. |
| 83 | char s0[10], s1[] = "Hello"; |
Daniel Dunbar | f8ebb41 | 2009-02-20 06:36:40 +0000 | [diff] [blame] | 84 | V(strcat, (s0, s1)); |
Daniel Dunbar | 7a0048b | 2009-04-09 16:42:50 +0000 | [diff] [blame] | 85 | V(strcmp, (s0, s1)); |
Daniel Dunbar | f8ebb41 | 2009-02-20 06:36:40 +0000 | [diff] [blame] | 86 | V(strncat, (s0, s1, n)); |
| 87 | V(strchr, (s0, s1[0])); |
| 88 | V(strrchr, (s0, s1[0])); |
| 89 | V(strcpy, (s0, s1)); |
| 90 | V(strncpy, (s0, s1, n)); |
| 91 | |
| 92 | // Object size checking |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 93 | V(__memset_chk, (s0, 0, sizeof s0, n)); |
| 94 | V(__memcpy_chk, (s0, s1, sizeof s0, n)); |
| 95 | V(__memmove_chk, (s0, s1, sizeof s0, n)); |
| 96 | V(__mempcpy_chk, (s0, s1, sizeof s0, n)); |
| 97 | V(__strncpy_chk, (s0, s1, sizeof s0, n)); |
| 98 | V(__strcpy_chk, (s0, s1, n)); |
| 99 | s0[0] = 0; |
| 100 | V(__strcat_chk, (s0, s1, n)); |
| 101 | P(object_size, (s0, 0)); |
| 102 | P(object_size, (s0, 1)); |
| 103 | P(object_size, (s0, 2)); |
| 104 | P(object_size, (s0, 3)); |
| 105 | |
| 106 | // Whatever |
| 107 | |
| 108 | P(bswap32, (N)); |
| 109 | P(bswap64, (N)); |
| 110 | // FIXME |
| 111 | // V(clear_cache, (&N, &N+1)); |
| 112 | V(trap, ()); |
Eli Friedman | 3b660ef | 2009-05-03 19:23:23 +0000 | [diff] [blame] | 113 | P(extract_return_addr, (&N)); |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
Chris Lattner | b808c95 | 2009-03-22 21:56:56 +0000 | [diff] [blame] | 118 | |
| 119 | |
John Thompson | f65b9f5 | 2009-10-15 14:34:41 +0000 | [diff] [blame] | 120 | void strcat() {} |
Chris Lattner | b808c95 | 2009-03-22 21:56:56 +0000 | [diff] [blame] | 121 | |
| 122 | void foo() { |
| 123 | __builtin_strcat(0, 0); |
| 124 | } |
| 125 | |