David Majnemer | d616362 | 2014-12-15 09:03:58 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -triple=i686-apple-darwin9 -verify -DVERIFY |
Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 %s -E -triple=i686-apple-darwin9 |
Chris Lattner | b6f77af | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 3 | #ifndef __has_feature |
| 4 | #error Should have __has_feature |
| 5 | #endif |
| 6 | |
| 7 | |
| 8 | #if __has_feature(something_we_dont_have) |
| 9 | #error Bad |
| 10 | #endif |
| 11 | |
| 12 | #if !__has_builtin(__builtin_huge_val) || \ |
| 13 | !__has_builtin(__builtin_shufflevector) || \ |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 14 | !__has_builtin(__builtin_convertvector) || \ |
Chris Lattner | b6f77af | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 15 | !__has_builtin(__builtin_trap) || \ |
Richard Smith | b1e36c6 | 2012-04-11 17:55:32 +0000 | [diff] [blame] | 16 | !__has_builtin(__c11_atomic_init) || \ |
Chris Lattner | b6f77af | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 17 | !__has_feature(attribute_analyzer_noreturn) || \ |
| 18 | !__has_feature(attribute_overloadable) |
| 19 | #error Clang should have these |
| 20 | #endif |
| 21 | |
| 22 | #if __has_builtin(__builtin_insanity) |
| 23 | #error Clang should not have this |
| 24 | #endif |
| 25 | |
Richard Smith | 2cca7b5 | 2012-02-25 10:41:10 +0000 | [diff] [blame] | 26 | #if !__has_feature(__attribute_deprecated_with_message__) |
| 27 | #error Feature name in double underscores does not work |
| 28 | #endif |
Chris Lattner | b6f77af | 2009-06-13 07:13:28 +0000 | [diff] [blame] | 29 | |
| 30 | // Make sure we have x86 builtins only (forced with target triple). |
| 31 | |
| 32 | #if !__has_builtin(__builtin_ia32_emms) || \ |
| 33 | __has_builtin(__builtin_altivec_abs_v4sf) |
| 34 | #error Broken handling of target-specific builtins |
| 35 | #endif |
Andy Gibbs | d41d094 | 2012-11-17 19:18:27 +0000 | [diff] [blame] | 36 | |
| 37 | // Macro expansion does not occur in the parameter to __has_builtin, |
| 38 | // __has_feature, etc. (as is also expected behaviour for ordinary |
| 39 | // macros), so the following should not expand: |
| 40 | |
| 41 | #define MY_ALIAS_BUILTIN __c11_atomic_init |
| 42 | #define MY_ALIAS_FEATURE attribute_overloadable |
| 43 | |
| 44 | #if __has_builtin(MY_ALIAS_BUILTIN) || __has_feature(MY_ALIAS_FEATURE) |
| 45 | #error Alias expansion not allowed |
| 46 | #endif |
| 47 | |
| 48 | // But deferring should expand: |
| 49 | |
| 50 | #define HAS_BUILTIN(X) __has_builtin(X) |
| 51 | #define HAS_FEATURE(X) __has_feature(X) |
| 52 | |
| 53 | #if !HAS_BUILTIN(MY_ALIAS_BUILTIN) || !HAS_FEATURE(MY_ALIAS_FEATURE) |
| 54 | #error Expansion should have occurred |
| 55 | #endif |
David Majnemer | d616362 | 2014-12-15 09:03:58 +0000 | [diff] [blame] | 56 | |
| 57 | #ifdef VERIFY |
Andy Gibbs | 50b6cef | 2016-04-05 08:36:47 +0000 | [diff] [blame] | 58 | // expected-error@+1 {{builtin feature check macro requires a parenthesized identifier}} |
David Majnemer | d616362 | 2014-12-15 09:03:58 +0000 | [diff] [blame] | 59 | #if __has_feature('x') |
| 60 | #endif |
Andy Gibbs | 50b6cef | 2016-04-05 08:36:47 +0000 | [diff] [blame] | 61 | |
| 62 | // The following are not identifiers: |
| 63 | _Static_assert(!__is_identifier("string"), "oops"); |
| 64 | _Static_assert(!__is_identifier('c'), "oops"); |
| 65 | _Static_assert(!__is_identifier(123), "oops"); |
| 66 | _Static_assert(!__is_identifier(int), "oops"); |
| 67 | |
| 68 | // The following are: |
| 69 | _Static_assert(__is_identifier(abc /* comment */), "oops"); |
| 70 | _Static_assert(__is_identifier /* comment */ (xyz), "oops"); |
| 71 | |
| 72 | // expected-error@+1 {{too few arguments}} |
| 73 | #if __is_identifier() |
| 74 | #endif |
| 75 | |
| 76 | // expected-error@+1 {{too many arguments}} |
| 77 | #if __is_identifier(,()) |
| 78 | #endif |
| 79 | |
| 80 | // expected-error@+1 {{missing ')' after 'abc'}} |
| 81 | #if __is_identifier(abc xyz) // expected-note {{to match this '('}} |
| 82 | #endif |
| 83 | |
| 84 | // expected-error@+1 {{missing ')' after 'abc'}} |
| 85 | #if __is_identifier(abc()) // expected-note {{to match this '('}} |
| 86 | #endif |
| 87 | |
| 88 | // expected-error@+1 {{missing ')' after '.'}} |
| 89 | #if __is_identifier(.abc) // expected-note {{to match this '('}} |
| 90 | #endif |
| 91 | |
| 92 | // expected-error@+1 {{nested parentheses not permitted in '__is_identifier'}} |
| 93 | #if __is_identifier((abc)) |
| 94 | #endif |
| 95 | |
| 96 | // expected-error@+1 {{missing '(' after '__is_identifier'}} expected-error@+1 {{expected value}} |
| 97 | #if __is_identifier |
| 98 | #endif |
| 99 | |
| 100 | // expected-error@+1 {{unterminated}} expected-error@+1 {{expected value}} |
| 101 | #if __is_identifier( |
| 102 | #endif |
| 103 | |
David Majnemer | d616362 | 2014-12-15 09:03:58 +0000 | [diff] [blame] | 104 | #endif |