feature_tests.c 1.8 KB

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