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(coverage_sanitizer, LangOpts.SanitizeCoverage)
53FEATURE(assume_nonnull, true)
54FEATURE(attribute_analyzer_noreturn, true)
55FEATURE(attribute_availability, true)
56FEATURE(attribute_availability_with_message, true)
57FEATURE(attribute_availability_app_extension, true)
58FEATURE(attribute_availability_with_version_underscores, true)
59FEATURE(attribute_availability_tvos, true)
60FEATURE(attribute_availability_watchos, true)
61FEATURE(attribute_availability_with_strict, true)
62FEATURE(attribute_availability_with_replacement, true)
63FEATURE(attribute_availability_in_templates, true)
64FEATURE(attribute_availability_swift, true)
65FEATURE(attribute_cf_returns_not_retained, true)
66FEATURE(attribute_cf_returns_retained, true)
67FEATURE(attribute_cf_returns_on_parameters, true)
68FEATURE(attribute_deprecated_with_message, true)
69FEATURE(attribute_deprecated_with_replacement, true)
70FEATURE(attribute_ext_vector_type, true)
71FEATURE(attribute_ns_returns_not_retained, true)
72FEATURE(attribute_ns_returns_retained, true)
73FEATURE(attribute_ns_consumes_self, true)
74FEATURE(attribute_ns_consumed, true)
75FEATURE(attribute_cf_consumed, true)
76FEATURE(attribute_objc_ivar_unused, true)
77FEATURE(attribute_objc_method_family, true)
78FEATURE(attribute_overloadable, true)
79FEATURE(attribute_unavailable_with_message, true)
80FEATURE(attribute_unused_on_fields, true)
81FEATURE(attribute_diagnose_if_objc, true)
82FEATURE(blocks, LangOpts.Blocks)
83FEATURE(c_thread_safety_attributes, true)
84FEATURE(cxx_exceptions, LangOpts.CXXExceptions)
85FEATURE(cxx_rtti, LangOpts.RTTI &&LangOpts.RTTIData)
86FEATURE(enumerator_attributes, true)
87FEATURE(nullability, true)
88FEATURE(nullability_on_arrays, true)
89FEATURE(nullability_nullable_result, true)
90FEATURE(memory_sanitizer,
91        LangOpts.Sanitize.hasOneOf(SanitizerKind::Memory |
92                                   SanitizerKind::KernelMemory))
93FEATURE(thread_sanitizer, LangOpts.Sanitize.has(SanitizerKind::Thread))
94FEATURE(dataflow_sanitizer, LangOpts.Sanitize.has(SanitizerKind::DataFlow))
95FEATURE(scudo, LangOpts.Sanitize.hasOneOf(SanitizerKind::Scudo))
96FEATURE(swiftasynccc,
97  PP.getTargetInfo().checkCallingConvention(CC_SwiftAsync) ==
98  clang::TargetInfo::CCCR_OK)
99// Objective-C features
100FEATURE(objc_arr, LangOpts.ObjCAutoRefCount) // FIXME: REMOVE?
101FEATURE(objc_arc, LangOpts.ObjCAutoRefCount)
102FEATURE(objc_arc_fields, true)
103FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
104FEATURE(objc_default_synthesize_properties, LangOpts.ObjC)
105FEATURE(objc_fixed_enum, LangOpts.ObjC)
106FEATURE(objc_instancetype, LangOpts.ObjC)
107FEATURE(objc_kindof, LangOpts.ObjC)
108FEATURE(objc_modules, LangOpts.ObjC && LangOpts.Modules)
109FEATURE(objc_nonfragile_abi, LangOpts.ObjCRuntime.isNonFragile())
110FEATURE(objc_property_explicit_atomic, true)
111FEATURE(objc_protocol_qualifier_mangling, true)
112FEATURE(objc_weak_class, LangOpts.ObjCRuntime.hasWeakClassImport())
113FEATURE(ownership_holds, true)
114FEATURE(ownership_returns, true)
115FEATURE(ownership_takes, true)
116FEATURE(objc_bool, true)
117FEATURE(objc_subscripting, LangOpts.ObjCRuntime.isNonFragile())
118FEATURE(objc_array_literals, LangOpts.ObjC)
119FEATURE(objc_dictionary_literals, LangOpts.ObjC)
120FEATURE(objc_boxed_expressions, LangOpts.ObjC)
121FEATURE(objc_boxed_nsvalue_expressions, LangOpts.ObjC)
122FEATURE(arc_cf_code_audited, true)
123FEATURE(objc_bridge_id, true)
124FEATURE(objc_bridge_id_on_typedefs, true)
125FEATURE(objc_generics, LangOpts.ObjC)
126FEATURE(objc_generics_variance, LangOpts.ObjC)
127FEATURE(objc_class_property, LangOpts.ObjC)
128FEATURE(objc_c_static_assert, LangOpts.C11)
129FEATURE(objc_cxx_static_assert, LangOpts.CPlusPlus11)
130EXTENSION(objc_c_static_assert, true)
131// C11 features
132FEATURE(c_alignas, LangOpts.C11)
133FEATURE(c_alignof, LangOpts.C11)
134FEATURE(c_atomic, LangOpts.C11)
135FEATURE(c_generic_selections, LangOpts.C11)
136FEATURE(c_static_assert, LangOpts.C11)
137FEATURE(c_thread_local, LangOpts.C11 &&PP.getTargetInfo().isTLSSupported())
138// C++11 features
139FEATURE(cxx_access_control_sfinae, LangOpts.CPlusPlus11)
140FEATURE(cxx_alias_templates, LangOpts.CPlusPlus11)
141FEATURE(cxx_alignas, LangOpts.CPlusPlus11)
142FEATURE(cxx_alignof, LangOpts.CPlusPlus11)
143FEATURE(cxx_atomic, LangOpts.CPlusPlus11)
144FEATURE(cxx_attributes, LangOpts.CPlusPlus11)
145FEATURE(cxx_auto_type, LangOpts.CPlusPlus11)
146FEATURE(cxx_constexpr, LangOpts.CPlusPlus11)
147FEATURE(cxx_constexpr_string_builtins, LangOpts.CPlusPlus11)
148FEATURE(cxx_decltype, LangOpts.CPlusPlus11)
149FEATURE(cxx_decltype_incomplete_return_types, LangOpts.CPlusPlus11)
150FEATURE(cxx_default_function_template_args, LangOpts.CPlusPlus11)
151FEATURE(cxx_defaulted_functions, LangOpts.CPlusPlus11)
152FEATURE(cxx_delegating_constructors, LangOpts.CPlusPlus11)
153FEATURE(cxx_deleted_functions, LangOpts.CPlusPlus11)
154FEATURE(cxx_explicit_conversions, LangOpts.CPlusPlus11)
155FEATURE(cxx_generalized_initializers, LangOpts.CPlusPlus11)
156FEATURE(cxx_implicit_moves, LangOpts.CPlusPlus11)
157FEATURE(cxx_inheriting_constructors, LangOpts.CPlusPlus11)
158FEATURE(cxx_inline_namespaces, LangOpts.CPlusPlus11)
159FEATURE(cxx_lambdas, LangOpts.CPlusPlus11)
160FEATURE(cxx_local_type_template_args, LangOpts.CPlusPlus11)
161FEATURE(cxx_nonstatic_member_init, LangOpts.CPlusPlus11)
162FEATURE(cxx_noexcept, LangOpts.CPlusPlus11)
163FEATURE(cxx_nullptr, LangOpts.CPlusPlus11)
164FEATURE(cxx_override_control, LangOpts.CPlusPlus11)
165FEATURE(cxx_range_for, LangOpts.CPlusPlus11)
166FEATURE(cxx_raw_string_literals, LangOpts.CPlusPlus11)
167FEATURE(cxx_reference_qualified_functions, LangOpts.CPlusPlus11)
168FEATURE(cxx_rvalue_references, LangOpts.CPlusPlus11)
169FEATURE(cxx_strong_enums, LangOpts.CPlusPlus11)
170FEATURE(cxx_static_assert, LangOpts.CPlusPlus11)
171FEATURE(cxx_thread_local,
172        LangOpts.CPlusPlus11 &&PP.getTargetInfo().isTLSSupported())
173FEATURE(cxx_trailing_return, LangOpts.CPlusPlus11)
174FEATURE(cxx_unicode_literals, LangOpts.CPlusPlus11)
175FEATURE(cxx_unrestricted_unions, LangOpts.CPlusPlus11)
176FEATURE(cxx_user_literals, LangOpts.CPlusPlus11)
177FEATURE(cxx_variadic_templates, LangOpts.CPlusPlus11)
178// C++14 features
179FEATURE(cxx_aggregate_nsdmi, LangOpts.CPlusPlus14)
180FEATURE(cxx_binary_literals, LangOpts.CPlusPlus14)
181FEATURE(cxx_contextual_conversions, LangOpts.CPlusPlus14)
182FEATURE(cxx_decltype_auto, LangOpts.CPlusPlus14)
183FEATURE(cxx_generic_lambdas, LangOpts.CPlusPlus14)
184FEATURE(cxx_init_captures, LangOpts.CPlusPlus14)
185FEATURE(cxx_relaxed_constexpr, LangOpts.CPlusPlus14)
186FEATURE(cxx_return_type_deduction, LangOpts.CPlusPlus14)
187FEATURE(cxx_variable_templates, LangOpts.CPlusPlus14)
188// NOTE: For features covered by SD-6, it is preferable to provide *only*
189// the SD-6 macro and not a __has_feature check.
190
191// C++ TSes
192// FEATURE(cxx_runtime_arrays, LangOpts.CPlusPlusTSArrays)
193// FEATURE(cxx_concepts, LangOpts.CPlusPlusTSConcepts)
194// FIXME: Should this be __has_feature or __has_extension?
195// FEATURE(raw_invocation_type, LangOpts.CPlusPlus)
196// Type traits
197// N.B. Additional type traits should not be added to the following list.
198// Instead, they should be detected by has_builtin.
199FEATURE(has_nothrow_assign, LangOpts.CPlusPlus)
200FEATURE(has_nothrow_copy, LangOpts.CPlusPlus)
201FEATURE(has_nothrow_constructor, LangOpts.CPlusPlus)
202FEATURE(has_trivial_assign, LangOpts.CPlusPlus)
203FEATURE(has_trivial_copy, LangOpts.CPlusPlus)
204FEATURE(has_trivial_constructor, LangOpts.CPlusPlus)
205FEATURE(has_trivial_destructor, LangOpts.CPlusPlus)
206FEATURE(has_virtual_destructor, LangOpts.CPlusPlus)
207FEATURE(is_abstract, LangOpts.CPlusPlus)
208FEATURE(is_base_of, LangOpts.CPlusPlus)
209FEATURE(is_class, LangOpts.CPlusPlus)
210FEATURE(is_constructible, LangOpts.CPlusPlus)
211FEATURE(is_convertible_to, LangOpts.CPlusPlus)
212FEATURE(is_empty, LangOpts.CPlusPlus)
213FEATURE(is_enum, LangOpts.CPlusPlus)
214FEATURE(is_final, LangOpts.CPlusPlus)
215FEATURE(is_literal, LangOpts.CPlusPlus)
216FEATURE(is_standard_layout, LangOpts.CPlusPlus)
217FEATURE(is_pod, LangOpts.CPlusPlus)
218FEATURE(is_polymorphic, LangOpts.CPlusPlus)
219FEATURE(is_sealed, LangOpts.CPlusPlus &&LangOpts.MicrosoftExt)
220FEATURE(is_trivial, LangOpts.CPlusPlus)
221FEATURE(is_trivially_assignable, LangOpts.CPlusPlus)
222FEATURE(is_trivially_constructible, LangOpts.CPlusPlus)
223FEATURE(is_trivially_copyable, LangOpts.CPlusPlus)
224FEATURE(is_union, LangOpts.CPlusPlus)
225FEATURE(modules, LangOpts.Modules)
226FEATURE(safe_stack, LangOpts.Sanitize.has(SanitizerKind::SafeStack))
227FEATURE(shadow_call_stack,
228        LangOpts.Sanitize.has(SanitizerKind::ShadowCallStack))
229FEATURE(tls, PP.getTargetInfo().isTLSSupported())
230FEATURE(underlying_type, LangOpts.CPlusPlus)
231
232// C11 features supported by other languages as extensions.
233EXTENSION(c_alignas, true)
234EXTENSION(c_alignof, true)
235EXTENSION(c_atomic, true)
236EXTENSION(c_generic_selections, true)
237EXTENSION(c_static_assert, true)
238EXTENSION(c_thread_local, PP.getTargetInfo().isTLSSupported())
239// C++11 features supported by other languages as extensions.
240EXTENSION(cxx_atomic, LangOpts.CPlusPlus)
241EXTENSION(cxx_deleted_functions, LangOpts.CPlusPlus)
242EXTENSION(cxx_explicit_conversions, LangOpts.CPlusPlus)
243EXTENSION(cxx_inline_namespaces, LangOpts.CPlusPlus)
244EXTENSION(cxx_local_type_template_args, LangOpts.CPlusPlus)
245EXTENSION(cxx_nonstatic_member_init, LangOpts.CPlusPlus)
246EXTENSION(cxx_override_control, LangOpts.CPlusPlus)
247EXTENSION(cxx_range_for, LangOpts.CPlusPlus)
248EXTENSION(cxx_reference_qualified_functions, LangOpts.CPlusPlus)
249EXTENSION(cxx_rvalue_references, LangOpts.CPlusPlus)
250EXTENSION(cxx_variadic_templates, LangOpts.CPlusPlus)
251EXTENSION(cxx_fixed_enum, true)
252// C++14 features supported by other languages as extensions.
253EXTENSION(cxx_binary_literals, true)
254EXTENSION(cxx_init_captures, LangOpts.CPlusPlus11)
255EXTENSION(cxx_variable_templates, LangOpts.CPlusPlus)
256// Miscellaneous language extensions
257EXTENSION(overloadable_unmarked, true)
258EXTENSION(pragma_clang_attribute_namespaces, true)
259EXTENSION(pragma_clang_attribute_external_declaration, true)
260EXTENSION(statement_attributes_with_gnu_syntax, true)
261EXTENSION(gnu_asm, LangOpts.GNUAsm)
262EXTENSION(gnu_asm_goto_with_outputs, LangOpts.GNUAsm)
263EXTENSION(matrix_types, LangOpts.MatrixTypes)
264EXTENSION(matrix_types_scalar_division, true)
265EXTENSION(cxx_attributes_on_using_declarations, LangOpts.CPlusPlus11)
266
267FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && LangOpts.RelativeCXXABIVTables)
268
269#undef EXTENSION
270#undef FEATURE
271