Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Preprocessor / feature_tests.c
blobe8aecfb82cb3beb0ea15101617ae99b96df826b0
1 // RUN: %clang_cc1 %s -triple=i686-apple-darwin9 -target-cpu pentium4 -verify -DVERIFY
2 // RUN: %clang_cc1 %s -E -triple=i686-apple-darwin9 -target-cpu pentium4
3 // RUN: %clang_cc1 %s -triple=i686-apple-darwin9 -target-cpu pentium4 -fms-extensions -DMS -verify -DVERIFY
4 // RUN: %clang_cc1 %s -E -triple=i686-apple-darwin9 -target-cpu pentium4 -fms-extensions -DMS
5 #ifndef __has_feature
6 #error Should have __has_feature
7 #endif
10 #if __has_feature(something_we_dont_have)
11 #error Bad
12 #endif
14 #if !__has_builtin(__builtin_huge_val) || \
15 !__has_builtin(__builtin_shufflevector) || \
16 !__has_builtin(__builtin_convertvector) || \
17 !__has_builtin(__builtin_trap) || \
18 !__has_builtin(__c11_atomic_init) || \
19 !__has_builtin(__builtin_launder) || \
20 !__has_feature(attribute_analyzer_noreturn) || \
21 !__has_feature(attribute_overloadable)
22 #error Clang should have these
23 #endif
25 // These are technically implemented as keywords, but __has_builtin should
26 // still return true.
27 #if !__has_builtin(__builtin_LINE) || \
28 !__has_builtin(__builtin_FILE) || \
29 !__has_builtin(__builtin_FILE_NAME) || \
30 !__has_builtin(__builtin_FUNCTION) || \
31 !__has_builtin(__builtin_COLUMN) || \
32 !__has_builtin(__builtin_types_compatible_p)
33 #error Clang should have these
34 #endif
36 #ifdef MS
37 #if !__has_builtin(__builtin_FUNCSIG)
38 #error Clang should have this
39 #endif
40 #elif __has_builtin(__builtin_FUNCSIG)
41 #error Clang should not have this without '-fms-extensions'
42 #endif
44 // These are C++-only builtins.
45 #if __has_builtin(__array_rank) || \
46 __has_builtin(__underlying_type) || \
47 __has_builtin(__is_trivial)
48 #error Clang should not have these in C mode
49 #endif
51 #if __has_builtin(__builtin_insanity)
52 #error Clang should not have this
53 #endif
55 #if !__has_feature(__attribute_deprecated_with_message__)
56 #error Feature name in double underscores does not work
57 #endif
59 // Make sure we have x86 builtins only (forced with target triple).
61 #if !__has_builtin(__builtin_ia32_emms) || \
62 __has_builtin(__builtin_altivec_abs_v4sf)
63 #error Broken handling of target-specific builtins
64 #endif
66 // Macro expansion does not occur in the parameter to __has_builtin,
67 // __has_feature, etc. (as is also expected behaviour for ordinary
68 // macros), so the following should not expand:
70 #define MY_ALIAS_BUILTIN __c11_atomic_init
71 #define MY_ALIAS_FEATURE attribute_overloadable
73 #if __has_builtin(MY_ALIAS_BUILTIN) || __has_feature(MY_ALIAS_FEATURE)
74 #error Alias expansion not allowed
75 #endif
77 // But deferring should expand:
79 #define HAS_BUILTIN(X) __has_builtin(X)
80 #define HAS_FEATURE(X) __has_feature(X)
82 #if !HAS_BUILTIN(MY_ALIAS_BUILTIN) || !HAS_FEATURE(MY_ALIAS_FEATURE)
83 #error Expansion should have occurred
84 #endif
86 #ifdef VERIFY
87 // expected-error@+1 {{builtin feature check macro requires a parenthesized identifier}}
88 #if __has_feature('x')
89 #endif
91 // The following are not identifiers:
92 _Static_assert(!__is_identifier("string"), "oops");
93 _Static_assert(!__is_identifier('c'), "oops");
94 _Static_assert(!__is_identifier(123), "oops");
95 _Static_assert(!__is_identifier(int), "oops");
97 // The following are:
98 _Static_assert(__is_identifier(abc /* comment */), "oops");
99 _Static_assert(__is_identifier /* comment */ (xyz), "oops");
101 // expected-error@+1 {{too few arguments}}
102 #if __is_identifier()
103 #endif
105 // expected-error@+1 {{too many arguments}}
106 #if __is_identifier(,())
107 #endif
109 // expected-error@+1 {{missing ')' after 'abc'}}
110 #if __is_identifier(abc xyz) // expected-note {{to match this '('}}
111 #endif
113 // expected-error@+1 {{missing ')' after 'abc'}}
114 #if __is_identifier(abc()) // expected-note {{to match this '('}}
115 #endif
117 // expected-error@+1 {{missing ')' after '.'}}
118 #if __is_identifier(.abc) // expected-note {{to match this '('}}
119 #endif
121 // expected-error@+1 {{nested parentheses not permitted in '__is_identifier'}}
122 #if __is_identifier((abc))
123 #endif
125 // expected-error@+1 {{missing '(' after '__is_identifier'}} expected-error@+1 {{expected value}}
126 #if __is_identifier
127 #endif
129 // expected-error@+1 {{unterminated}} expected-error@+1 {{expected value}}
130 #if __is_identifier(
131 #endif
133 #endif