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 | |
| 41 | // FIXME: |
| 42 | // XXX I don't know what the string arg is for |
| 43 | Q(nan, ("0x12")); |
| 44 | Q(nanf, ("0x12")); |
| 45 | Q(nanl, ("0x12")); |
| 46 | Q(nans, ("0x12")); |
| 47 | |
| 48 | // Bitwise & Numeric Functions |
| 49 | |
| 50 | P(clz, (N)); |
| 51 | P(clzl, (N)); |
| 52 | P(clzll, (N)); |
| 53 | P(ctz, (N)); |
| 54 | P(ctzl, (N)); |
| 55 | P(ctzll, (N)); |
| 56 | P(ffs, (N)); |
| 57 | P(ffsl, (N)); |
| 58 | P(ffsll, (N)); |
| 59 | P(parity, (N)); |
| 60 | P(parityl, (N)); |
| 61 | P(parityll, (N)); |
| 62 | P(popcount, (N)); |
| 63 | P(popcountl, (N)); |
| 64 | P(popcountll, (N)); |
| 65 | Q(powi, (1.2f, N)); |
| 66 | Q(powif, (1.2f, N)); |
| 67 | Q(powil, (1.2f, N)); |
| 68 | |
| 69 | // Object size checking |
| 70 | int a, b, n = random(); // Avoid optimizing out. |
| 71 | char s0[10], s1[] = "Hello"; |
| 72 | V(__memset_chk, (s0, 0, sizeof s0, n)); |
| 73 | V(__memcpy_chk, (s0, s1, sizeof s0, n)); |
| 74 | V(__memmove_chk, (s0, s1, sizeof s0, n)); |
| 75 | V(__mempcpy_chk, (s0, s1, sizeof s0, n)); |
| 76 | V(__strncpy_chk, (s0, s1, sizeof s0, n)); |
| 77 | V(__strcpy_chk, (s0, s1, n)); |
| 78 | s0[0] = 0; |
| 79 | V(__strcat_chk, (s0, s1, n)); |
| 80 | P(object_size, (s0, 0)); |
| 81 | P(object_size, (s0, 1)); |
| 82 | P(object_size, (s0, 2)); |
| 83 | P(object_size, (s0, 3)); |
| 84 | |
| 85 | // Whatever |
| 86 | |
| 87 | P(bswap32, (N)); |
| 88 | P(bswap64, (N)); |
| 89 | // FIXME |
| 90 | // V(clear_cache, (&N, &N+1)); |
| 91 | V(trap, ()); |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |