1//===--- Features.def - Features and Extensions database --------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines features exposed via __has_feature and extensions exposed
10// via __has_extension. Users of this file must either define the FEATURE or
11// EXTENSION macros (or both) to make use of this information. Note that these
12// macros expect the following declarations to be available for the Predicate:
13//
14//   const LangOptions &LangOpts;
15//   const Preprocessor &PP;
16//
17// The Predicate field dictates the conditions under which the feature or
18// extension will be made available.
19//
20// FEATURE(...) should be used to advertise support for standard language
21// features, whereas EXTENSION(...) should be used for clang extensions. Note
22// that many of the identifiers in this file don't follow this rule for backward
23// compatibility reasons.
24//
25//===----------------------------------------------------------------------===//
26
27#if !defined(FEATURE) && !defined(EXTENSION)
28#  error Define either the FEATURE or EXTENSION macro to handle features
29#endif
30
31#ifndef FEATURE
32#define FEATURE(Name, Predicate)
33#endif
34
35#ifndef EXTENSION
36#define EXTENSION(Name, Predicate)
37#endif
38
39FEATURE(speculative_load_hardening, LangOpts.SpeculativeLoadHardening)
40FEATURE(address_sanitizer,
41        LangOpts.Sanitize.hasOneOf(SanitizerKind::Address |
42                                   SanitizerKind::KernelAddress))
43FEATURE(leak_sanitizer,
44        LangOpts.Sanitize.has(SanitizerKind::Leak))
45FEATURE(hwaddress_sanitizer,
46        LangOpts.Sanitize.hasOneOf(SanitizerKind::HWAddress |
47                                   SanitizerKind::KernelHWAddress))
48FEATURE(memtag_sanitizer, LangOpts.Sanitize.has(SanitizerKind::MemTag))
49FEATURE(xray_instrument, LangOpts.XRayInstrument)
50FEATURE(undefined_behavior_sanitizer,
51        LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
52FEATURE(assume_nonnull, true)
53FEATURE(attribute_analyzer_noreturn, true)
54FEATURE(attribute_availability, true)
55FEATURE(attribute_availability_with_message, true)
56FEATURE(attribute_availability_app_extension, true)
57FEATURE(attribute_availability_with_version_underscores, true)
58FEATURE(attribute_availability_tvos, true)
59FEATURE(attribute_availability_watchos, true)
60FEATURE(attribute_availability_with_strict, true)
61FEATURE(attribute_availability_with_replacement, true)
62FEATURE(attribute_availability_in_templates, true)
63FEATURE(attribute_availability_swift, true)
64FEATURE(attribute_cf_returns_not_retained, true)
65FEATURE(attribute_cf_returns_retained, true)
66FEATURE(attribute_cf_returns_on_parameters, true)
67FEATURE(attribute_deprecated_with_message, true)
68FEATURE(attribute_deprecated_with_replacement, true)
69FEATURE(attribute_ext_vector_type, true)
70FEATURE(attribute_ns_returns_not_retained, true)
71FEATURE(attribute_ns_returns_retained, true)
72FEATURE(attribute_ns_consumes_self, true)
73FEATURE(attribute_ns_consumed, true)
74FEATURE(attribute_cf_consumed, true)
75FEATURE(attribute_objc_ivar_unused, true)
76FEATURE(attribute_objc_method_family, true)
77FEATURE(attribute_overloadable, true)
78FEATURE(attribute_unavailable_with_message, true)
79FEATURE(attribute_unused_on_fields, true)
80FEATURE(attribute_diagnose_if_objc, true)
81FEATURE(blocks, LangOpts.Blocks)
82FEATURE(c_thread_safety_attributes, true)
83FEATURE(cxx_exceptions, LangOpts.CXXExceptions)
84FEATURE(cxx_rtti, LangOpts.RTTI &&LangOpts.RTTIData)
85FEATURE(enumerator_attributes, true)
86FEATURE(nullability, true)
87FEATURE(nullability_on_arrays, true)
88FEATURE(nullability_nullable_result, true)
89FEATURE(memory_sanitizer,
90        LangOpts.Sanitize.hasOneOf(SanitizerKind::Memory |
91                                   SanitizerKind::KernelMemory))
92FEATURE(thread_sanitizer, LangOpts.Sanitize.has(SanitizerKind::Thread))
93FEATURE(dataflow_sanitizer, LangOpts.Sanitize.has(SanitizerKind::DataFlow))
94FEATURE(scudo, LangOpts.Sanitize.hasOneOf(SanitizerKind::Scudo))
95// Objective-C features
96FEATURE(objc_arr, LangOpts.ObjCAutoRefCount) // FIXME: REMOVE?
97FEATURE(objc_arc, LangOpts.ObjCAutoRefCount)
98FEATURE(objc_arc_fields, true)
99FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
100FEATURE(objc_default_synthesize_properties, LangOpts.ObjC)
101FEATURE(objc_fixed_enum, LangOpts.ObjC)
102FEATURE(objc_instancetype, LangOpts.ObjC)
103FEATURE(objc_kindof, LangOpts.ObjC)
104FEATURE(objc_modules, LangOpts.ObjC && LangOpts.Modules)
105FEATURE(objc_nonfragile_abi, LangOpts.ObjCRuntime.isNonFragile())
106FEATURE(objc_property_explicit_atomic, true)
107FEATURE(objc_protocol_qualifier_mangling, true)
108FEATURE(objc_weak_class, LangOpts.ObjCRuntime.hasWeakClassImport())
109FEATURE(ownership_holds, true)
110FEATURE(ownership_returns, true)
111FEATURE(ownership_takes, true)
112FEATURE(objc_bool, true)
113FEATURE(objc_subscripting, LangOpts.ObjCRuntime.isNonFragile())
114FEATURE(objc_array_literals, LangOpts.ObjC)
115FEATURE(objc_dictionary_literals, LangOpts.ObjC)
116FEATURE(objc_boxed_expressions, LangOpts.ObjC)
117FEATURE(objc_boxed_nsvalue_expressions, LangOpts.ObjC)
118FEATURE(arc_cf_code_audited, true)
119FEATURE(objc_bridge_id, true)
120FEATURE(objc_bridge_id_on_typedefs, true)
121FEATURE(objc_generics, LangOpts.ObjC)
122FEATURE(objc_generics_variance, LangOpts.ObjC)
123FEATURE(objc_class_property, LangOpts.ObjC)
124FEATURE(objc_c_static_assert, LangOpts.C11)
125FEATURE(objc_cxx_static_assert, LangOpts.CPlusPlus11)
126EXTENSION(objc_c_static_assert, true)
127// C11 features
128FEATURE(c_alignas, LangOpts.C11)
129FEATURE(c_alignof, LangOpts.C11)
130FEATURE(c_atomic, LangOpts.C11)
131FEATURE(c_generic_selections, LangOpts.C11)
132FEATURE(c_static_assert, LangOpts.C11)
133FEATURE(c_thread_local, LangOpts.C11 &&PP.getTargetInfo().isTLSSupported())
134// C++11 features
135FEATURE(cxx_access_control_sfinae, LangOpts.CPlusPlus11)
136FEATURE(cxx_alias_templates, LangOpts.CPlusPlus11)
137FEATURE(cxx_alignas, LangOpts.CPlusPlus11)
138FEATURE(cxx_alignof, LangOpts.CPlusPlus11)
139FEATURE(cxx_atomic, LangOpts.CPlusPlus11)
140FEATURE(cxx_attributes, LangOpts.CPlusPlus11)
141FEATURE(cxx_auto_type, LangOpts.CPlusPlus11)
142FEATURE(cxx_constexpr, LangOpts.CPlusPlus11)
143FEATURE(cxx_constexpr_string_builtins, LangOpts.CPlusPlus11)
144FEATURE(cxx_decltype, LangOpts.CPlusPlus11)
145FEATURE(cxx_decltype_incomplete_return_types, LangOpts.CPlusPlus11)
146FEATURE(cxx_default_function_template_args, LangOpts.CPlusPlus11)
147FEATURE(cxx_defaulted_functions, LangOpts.CPlusPlus11)
148FEATURE(cxx_delegating_constructors, LangOpts.CPlusPlus11)
149FEATURE(cxx_deleted_functions, LangOpts.CPlusPlus11)
150FEATURE(cxx_explicit_conversions, LangOpts.CPlusPlus11)
151FEATURE(cxx_generalized_initializers, LangOpts.CPlusPlus11)
152FEATURE(cxx_implicit_moves, LangOpts.CPlusPlus11)
153FEATURE(cxx_inheriting_constructors, LangOpts.CPlusPlus11)
154FEATURE(cxx_inline_namespaces, LangOpts.CPlusPlus11)
155FEATURE(cxx_lambdas, LangOpts.CPlusPlus11)
156FEATURE(cxx_local_type_template_args, LangOpts.CPlusPlus11)
157FEATURE(cxx_nonstatic_member_init, LangOpts.CPlusPlus11)
158FEATURE(cxx_noexcept, LangOpts.CPlusPlus11)
159FEATURE(cxx_nullptr, LangOpts.CPlusPlus11)
160FEATURE(cxx_override_control, LangOpts.CPlusPlus11)
161FEATURE(cxx_range_for, LangOpts.CPlusPlus11)
162FEATURE(cxx_raw_string_literals, LangOpts.CPlusPlus11)
163FEATURE(cxx_reference_qualified_functions, LangOpts.CPlusPlus11)
164FEATURE(cxx_rvalue_references, LangOpts.CPlusPlus11)
165FEATURE(cxx_strong_enums, LangOpts.CPlusPlus11)
166FEATURE(cxx_static_assert, LangOpts.CPlusPlus11)
167FEATURE(cxx_thread_local,
168        LangOpts.CPlusPlus11 &&PP.getTargetInfo().isTLSSupported())
169FEATURE(cxx_trailing_return, LangOpts.CPlusPlus11)
170FEATURE(cxx_unicode_literals, LangOpts.CPlusPlus11)
171FEATURE(cxx_unrestricted_unions, LangOpts.CPlusPlus11)
172FEATURE(cxx_user_literals, LangOpts.CPlusPlus11)
173FEATURE(cxx_variadic_templates, LangOpts.CPlusPlus11)
174// C++14 features
175FEATURE(cxx_aggregate_nsdmi, LangOpts.CPlusPlus14)
176FEATURE(cxx_binary_literals, LangOpts.CPlusPlus14)
177FEATURE(cxx_contextual_conversions, LangOpts.CPlusPlus14)
178FEATURE(cxx_decltype_auto, LangOpts.CPlusPlus14)
179FEATURE(cxx_generic_lambdas, LangOpts.CPlusPlus14)
180FEATURE(cxx_init_captures, LangOpts.CPlusPlus14)
181FEATURE(cxx_relaxed_constexpr, LangOpts.CPlusPlus14)
182FEATURE(cxx_return_type_deduction, LangOpts.CPlusPlus14)
183FEATURE(cxx_variable_templates, LangOpts.CPlusPlus14)
184// NOTE: For features covered by SD-6, it is preferable to provide *only*
185// the SD-6 macro and not a __has_feature check.
186
187// C++ TSes
188// FEATURE(cxx_runtime_arrays, LangOpts.CPlusPlusTSArrays)
189// FEATURE(cxx_concepts, LangOpts.CPlusPlusTSConcepts)
190// FIXME: Should this be __has_feature or __has_extension?
191// FEATURE(raw_invocation_type, LangOpts.CPlusPlus)
192// Type traits
193// N.B. Additional type traits should not be added to the following list.
194// Instead, they should be detected by has_builtin.
195FEATURE(has_nothrow_assign, LangOpts.CPlusPlus)
196FEATURE(has_nothrow_copy, LangOpts.CPlusPlus)
197FEATURE(has_nothrow_constructor, LangOpts.CPlusPlus)
198FEATURE(has_trivial_assign, LangOpts.CPlusPlus)
199FEATURE(has_trivial_copy, LangOpts.CPlusPlus)
200FEATURE(has_trivial_constructor, LangOpts.CPlusPlus)
201FEATURE(has_trivial_destructor, LangOpts.CPlusPlus)
202FEATURE(has_virtual_destructor, LangOpts.CPlusPlus)
203FEATURE(is_abstract, LangOpts.CPlusPlus)
204FEATURE(is_base_of, LangOpts.CPlusPlus)
205FEATURE(is_class, LangOpts.CPlusPlus)
206FEATURE(is_constructible, LangOpts.CPlusPlus)
207FEATURE(is_convertible_to, LangOpts.CPlusPlus)
208FEATURE(is_empty, LangOpts.CPlusPlus)
209FEATURE(is_enum, LangOpts.CPlusPlus)
210FEATURE(is_final, LangOpts.CPlusPlus)
211FEATURE(is_literal, LangOpts.CPlusPlus)
212FEATURE(is_standard_layout, LangOpts.CPlusPlus)
213FEATURE(is_pod, LangOpts.CPlusPlus)
214FEATURE(is_polymorphic, LangOpts.CPlusPlus)
215FEATURE(is_sealed, LangOpts.CPlusPlus &&LangOpts.MicrosoftExt)
216FEATURE(is_trivial, LangOpts.CPlusPlus)
217FEATURE(is_trivially_assignable, LangOpts.CPlusPlus)
218FEATURE(is_trivially_constructible, LangOpts.CPlusPlus)
219FEATURE(is_trivially_copyable, LangOpts.CPlusPlus)
220FEATURE(is_union, LangOpts.CPlusPlus)
221FEATURE(modules, LangOpts.Modules)
222FEATURE(safe_stack, LangOpts.Sanitize.has(SanitizerKind::SafeStack))
223FEATURE(shadow_call_stack,
224        LangOpts.Sanitize.has(SanitizerKind::ShadowCallStack))
225FEATURE(tls, PP.getTargetInfo().isTLSSupported())
226FEATURE(underlying_type, LangOpts.CPlusPlus)
227
228// C11 features supported by other languages as extensions.
229EXTENSION(c_alignas, true)
230EXTENSION(c_alignof, true)
231EXTENSION(c_atomic, true)
232EXTENSION(c_generic_selections, true)
233EXTENSION(c_static_assert, true)
234EXTENSION(c_thread_local, PP.getTargetInfo().isTLSSupported())
235// C++11 features supported by other languages as extensions.
236EXTENSION(cxx_atomic, LangOpts.CPlusPlus)
237EXTENSION(cxx_deleted_functions, LangOpts.CPlusPlus)
238EXTENSION(cxx_explicit_conversions, LangOpts.CPlusPlus)
239EXTENSION(cxx_inline_namespaces, LangOpts.CPlusPlus)
240EXTENSION(cxx_local_type_template_args, LangOpts.CPlusPlus)
241EXTENSION(cxx_nonstatic_member_init, LangOpts.CPlusPlus)
242EXTENSION(cxx_override_control, LangOpts.CPlusPlus)
243EXTENSION(cxx_range_for, LangOpts.CPlusPlus)
244EXTENSION(cxx_reference_qualified_functions, LangOpts.CPlusPlus)
245EXTENSION(cxx_rvalue_references, LangOpts.CPlusPlus)
246EXTENSION(cxx_variadic_templates, LangOpts.CPlusPlus)
247EXTENSION(cxx_fixed_enum, true)
248// C++14 features supported by other languages as extensions.
249EXTENSION(cxx_binary_literals, true)
250EXTENSION(cxx_init_captures, LangOpts.CPlusPlus11)
251EXTENSION(cxx_variable_templates, LangOpts.CPlusPlus)
252// Miscellaneous language extensions
253EXTENSION(overloadable_unmarked, true)
254EXTENSION(pragma_clang_attribute_namespaces, true)
255EXTENSION(pragma_clang_attribute_external_declaration, true)
256EXTENSION(gnu_asm, LangOpts.GNUAsm)
257EXTENSION(gnu_asm_goto_with_outputs, LangOpts.GNUAsm)
258EXTENSION(matrix_types, LangOpts.MatrixTypes)
259
260FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && LangOpts.RelativeCXXABIVTables)
261
262#undef EXTENSION
263#undef FEATURE
264