1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 %s -triple=i686-apple-darwin9 -verify -DVERIFY 2f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -E -triple=i686-apple-darwin9 3f4a2713aSLionel Sambuc #ifndef __has_feature 4f4a2713aSLionel Sambuc #error Should have __has_feature 5f4a2713aSLionel Sambuc #endif 6f4a2713aSLionel Sambuc 7f4a2713aSLionel Sambuc 8f4a2713aSLionel Sambuc #if __has_feature(something_we_dont_have) 9f4a2713aSLionel Sambuc #error Bad 10f4a2713aSLionel Sambuc #endif 11f4a2713aSLionel Sambuc 12f4a2713aSLionel Sambuc #if !__has_builtin(__builtin_huge_val) || \ 13f4a2713aSLionel Sambuc !__has_builtin(__builtin_shufflevector) || \ 14f4a2713aSLionel Sambuc !__has_builtin(__builtin_convertvector) || \ 15f4a2713aSLionel Sambuc !__has_builtin(__builtin_trap) || \ 16f4a2713aSLionel Sambuc !__has_builtin(__c11_atomic_init) || \ 17f4a2713aSLionel Sambuc !__has_feature(attribute_analyzer_noreturn) || \ 18f4a2713aSLionel Sambuc !__has_feature(attribute_overloadable) 19f4a2713aSLionel Sambuc #error Clang should have these 20f4a2713aSLionel Sambuc #endif 21f4a2713aSLionel Sambuc 22f4a2713aSLionel Sambuc #if __has_builtin(__builtin_insanity) 23f4a2713aSLionel Sambuc #error Clang should not have this 24f4a2713aSLionel Sambuc #endif 25f4a2713aSLionel Sambuc 26f4a2713aSLionel Sambuc #if !__has_feature(__attribute_deprecated_with_message__) 27f4a2713aSLionel Sambuc #error Feature name in double underscores does not work 28f4a2713aSLionel Sambuc #endif 29f4a2713aSLionel Sambuc 30f4a2713aSLionel Sambuc // Make sure we have x86 builtins only (forced with target triple). 31f4a2713aSLionel Sambuc 32f4a2713aSLionel Sambuc #if !__has_builtin(__builtin_ia32_emms) || \ 33f4a2713aSLionel Sambuc __has_builtin(__builtin_altivec_abs_v4sf) 34f4a2713aSLionel Sambuc #error Broken handling of target-specific builtins 35f4a2713aSLionel Sambuc #endif 36f4a2713aSLionel Sambuc 37f4a2713aSLionel Sambuc // Macro expansion does not occur in the parameter to __has_builtin, 38f4a2713aSLionel Sambuc // __has_feature, etc. (as is also expected behaviour for ordinary 39f4a2713aSLionel Sambuc // macros), so the following should not expand: 40f4a2713aSLionel Sambuc 41f4a2713aSLionel Sambuc #define MY_ALIAS_BUILTIN __c11_atomic_init 42f4a2713aSLionel Sambuc #define MY_ALIAS_FEATURE attribute_overloadable 43f4a2713aSLionel Sambuc 44f4a2713aSLionel Sambuc #if __has_builtin(MY_ALIAS_BUILTIN) || __has_feature(MY_ALIAS_FEATURE) 45f4a2713aSLionel Sambuc #error Alias expansion not allowed 46f4a2713aSLionel Sambuc #endif 47f4a2713aSLionel Sambuc 48f4a2713aSLionel Sambuc // But deferring should expand: 49f4a2713aSLionel Sambuc 50f4a2713aSLionel Sambuc #define HAS_BUILTIN(X) __has_builtin(X) 51f4a2713aSLionel Sambuc #define HAS_FEATURE(X) __has_feature(X) 52f4a2713aSLionel Sambuc 53f4a2713aSLionel Sambuc #if !HAS_BUILTIN(MY_ALIAS_BUILTIN) || !HAS_FEATURE(MY_ALIAS_FEATURE) 54f4a2713aSLionel Sambuc #error Expansion should have occurred 55f4a2713aSLionel Sambuc #endif 56*0a6a1f1dSLionel Sambuc 57*0a6a1f1dSLionel Sambuc #ifdef VERIFY 58*0a6a1f1dSLionel Sambuc // expected-error@+2 {{builtin feature check macro requires a parenthesized identifier}} 59*0a6a1f1dSLionel Sambuc // expected-error@+1 {{expected value in expression}} 60*0a6a1f1dSLionel Sambuc #if __has_feature('x') 61*0a6a1f1dSLionel Sambuc #endif 62*0a6a1f1dSLionel Sambuc #endif 63