Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 1 | // RUN: clang -emit-llvm -o %t %s && |
| 2 | // RUN: not grep __builtin %t |
| 3 | |
| 4 | #include <stdio.h> |
| 5 | #include <math.h> |
| 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 | |
| 14 | int 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 Dunbar | 1768a62 | 2008-10-05 06:34:45 +0000 | [diff] [blame] | 41 | 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 Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 56 | |
| 57 | // Bitwise & Numeric Functions |
| 58 | |
Daniel Dunbar | 1768a62 | 2008-10-05 06:34:45 +0000 | [diff] [blame] | 59 | P(abs, (N)); |
| 60 | |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 61 | P(clz, (N)); |
| 62 | P(clzl, (N)); |
| 63 | P(clzll, (N)); |
| 64 | P(ctz, (N)); |
| 65 | P(ctzl, (N)); |
| 66 | P(ctzll, (N)); |
| 67 | P(ffs, (N)); |
| 68 | P(ffsl, (N)); |
| 69 | P(ffsll, (N)); |
| 70 | P(parity, (N)); |
| 71 | P(parityl, (N)); |
| 72 | P(parityll, (N)); |
| 73 | P(popcount, (N)); |
| 74 | P(popcountl, (N)); |
| 75 | P(popcountll, (N)); |
| 76 | Q(powi, (1.2f, N)); |
| 77 | Q(powif, (1.2f, N)); |
| 78 | Q(powil, (1.2f, N)); |
| 79 | |
Daniel Dunbar | f8ebb41 | 2009-02-20 06:36:40 +0000 | [diff] [blame] | 80 | // Lib functions |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 81 | int a, b, n = random(); // Avoid optimizing out. |
| 82 | char s0[10], s1[] = "Hello"; |
Daniel Dunbar | f8ebb41 | 2009-02-20 06:36:40 +0000 | [diff] [blame] | 83 | V(strcat, (s0, s1)); |
| 84 | V(strncat, (s0, s1, n)); |
| 85 | V(strchr, (s0, s1[0])); |
| 86 | V(strrchr, (s0, s1[0])); |
| 87 | V(strcpy, (s0, s1)); |
| 88 | V(strncpy, (s0, s1, n)); |
| 89 | |
| 90 | // Object size checking |
Daniel Dunbar | d417d96 | 2008-09-03 21:17:21 +0000 | [diff] [blame] | 91 | V(__memset_chk, (s0, 0, sizeof s0, n)); |
| 92 | V(__memcpy_chk, (s0, s1, sizeof s0, n)); |
| 93 | V(__memmove_chk, (s0, s1, sizeof s0, n)); |
| 94 | V(__mempcpy_chk, (s0, s1, sizeof s0, n)); |
| 95 | V(__strncpy_chk, (s0, s1, sizeof s0, n)); |
| 96 | V(__strcpy_chk, (s0, s1, n)); |
| 97 | s0[0] = 0; |
| 98 | V(__strcat_chk, (s0, s1, n)); |
| 99 | P(object_size, (s0, 0)); |
| 100 | P(object_size, (s0, 1)); |
| 101 | P(object_size, (s0, 2)); |
| 102 | P(object_size, (s0, 3)); |
| 103 | |
| 104 | // Whatever |
| 105 | |
| 106 | P(bswap32, (N)); |
| 107 | P(bswap64, (N)); |
| 108 | // FIXME |
| 109 | // V(clear_cache, (&N, &N+1)); |
| 110 | V(trap, ()); |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |