1 | //===- LangOptions.h - C Language Family Language Options -------*- 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 | /// \file |
10 | /// Defines the clang::LangOptions interface. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #ifndef LLVM_CLANG_BASIC_LANGOPTIONS_H |
15 | #define LLVM_CLANG_BASIC_LANGOPTIONS_H |
16 | |
17 | #include "clang/Basic/CFProtectionOptions.h" |
18 | #include "clang/Basic/CommentOptions.h" |
19 | #include "clang/Basic/LLVM.h" |
20 | #include "clang/Basic/LangStandard.h" |
21 | #include "clang/Basic/ObjCRuntime.h" |
22 | #include "clang/Basic/Sanitizers.h" |
23 | #include "clang/Basic/TargetCXXABI.h" |
24 | #include "clang/Basic/Visibility.h" |
25 | #include "llvm/ADT/FloatingPointMode.h" |
26 | #include "llvm/ADT/StringRef.h" |
27 | #include "llvm/TargetParser/Triple.h" |
28 | #include <optional> |
29 | #include <string> |
30 | #include <vector> |
31 | |
32 | namespace clang { |
33 | |
34 | /// In the Microsoft ABI, this controls the placement of virtual displacement |
35 | /// members used to implement virtual inheritance. |
36 | enum class MSVtorDispMode { Never, ForVBaseOverride, ForVFTable }; |
37 | |
38 | /// Shader programs run in specific pipeline stages. |
39 | /// The order of these values matters, and must be kept in sync with the |
40 | /// Triple Environment enum in llvm::Triple. The ordering is enforced in |
41 | /// static_asserts in Triple.cpp and in clang/Basic/HLSLRuntime.h. |
42 | enum class ShaderStage { |
43 | Pixel = 0, |
44 | Vertex, |
45 | Geometry, |
46 | Hull, |
47 | Domain, |
48 | Compute, |
49 | Library, |
50 | RayGeneration, |
51 | Intersection, |
52 | AnyHit, |
53 | ClosestHit, |
54 | Miss, |
55 | Callable, |
56 | Mesh, |
57 | Amplification, |
58 | Invalid, |
59 | }; |
60 | |
61 | enum class PointerAuthenticationMode : unsigned { |
62 | None, |
63 | Strip, |
64 | SignAndStrip, |
65 | SignAndAuth |
66 | }; |
67 | |
68 | /// Bitfields of LangOptions, split out from LangOptions in order to ensure that |
69 | /// this large collection of bitfields is a trivial class type. |
70 | class LangOptionsBase { |
71 | friend class CompilerInvocation; |
72 | friend class CompilerInvocationBase; |
73 | |
74 | public: |
75 | using Visibility = clang::Visibility; |
76 | using RoundingMode = llvm::RoundingMode; |
77 | using CFBranchLabelSchemeKind = clang::CFBranchLabelSchemeKind; |
78 | |
79 | enum GCMode { NonGC, GCOnly, HybridGC }; |
80 | enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq }; |
81 | |
82 | // Automatic variables live on the stack, and when trivial they're usually |
83 | // uninitialized because it's undefined behavior to use them without |
84 | // initializing them. |
85 | enum class TrivialAutoVarInitKind { Uninitialized, Zero, Pattern }; |
86 | |
87 | enum SignedOverflowBehaviorTy { |
88 | // Default C standard behavior. |
89 | SOB_Undefined, |
90 | |
91 | // -fwrapv |
92 | SOB_Defined, |
93 | |
94 | // -ftrapv |
95 | SOB_Trapping |
96 | }; |
97 | |
98 | // FIXME: Unify with TUKind. |
99 | enum CompilingModuleKind { |
100 | /// Not compiling a module interface at all. |
101 | CMK_None, |
102 | |
103 | /// Compiling a module from a module map. |
104 | CMK_ModuleMap, |
105 | |
106 | /// Compiling a module header unit. |
107 | , |
108 | |
109 | /// Compiling a C++ modules interface unit. |
110 | CMK_ModuleInterface, |
111 | }; |
112 | |
113 | enum PragmaMSPointersToMembersKind { |
114 | PPTMK_BestCase, |
115 | PPTMK_FullGeneralitySingleInheritance, |
116 | PPTMK_FullGeneralityMultipleInheritance, |
117 | PPTMK_FullGeneralityVirtualInheritance |
118 | }; |
119 | |
120 | using MSVtorDispMode = clang::MSVtorDispMode; |
121 | |
122 | enum DefaultCallingConvention { |
123 | DCC_None, |
124 | DCC_CDecl, |
125 | DCC_FastCall, |
126 | DCC_StdCall, |
127 | DCC_VectorCall, |
128 | DCC_RegCall, |
129 | DCC_RtdCall |
130 | }; |
131 | |
132 | enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off }; |
133 | |
134 | // Corresponds to _MSC_VER |
135 | enum MSVCMajorVersion { |
136 | MSVC2010 = 1600, |
137 | MSVC2012 = 1700, |
138 | MSVC2013 = 1800, |
139 | MSVC2015 = 1900, |
140 | MSVC2017 = 1910, |
141 | MSVC2017_5 = 1912, |
142 | MSVC2017_7 = 1914, |
143 | MSVC2019 = 1920, |
144 | MSVC2019_5 = 1925, |
145 | MSVC2019_8 = 1928, |
146 | MSVC2022_3 = 1933, |
147 | MSVC2022_9 = 1939, |
148 | }; |
149 | |
150 | enum SYCLMajorVersion { |
151 | SYCL_None, |
152 | SYCL_2017, |
153 | SYCL_2020, |
154 | // The "default" SYCL version to be used when none is specified on the |
155 | // frontend command line. |
156 | SYCL_Default = SYCL_2020 |
157 | }; |
158 | |
159 | enum HLSLLangStd { |
160 | HLSL_Unset = 0, |
161 | HLSL_2015 = 2015, |
162 | HLSL_2016 = 2016, |
163 | HLSL_2017 = 2017, |
164 | HLSL_2018 = 2018, |
165 | HLSL_2021 = 2021, |
166 | HLSL_202x = 2028, |
167 | HLSL_202y = 2029, |
168 | }; |
169 | |
170 | /// Clang versions with different platform ABI conformance. |
171 | enum class ClangABI { |
172 | /// Attempt to be ABI-compatible with code generated by Clang 3.8.x |
173 | /// (SVN r257626). This causes <1 x long long> to be passed in an |
174 | /// integer register instead of an SSE register on x64_64. |
175 | Ver3_8, |
176 | |
177 | /// Attempt to be ABI-compatible with code generated by Clang 4.0.x |
178 | /// (SVN r291814). This causes move operations to be ignored when |
179 | /// determining whether a class type can be passed or returned directly. |
180 | Ver4, |
181 | |
182 | /// Attempt to be ABI-compatible with code generated by Clang 6.0.x |
183 | /// (SVN r321711). This causes determination of whether a type is |
184 | /// standard-layout to ignore collisions between empty base classes |
185 | /// and between base classes and member subobjects, which affects |
186 | /// whether we reuse base class tail padding in some ABIs. |
187 | Ver6, |
188 | |
189 | /// Attempt to be ABI-compatible with code generated by Clang 7.0.x |
190 | /// (SVN r338536). This causes alignof (C++) and _Alignof (C11) to be |
191 | /// compatible with __alignof (i.e., return the preferred alignment) |
192 | /// rather than returning the required alignment. |
193 | Ver7, |
194 | |
195 | /// Attempt to be ABI-compatible with code generated by Clang 9.0.x |
196 | /// (SVN r351319). This causes vectors of __int128 to be passed in memory |
197 | /// instead of passing in multiple scalar registers on x86_64 on Linux and |
198 | /// NetBSD. |
199 | Ver9, |
200 | |
201 | /// Attempt to be ABI-compatible with code generated by Clang 11.0.x |
202 | /// (git 2e10b7a39b93). This causes clang to pass unions with a 256-bit |
203 | /// vector member on the stack instead of using registers, to not properly |
204 | /// mangle substitutions for template names in some cases, and to mangle |
205 | /// declaration template arguments without a cast to the parameter type |
206 | /// even when that can lead to mangling collisions. |
207 | Ver11, |
208 | |
209 | /// Attempt to be ABI-compatible with code generated by Clang 12.0.x |
210 | /// (git 8e464dd76bef). This causes clang to mangle lambdas within |
211 | /// global-scope inline variables incorrectly. |
212 | Ver12, |
213 | |
214 | /// Attempt to be ABI-compatible with code generated by Clang 14.0.x. |
215 | /// This causes clang to: |
216 | /// - mangle dependent nested names incorrectly. |
217 | /// - make trivial only those defaulted copy constructors with a |
218 | /// parameter-type-list equivalent to the parameter-type-list of an |
219 | /// implicit declaration. |
220 | Ver14, |
221 | |
222 | /// Attempt to be ABI-compatible with code generated by Clang 15.0.x. |
223 | /// This causes clang to: |
224 | /// - Reverse the implementation for DR692, DR1395 and DR1432. |
225 | /// - pack non-POD members of packed structs. |
226 | /// - consider classes with defaulted special member functions non-pod. |
227 | Ver15, |
228 | |
229 | /// Attempt to be ABI-compatible with code generated by Clang 17.0.x. |
230 | /// This causes clang to revert some fixes to its implementation of the |
231 | /// Itanium name mangling scheme, with the consequence that overloaded |
232 | /// function templates are mangled the same if they differ only by: |
233 | /// - constraints |
234 | /// - whether a non-type template parameter has a deduced type |
235 | /// - the parameter list of a template template parameter |
236 | Ver17, |
237 | |
238 | /// Attempt to be ABI-compatible with code generated by Clang 18.0.x. |
239 | /// This causes clang to revert some fixes to the mangling of lambdas |
240 | /// in the initializers of members of local classes. |
241 | Ver18, |
242 | |
243 | /// Attempt to be ABI-compatible with code generated by Clang 19.0.x. |
244 | /// This causes clang to: |
245 | /// - Incorrectly mangle the 'base type' substitutions of the CXX |
246 | /// construction vtable because it hasn't added 'type' as a substitution. |
247 | /// - Skip mangling enclosing class templates of member-like friend |
248 | /// function templates. |
249 | /// - Ignore empty struct arguments in C++ mode for ARM, instead of |
250 | /// passing them as if they had a size of 1 byte. |
251 | Ver19, |
252 | |
253 | /// Attempt to be ABI-compatible with code generated by Clang 20.0.x. |
254 | /// This causes clang to: |
255 | /// - Incorrectly return C++ records in AVX registers on x86_64. |
256 | Ver20, |
257 | |
258 | /// Conform to the underlying platform's C and C++ ABIs as closely |
259 | /// as we can. |
260 | Latest |
261 | }; |
262 | |
263 | enum class CoreFoundationABI { |
264 | /// No interoperability ABI has been specified |
265 | Unspecified, |
266 | /// CoreFoundation does not have any language interoperability |
267 | Standalone, |
268 | /// Interoperability with the ObjectiveC runtime |
269 | ObjectiveC, |
270 | /// Interoperability with the latest known version of the Swift runtime |
271 | Swift, |
272 | /// Interoperability with the Swift 5.0 runtime |
273 | Swift5_0, |
274 | /// Interoperability with the Swift 4.2 runtime |
275 | Swift4_2, |
276 | /// Interoperability with the Swift 4.1 runtime |
277 | Swift4_1, |
278 | }; |
279 | |
280 | enum FPModeKind { |
281 | // Disable the floating point pragma |
282 | FPM_Off, |
283 | |
284 | // Enable the floating point pragma |
285 | FPM_On, |
286 | |
287 | // Aggressively fuse FP ops (E.g. FMA) disregarding pragmas. |
288 | FPM_Fast, |
289 | |
290 | // Aggressively fuse FP ops and honor pragmas. |
291 | FPM_FastHonorPragmas |
292 | }; |
293 | |
294 | /// Possible floating point exception behavior. |
295 | enum FPExceptionModeKind { |
296 | /// Assume that floating-point exceptions are masked. |
297 | FPE_Ignore, |
298 | /// Transformations do not cause new exceptions but may hide some. |
299 | FPE_MayTrap, |
300 | /// Strictly preserve the floating-point exception semantics. |
301 | FPE_Strict, |
302 | /// Used internally to represent initial unspecified value. |
303 | FPE_Default |
304 | }; |
305 | |
306 | /// Possible float expression evaluation method choices. |
307 | enum FPEvalMethodKind { |
308 | /// The evaluation method cannot be determined or is inconsistent for this |
309 | /// target. |
310 | FEM_Indeterminable = -1, |
311 | /// Use the declared type for fp arithmetic. |
312 | FEM_Source = 0, |
313 | /// Use the type double for fp arithmetic. |
314 | FEM_Double = 1, |
315 | /// Use extended type for fp arithmetic. |
316 | FEM_Extended = 2, |
317 | /// Used only for FE option processing; this is only used to indicate that |
318 | /// the user did not specify an explicit evaluation method on the command |
319 | /// line and so the target should be queried for its default evaluation |
320 | /// method instead. |
321 | FEM_UnsetOnCommandLine = 3 |
322 | }; |
323 | |
324 | enum ExcessPrecisionKind { FPP_Standard, FPP_Fast, FPP_None }; |
325 | |
326 | /// Possible exception handling behavior. |
327 | enum class ExceptionHandlingKind { None, SjLj, WinEH, DwarfCFI, Wasm }; |
328 | |
329 | enum class LaxVectorConversionKind { |
330 | /// Permit no implicit vector bitcasts. |
331 | None, |
332 | /// Permit vector bitcasts between integer vectors with different numbers |
333 | /// of elements but the same total bit-width. |
334 | Integer, |
335 | /// Permit vector bitcasts between all vectors with the same total |
336 | /// bit-width. |
337 | All, |
338 | }; |
339 | |
340 | enum class AltivecSrcCompatKind { |
341 | // All vector compares produce scalars except vector pixel and vector bool. |
342 | // The types vector pixel and vector bool return vector results. |
343 | Mixed, |
344 | // All vector compares produce vector results as in GCC. |
345 | GCC, |
346 | // All vector compares produce scalars as in XL. |
347 | XL, |
348 | // Default clang behaviour. |
349 | Default = Mixed, |
350 | }; |
351 | |
352 | enum class SignReturnAddressScopeKind { |
353 | /// No signing for any function. |
354 | None, |
355 | /// Sign the return address of functions that spill LR. |
356 | NonLeaf, |
357 | /// Sign the return address of all functions, |
358 | All |
359 | }; |
360 | |
361 | enum class SignReturnAddressKeyKind { |
362 | /// Return address signing uses APIA key. |
363 | AKey, |
364 | /// Return address signing uses APIB key. |
365 | BKey |
366 | }; |
367 | |
368 | enum class ThreadModelKind { |
369 | /// POSIX Threads. |
370 | POSIX, |
371 | /// Single Threaded Environment. |
372 | Single |
373 | }; |
374 | |
375 | enum class ExtendArgsKind { |
376 | /// Integer arguments are sign or zero extended to 32/64 bits |
377 | /// during default argument promotions. |
378 | ExtendTo32, |
379 | ExtendTo64 |
380 | }; |
381 | |
382 | enum class GPUDefaultStreamKind { |
383 | /// Legacy default stream |
384 | Legacy, |
385 | /// Per-thread default stream |
386 | PerThread, |
387 | }; |
388 | |
389 | /// Exclude certain code patterns from being instrumented by arithmetic |
390 | /// overflow sanitizers |
391 | enum OverflowPatternExclusionKind { |
392 | /// Don't exclude any overflow patterns from sanitizers |
393 | None = 1 << 0, |
394 | /// Exclude all overflow patterns (below) |
395 | All = 1 << 1, |
396 | /// if (a + b < a) |
397 | AddSignedOverflowTest = 1 << 2, |
398 | /// if (a + b < a) |
399 | AddUnsignedOverflowTest = 1 << 3, |
400 | /// -1UL |
401 | NegUnsignedConst = 1 << 4, |
402 | /// while (count--) |
403 | PostDecrInWhile = 1 << 5, |
404 | }; |
405 | |
406 | enum class DefaultVisiblityExportMapping { |
407 | None, |
408 | /// map only explicit default visibilities to exported |
409 | Explicit, |
410 | /// map all default visibilities to exported |
411 | All, |
412 | }; |
413 | |
414 | enum class VisibilityForcedKinds { |
415 | /// Force hidden visibility |
416 | ForceHidden, |
417 | /// Force protected visibility |
418 | ForceProtected, |
419 | /// Force default visibility |
420 | ForceDefault, |
421 | /// Don't alter the visibility |
422 | Source, |
423 | }; |
424 | |
425 | enum class VisibilityFromDLLStorageClassKinds { |
426 | /// Keep the IR-gen assigned visibility. |
427 | Keep, |
428 | /// Override the IR-gen assigned visibility with default visibility. |
429 | Default, |
430 | /// Override the IR-gen assigned visibility with hidden visibility. |
431 | Hidden, |
432 | /// Override the IR-gen assigned visibility with protected visibility. |
433 | Protected, |
434 | }; |
435 | |
436 | enum class StrictFlexArraysLevelKind { |
437 | /// Any trailing array member is a FAM. |
438 | Default = 0, |
439 | /// Any trailing array member of undefined, 0, or 1 size is a FAM. |
440 | OneZeroOrIncomplete = 1, |
441 | /// Any trailing array member of undefined or 0 size is a FAM. |
442 | ZeroOrIncomplete = 2, |
443 | /// Any trailing array member of undefined size is a FAM. |
444 | IncompleteOnly = 3, |
445 | }; |
446 | |
447 | /// Controls the various implementations for complex multiplication and |
448 | // division. |
449 | enum ComplexRangeKind { |
450 | /// Implementation of complex division and multiplication using a call to |
451 | /// runtime library functions(generally the case, but the BE might |
452 | /// sometimes replace the library call if it knows enough about the |
453 | /// potential range of the inputs). Overflow and non-finite values are |
454 | /// handled by the library implementation. This is the default value. |
455 | CX_Full, |
456 | |
457 | /// Implementation of complex division offering an improved handling |
458 | /// for overflow in intermediate calculations with no special handling for |
459 | /// NaN and infinite values. |
460 | CX_Improved, |
461 | |
462 | /// Implementation of complex division using algebraic formulas at |
463 | /// higher precision. Overflow is handled. Non-finite values are handled in |
464 | /// some cases. If the target hardware does not have native support for a |
465 | /// higher precision data type, an implementation for the complex operation |
466 | /// will be used to provide improved guards against intermediate overflow, |
467 | /// but overflow and underflow may still occur in some cases. NaN and |
468 | /// infinite values are not handled. |
469 | CX_Promoted, |
470 | |
471 | /// Implementation of complex division and multiplication using |
472 | /// algebraic formulas at source precision. No special handling to avoid |
473 | /// overflow. NaN and infinite values are not handled. |
474 | CX_Basic, |
475 | |
476 | /// No range rule is enabled. |
477 | CX_None |
478 | }; |
479 | |
480 | /// Controls which variables have static destructors registered. |
481 | enum class RegisterStaticDestructorsKind { |
482 | /// Register static destructors for all variables. |
483 | All, |
484 | /// Register static destructors only for thread-local variables. |
485 | ThreadLocal, |
486 | /// Don't register static destructors for any variables. |
487 | None, |
488 | }; |
489 | |
490 | // Define simple language options (with no accessors). |
491 | #define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits; |
492 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) |
493 | #include "clang/Basic/LangOptions.def" |
494 | |
495 | protected: |
496 | // Define language options of enumeration type. These are private, and will |
497 | // have accessors (below). |
498 | #define LANGOPT(Name, Bits, Default, Description) |
499 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
500 | LLVM_PREFERRED_TYPE(Type) \ |
501 | unsigned Name : Bits; |
502 | #include "clang/Basic/LangOptions.def" |
503 | }; |
504 | |
505 | /// Keeps track of the various options that can be |
506 | /// enabled, which controls the dialect of C or C++ that is accepted. |
507 | class LangOptions : public LangOptionsBase { |
508 | public: |
509 | /// The used language standard. |
510 | LangStandard::Kind LangStd; |
511 | |
512 | /// Set of enabled sanitizers. |
513 | SanitizerSet Sanitize; |
514 | /// Is at least one coverage instrumentation type enabled. |
515 | bool SanitizeCoverage = false; |
516 | |
517 | /// Paths to files specifying which objects |
518 | /// (files, functions, variables) should not be instrumented. |
519 | std::vector<std::string> NoSanitizeFiles; |
520 | |
521 | /// Paths to the XRay "always instrument" files specifying which |
522 | /// objects (files, functions, variables) should be imbued with the XRay |
523 | /// "always instrument" attribute. |
524 | /// WARNING: This is a deprecated field and will go away in the future. |
525 | std::vector<std::string> XRayAlwaysInstrumentFiles; |
526 | |
527 | /// Paths to the XRay "never instrument" files specifying which |
528 | /// objects (files, functions, variables) should be imbued with the XRay |
529 | /// "never instrument" attribute. |
530 | /// WARNING: This is a deprecated field and will go away in the future. |
531 | std::vector<std::string> XRayNeverInstrumentFiles; |
532 | |
533 | /// Paths to the XRay attribute list files, specifying which objects |
534 | /// (files, functions, variables) should be imbued with the appropriate XRay |
535 | /// attribute(s). |
536 | std::vector<std::string> XRayAttrListFiles; |
537 | |
538 | /// Paths to special case list files specifying which entities |
539 | /// (files, functions) should or should not be instrumented. |
540 | std::vector<std::string> ProfileListFiles; |
541 | |
542 | clang::ObjCRuntime ObjCRuntime; |
543 | |
544 | CoreFoundationABI CFRuntime = CoreFoundationABI::Unspecified; |
545 | |
546 | std::string ObjCConstantStringClass; |
547 | |
548 | /// The name of the handler function to be called when -ftrapv is |
549 | /// specified. |
550 | /// |
551 | /// If none is specified, abort (GCC-compatible behaviour). |
552 | std::string OverflowHandler; |
553 | |
554 | /// The module currently being compiled as specified by -fmodule-name. |
555 | std::string ModuleName; |
556 | |
557 | /// The name of the current module, of which the main source file |
558 | /// is a part. If CompilingModule is set, we are compiling the interface |
559 | /// of this module, otherwise we are compiling an implementation file of |
560 | /// it. This starts as ModuleName in case -fmodule-name is provided and |
561 | /// changes during compilation to reflect the current module. |
562 | std::string CurrentModule; |
563 | |
564 | /// The names of any features to enable in module 'requires' decls |
565 | /// in addition to the hard-coded list in Module.cpp and the target features. |
566 | /// |
567 | /// This list is sorted. |
568 | std::vector<std::string> ModuleFeatures; |
569 | |
570 | /// Options for parsing comments. |
571 | CommentOptions ; |
572 | |
573 | /// A list of all -fno-builtin-* function names (e.g., memset). |
574 | std::vector<std::string> NoBuiltinFuncs; |
575 | |
576 | /// A prefix map for __FILE__, __BASE_FILE__ and __builtin_FILE(). |
577 | std::map<std::string, std::string, std::greater<std::string>> MacroPrefixMap; |
578 | |
579 | /// Triples of the OpenMP targets that the host code codegen should |
580 | /// take into account in order to generate accurate offloading descriptors. |
581 | std::vector<llvm::Triple> OMPTargetTriples; |
582 | |
583 | /// Name of the IR file that contains the result of the OpenMP target |
584 | /// host code generation. |
585 | std::string OMPHostIRFile; |
586 | |
587 | /// The user provided compilation unit ID, if non-empty. This is used to |
588 | /// externalize static variables which is needed to support accessing static |
589 | /// device variables in host code for single source offloading languages |
590 | /// like CUDA/HIP. |
591 | std::string CUID; |
592 | |
593 | /// C++ ABI to compile with, if specified by the frontend through -fc++-abi=. |
594 | /// This overrides the default ABI used by the target. |
595 | std::optional<TargetCXXABI::Kind> CXXABI; |
596 | |
597 | /// Indicates whether the front-end is explicitly told that the |
598 | /// input is a header file (i.e. -x c-header). |
599 | bool = false; |
600 | |
601 | /// The default stream kind used for HIP kernel launching. |
602 | GPUDefaultStreamKind GPUDefaultStream; |
603 | |
604 | /// Which overflow patterns should be excluded from sanitizer instrumentation |
605 | unsigned OverflowPatternExclusionMask = 0; |
606 | |
607 | std::vector<std::string> OverflowPatternExclusionValues; |
608 | |
609 | /// The seed used by the randomize structure layout feature. |
610 | std::string RandstructSeed; |
611 | |
612 | /// Indicates whether to use target's platform-specific file separator when |
613 | /// __FILE__ macro is used and when concatenating filename with directory or |
614 | /// to use build environment environment's platform-specific file separator. |
615 | /// |
616 | /// The plaform-specific path separator is the backslash(\) for Windows and |
617 | /// forward slash (/) elsewhere. |
618 | bool UseTargetPathSeparator = false; |
619 | |
620 | // Indicates whether we should keep all nullptr checks for pointers |
621 | // received as a result of a standard operator new (-fcheck-new) |
622 | bool CheckNew = false; |
623 | |
624 | // In OpenACC mode, contains a user provided override for the _OPENACC macro. |
625 | // This exists so that we can override the macro value and test our incomplete |
626 | // implementation on real-world examples. |
627 | std::string OpenACCMacroOverride; |
628 | |
629 | // Indicates if the wasm-opt binary must be ignored in the case of a |
630 | // WebAssembly target. |
631 | bool NoWasmOpt = false; |
632 | |
633 | LangOptions(); |
634 | |
635 | /// Set language defaults for the given input language and |
636 | /// language standard in the given LangOptions object. |
637 | /// |
638 | /// \param Opts - The LangOptions object to set up. |
639 | /// \param Lang - The input language. |
640 | /// \param T - The target triple. |
641 | /// \param Includes - If the language requires extra headers to be implicitly |
642 | /// included, they will be appended to this list. |
643 | /// \param LangStd - The input language standard. |
644 | static void |
645 | setLangDefaults(LangOptions &Opts, Language Lang, const llvm::Triple &T, |
646 | std::vector<std::string> &Includes, |
647 | LangStandard::Kind LangStd = LangStandard::lang_unspecified); |
648 | |
649 | // Define accessors/mutators for language options of enumeration type. |
650 | #define LANGOPT(Name, Bits, Default, Description) |
651 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
652 | Type get##Name() const { return static_cast<Type>(Name); } \ |
653 | void set##Name(Type Value) { \ |
654 | assert(static_cast<unsigned>(Value) < (1u << Bits)); \ |
655 | Name = static_cast<unsigned>(Value); \ |
656 | } |
657 | #include "clang/Basic/LangOptions.def" |
658 | |
659 | /// Are we compiling a module? |
660 | bool isCompilingModule() const { |
661 | return getCompilingModule() != CMK_None; |
662 | } |
663 | |
664 | /// Are we compiling a module implementation? |
665 | bool isCompilingModuleImplementation() const { |
666 | return !isCompilingModule() && !ModuleName.empty(); |
667 | } |
668 | |
669 | /// Do we need to track the owning module for a local declaration? |
670 | bool trackLocalOwningModule() const { |
671 | return isCompilingModule() || ModulesLocalVisibility; |
672 | } |
673 | |
674 | bool isSignedOverflowDefined() const { |
675 | return getSignedOverflowBehavior() == SOB_Defined; |
676 | } |
677 | |
678 | bool isSubscriptPointerArithmetic() const { |
679 | return ObjCRuntime.isSubscriptPointerArithmetic() && |
680 | !ObjCSubscriptingLegacyRuntime; |
681 | } |
682 | |
683 | bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const { |
684 | return MSCompatibilityVersion >= MajorVersion * 100000U; |
685 | } |
686 | |
687 | bool isOverflowPatternExcluded(OverflowPatternExclusionKind Kind) const { |
688 | if (OverflowPatternExclusionMask & OverflowPatternExclusionKind::None) |
689 | return false; |
690 | if (OverflowPatternExclusionMask & OverflowPatternExclusionKind::All) |
691 | return true; |
692 | return OverflowPatternExclusionMask & Kind; |
693 | } |
694 | |
695 | /// Reset all of the options that are not considered when building a |
696 | /// module. |
697 | void resetNonModularOptions(); |
698 | |
699 | /// Is this a libc/libm function that is no longer recognized as a |
700 | /// builtin because a -fno-builtin-* option has been specified? |
701 | bool isNoBuiltinFunc(StringRef Name) const; |
702 | |
703 | /// True if any ObjC types may have non-trivial lifetime qualifiers. |
704 | bool allowsNonTrivialObjCLifetimeQualifiers() const { |
705 | return ObjCAutoRefCount || ObjCWeak; |
706 | } |
707 | |
708 | bool assumeFunctionsAreConvergent() const { |
709 | return ConvergentFunctions; |
710 | } |
711 | |
712 | /// Return true if atomicrmw operations targeting allocations in private |
713 | /// memory are undefined. |
714 | bool threadPrivateMemoryAtomicsAreUndefined() const { |
715 | // Should be false for OpenMP. |
716 | // TODO: Should this be true for SYCL? |
717 | return OpenCL || CUDA; |
718 | } |
719 | |
720 | /// Return the OpenCL C or C++ version as a VersionTuple. |
721 | VersionTuple getOpenCLVersionTuple() const; |
722 | |
723 | /// Return the OpenCL version that kernel language is compatible with |
724 | unsigned getOpenCLCompatibleVersion() const; |
725 | |
726 | /// Return the OpenCL C or C++ for OpenCL language name and version |
727 | /// as a string. |
728 | std::string getOpenCLVersionString() const; |
729 | |
730 | /// Returns true if functions without prototypes or functions with an |
731 | /// identifier list (aka K&R C functions) are not allowed. |
732 | bool requiresStrictPrototypes() const { |
733 | return CPlusPlus || C23 || DisableKNRFunctions; |
734 | } |
735 | |
736 | /// Returns true if implicit function declarations are allowed in the current |
737 | /// language mode. |
738 | bool implicitFunctionsAllowed() const { |
739 | return !requiresStrictPrototypes() && !OpenCL; |
740 | } |
741 | |
742 | /// Returns true if the language supports calling the 'atexit' function. |
743 | bool hasAtExit() const { return !(OpenMP && OpenMPIsTargetDevice); } |
744 | |
745 | /// Returns true if implicit int is part of the language requirements. |
746 | bool isImplicitIntRequired() const { return !CPlusPlus && !C99; } |
747 | |
748 | /// Returns true if implicit int is supported at all. |
749 | bool isImplicitIntAllowed() const { return !CPlusPlus && !C23; } |
750 | |
751 | /// Check if return address signing is enabled. |
752 | bool hasSignReturnAddress() const { |
753 | return getSignReturnAddressScope() != SignReturnAddressScopeKind::None; |
754 | } |
755 | |
756 | /// Check if return address signing uses AKey. |
757 | bool isSignReturnAddressWithAKey() const { |
758 | return getSignReturnAddressKey() == SignReturnAddressKeyKind::AKey; |
759 | } |
760 | |
761 | /// Check if leaf functions are also signed. |
762 | bool isSignReturnAddressScopeAll() const { |
763 | return getSignReturnAddressScope() == SignReturnAddressScopeKind::All; |
764 | } |
765 | |
766 | bool hasSjLjExceptions() const { |
767 | return getExceptionHandling() == ExceptionHandlingKind::SjLj; |
768 | } |
769 | |
770 | bool hasSEHExceptions() const { |
771 | return getExceptionHandling() == ExceptionHandlingKind::WinEH; |
772 | } |
773 | |
774 | bool hasDWARFExceptions() const { |
775 | return getExceptionHandling() == ExceptionHandlingKind::DwarfCFI; |
776 | } |
777 | |
778 | bool hasWasmExceptions() const { |
779 | return getExceptionHandling() == ExceptionHandlingKind::Wasm; |
780 | } |
781 | |
782 | bool isSYCL() const { return SYCLIsDevice || SYCLIsHost; } |
783 | |
784 | bool hasDefaultVisibilityExportMapping() const { |
785 | return getDefaultVisibilityExportMapping() != |
786 | DefaultVisiblityExportMapping::None; |
787 | } |
788 | |
789 | bool isExplicitDefaultVisibilityExportMapping() const { |
790 | return getDefaultVisibilityExportMapping() == |
791 | DefaultVisiblityExportMapping::Explicit; |
792 | } |
793 | |
794 | bool isAllDefaultVisibilityExportMapping() const { |
795 | return getDefaultVisibilityExportMapping() == |
796 | DefaultVisiblityExportMapping::All; |
797 | } |
798 | |
799 | bool hasGlobalAllocationFunctionVisibility() const { |
800 | return getGlobalAllocationFunctionVisibility() != |
801 | VisibilityForcedKinds::Source; |
802 | } |
803 | |
804 | bool hasDefaultGlobalAllocationFunctionVisibility() const { |
805 | return getGlobalAllocationFunctionVisibility() == |
806 | VisibilityForcedKinds::ForceDefault; |
807 | } |
808 | |
809 | bool hasProtectedGlobalAllocationFunctionVisibility() const { |
810 | return getGlobalAllocationFunctionVisibility() == |
811 | VisibilityForcedKinds::ForceProtected; |
812 | } |
813 | |
814 | bool hasHiddenGlobalAllocationFunctionVisibility() const { |
815 | return getGlobalAllocationFunctionVisibility() == |
816 | VisibilityForcedKinds::ForceHidden; |
817 | } |
818 | |
819 | /// Remap path prefix according to -fmacro-prefix-path option. |
820 | void remapPathPrefix(SmallVectorImpl<char> &Path) const; |
821 | |
822 | RoundingMode getDefaultRoundingMode() const { |
823 | return RoundingMath ? RoundingMode::Dynamic |
824 | : RoundingMode::NearestTiesToEven; |
825 | } |
826 | |
827 | FPExceptionModeKind getDefaultExceptionMode() const { |
828 | FPExceptionModeKind EM = getFPExceptionMode(); |
829 | if (EM == FPExceptionModeKind::FPE_Default) |
830 | return FPExceptionModeKind::FPE_Ignore; |
831 | return EM; |
832 | } |
833 | }; |
834 | |
835 | /// Floating point control options |
836 | class FPOptionsOverride; |
837 | class FPOptions { |
838 | public: |
839 | // We start by defining the layout. |
840 | using storage_type = uint32_t; |
841 | |
842 | using RoundingMode = llvm::RoundingMode; |
843 | |
844 | static constexpr unsigned StorageBitSize = 8 * sizeof(storage_type); |
845 | |
846 | // Define a fake option named "First" so that we have a PREVIOUS even for the |
847 | // real first option. |
848 | static constexpr storage_type FirstShift = 0, FirstWidth = 0; |
849 | #define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \ |
850 | static constexpr storage_type NAME##Shift = \ |
851 | PREVIOUS##Shift + PREVIOUS##Width; \ |
852 | static constexpr storage_type NAME##Width = WIDTH; \ |
853 | static constexpr storage_type NAME##Mask = ((1 << NAME##Width) - 1) \ |
854 | << NAME##Shift; |
855 | #include "clang/Basic/FPOptions.def" |
856 | |
857 | static constexpr storage_type TotalWidth = 0 |
858 | #define OPTION(NAME, TYPE, WIDTH, PREVIOUS) +WIDTH |
859 | #include "clang/Basic/FPOptions.def" |
860 | ; |
861 | static_assert(TotalWidth <= StorageBitSize, "Too short type for FPOptions" ); |
862 | |
863 | private: |
864 | storage_type Value; |
865 | |
866 | FPOptionsOverride getChangesSlow(const FPOptions &Base) const; |
867 | |
868 | public: |
869 | FPOptions() : Value(0) { |
870 | setFPContractMode(LangOptions::FPM_Off); |
871 | setConstRoundingMode(RoundingMode::Dynamic); |
872 | setSpecifiedExceptionMode(LangOptions::FPE_Default); |
873 | } |
874 | explicit FPOptions(const LangOptions &LO) { |
875 | Value = 0; |
876 | // The language fp contract option FPM_FastHonorPragmas has the same effect |
877 | // as FPM_Fast in frontend. For simplicity, use FPM_Fast uniformly in |
878 | // frontend. |
879 | auto LangOptContractMode = LO.getDefaultFPContractMode(); |
880 | if (LangOptContractMode == LangOptions::FPM_FastHonorPragmas) |
881 | LangOptContractMode = LangOptions::FPM_Fast; |
882 | setFPContractMode(LangOptContractMode); |
883 | setRoundingMath(LO.RoundingMath); |
884 | setConstRoundingMode(LangOptions::RoundingMode::Dynamic); |
885 | setSpecifiedExceptionMode(LO.getFPExceptionMode()); |
886 | setAllowFPReassociate(LO.AllowFPReassoc); |
887 | setNoHonorNaNs(LO.NoHonorNaNs); |
888 | setNoHonorInfs(LO.NoHonorInfs); |
889 | setNoSignedZero(LO.NoSignedZero); |
890 | setAllowReciprocal(LO.AllowRecip); |
891 | setAllowApproxFunc(LO.ApproxFunc); |
892 | if (getFPContractMode() == LangOptions::FPM_On && |
893 | getRoundingMode() == llvm::RoundingMode::Dynamic && |
894 | getExceptionMode() == LangOptions::FPE_Strict) |
895 | // If the FP settings are set to the "strict" model, then |
896 | // FENV access is set to true. (ffp-model=strict) |
897 | setAllowFEnvAccess(true); |
898 | else |
899 | setAllowFEnvAccess(LangOptions::FPM_Off); |
900 | setComplexRange(LO.getComplexRange()); |
901 | } |
902 | |
903 | bool allowFPContractWithinStatement() const { |
904 | return getFPContractMode() == LangOptions::FPM_On; |
905 | } |
906 | void setAllowFPContractWithinStatement() { |
907 | setFPContractMode(LangOptions::FPM_On); |
908 | } |
909 | |
910 | bool allowFPContractAcrossStatement() const { |
911 | return getFPContractMode() == LangOptions::FPM_Fast; |
912 | } |
913 | void setAllowFPContractAcrossStatement() { |
914 | setFPContractMode(LangOptions::FPM_Fast); |
915 | } |
916 | |
917 | bool isFPConstrained() const { |
918 | return getRoundingMode() != llvm::RoundingMode::NearestTiesToEven || |
919 | getExceptionMode() != LangOptions::FPE_Ignore || |
920 | getAllowFEnvAccess(); |
921 | } |
922 | |
923 | RoundingMode getRoundingMode() const { |
924 | RoundingMode RM = getConstRoundingMode(); |
925 | if (RM == RoundingMode::Dynamic) { |
926 | // C23: 7.6.2p3 If the FE_DYNAMIC mode is specified and FENV_ACCESS is |
927 | // "off", the translator may assume that the default rounding mode is in |
928 | // effect. |
929 | if (!getAllowFEnvAccess() && !getRoundingMath()) |
930 | RM = RoundingMode::NearestTiesToEven; |
931 | } |
932 | return RM; |
933 | } |
934 | |
935 | LangOptions::FPExceptionModeKind getExceptionMode() const { |
936 | LangOptions::FPExceptionModeKind EM = getSpecifiedExceptionMode(); |
937 | if (EM == LangOptions::FPExceptionModeKind::FPE_Default) { |
938 | if (getAllowFEnvAccess()) |
939 | return LangOptions::FPExceptionModeKind::FPE_Strict; |
940 | else |
941 | return LangOptions::FPExceptionModeKind::FPE_Ignore; |
942 | } |
943 | return EM; |
944 | } |
945 | |
946 | bool operator==(FPOptions other) const { return Value == other.Value; } |
947 | |
948 | /// Return the default value of FPOptions that's used when trailing |
949 | /// storage isn't required. |
950 | static FPOptions defaultWithoutTrailingStorage(const LangOptions &LO); |
951 | |
952 | storage_type getAsOpaqueInt() const { return Value; } |
953 | static FPOptions getFromOpaqueInt(storage_type Value) { |
954 | FPOptions Opts; |
955 | Opts.Value = Value; |
956 | return Opts; |
957 | } |
958 | |
959 | /// Return difference with the given option set. |
960 | FPOptionsOverride getChangesFrom(const FPOptions &Base) const; |
961 | |
962 | void applyChanges(FPOptionsOverride FPO); |
963 | |
964 | // We can define most of the accessors automatically: |
965 | // TODO: consider enforcing the assertion that value fits within bits |
966 | // statically. |
967 | #define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \ |
968 | TYPE get##NAME() const { \ |
969 | return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift); \ |
970 | } \ |
971 | void set##NAME(TYPE value) { \ |
972 | assert(storage_type(value) < (1u << WIDTH)); \ |
973 | Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift); \ |
974 | } |
975 | #include "clang/Basic/FPOptions.def" |
976 | LLVM_DUMP_METHOD void dump(); |
977 | }; |
978 | |
979 | /// Represents difference between two FPOptions values. |
980 | /// |
981 | /// The effect of language constructs changing the set of floating point options |
982 | /// is usually a change of some FP properties while leaving others intact. This |
983 | /// class describes such changes by keeping information about what FP options |
984 | /// are overridden. |
985 | /// |
986 | /// The integral set of FP options, described by the class FPOptions, may be |
987 | /// represented as a default FP option set, defined by language standard and |
988 | /// command line options, with the overrides introduced by pragmas. |
989 | /// |
990 | /// The is implemented as a value of the new FPOptions plus a mask showing which |
991 | /// fields are actually set in it. |
992 | class FPOptionsOverride { |
993 | FPOptions Options = FPOptions::getFromOpaqueInt(Value: 0); |
994 | FPOptions::storage_type OverrideMask = 0; |
995 | |
996 | public: |
997 | using RoundingMode = llvm::RoundingMode; |
998 | |
999 | /// The type suitable for storing values of FPOptionsOverride. Must be twice |
1000 | /// as wide as bit size of FPOption. |
1001 | using storage_type = uint64_t; |
1002 | static_assert(sizeof(storage_type) >= 2 * sizeof(FPOptions::storage_type), |
1003 | "Too short type for FPOptionsOverride" ); |
1004 | |
1005 | /// Bit mask selecting bits of OverrideMask in serialized representation of |
1006 | /// FPOptionsOverride. |
1007 | static constexpr storage_type OverrideMaskBits = |
1008 | (static_cast<storage_type>(1) << FPOptions::StorageBitSize) - 1; |
1009 | |
1010 | FPOptionsOverride() {} |
1011 | FPOptionsOverride(const LangOptions &LO) |
1012 | : Options(LO), OverrideMask(OverrideMaskBits) {} |
1013 | FPOptionsOverride(FPOptions FPO) |
1014 | : Options(FPO), OverrideMask(OverrideMaskBits) {} |
1015 | FPOptionsOverride(FPOptions FPO, FPOptions::storage_type Mask) |
1016 | : Options(FPO), OverrideMask(Mask) {} |
1017 | |
1018 | bool requiresTrailingStorage() const { return OverrideMask != 0; } |
1019 | |
1020 | void setAllowFPContractWithinStatement() { |
1021 | setFPContractModeOverride(LangOptions::FPM_On); |
1022 | } |
1023 | |
1024 | void setAllowFPContractAcrossStatement() { |
1025 | setFPContractModeOverride(LangOptions::FPM_Fast); |
1026 | } |
1027 | |
1028 | void setDisallowFPContract() { |
1029 | setFPContractModeOverride(LangOptions::FPM_Off); |
1030 | } |
1031 | |
1032 | void setFPPreciseEnabled(bool Value) { |
1033 | setAllowFPReassociateOverride(!Value); |
1034 | setNoHonorNaNsOverride(!Value); |
1035 | setNoHonorInfsOverride(!Value); |
1036 | setNoSignedZeroOverride(!Value); |
1037 | setAllowReciprocalOverride(!Value); |
1038 | setAllowApproxFuncOverride(!Value); |
1039 | setMathErrnoOverride(Value); |
1040 | if (Value) |
1041 | /* Precise mode implies fp_contract=on and disables ffast-math */ |
1042 | setAllowFPContractWithinStatement(); |
1043 | else |
1044 | /* Precise mode disabled sets fp_contract=fast and enables ffast-math */ |
1045 | setAllowFPContractAcrossStatement(); |
1046 | } |
1047 | |
1048 | void setDisallowOptimizations() { setFPPreciseEnabled(true); } |
1049 | |
1050 | storage_type getAsOpaqueInt() const { |
1051 | return (static_cast<storage_type>(Options.getAsOpaqueInt()) |
1052 | << FPOptions::StorageBitSize) | |
1053 | OverrideMask; |
1054 | } |
1055 | static FPOptionsOverride getFromOpaqueInt(storage_type I) { |
1056 | FPOptionsOverride Opts; |
1057 | Opts.OverrideMask = I & OverrideMaskBits; |
1058 | Opts.Options = FPOptions::getFromOpaqueInt(Value: I >> FPOptions::StorageBitSize); |
1059 | return Opts; |
1060 | } |
1061 | |
1062 | FPOptions applyOverrides(FPOptions Base) { |
1063 | FPOptions Result = |
1064 | FPOptions::getFromOpaqueInt(Value: (Base.getAsOpaqueInt() & ~OverrideMask) | |
1065 | (Options.getAsOpaqueInt() & OverrideMask)); |
1066 | return Result; |
1067 | } |
1068 | |
1069 | FPOptions applyOverrides(const LangOptions &LO) { |
1070 | return applyOverrides(Base: FPOptions(LO)); |
1071 | } |
1072 | |
1073 | bool operator==(FPOptionsOverride other) const { |
1074 | return Options == other.Options && OverrideMask == other.OverrideMask; |
1075 | } |
1076 | bool operator!=(FPOptionsOverride other) const { return !(*this == other); } |
1077 | |
1078 | #define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \ |
1079 | bool has##NAME##Override() const { \ |
1080 | return OverrideMask & FPOptions::NAME##Mask; \ |
1081 | } \ |
1082 | TYPE get##NAME##Override() const { \ |
1083 | assert(has##NAME##Override()); \ |
1084 | return Options.get##NAME(); \ |
1085 | } \ |
1086 | void clear##NAME##Override() { \ |
1087 | /* Clear the actual value so that we don't have spurious differences when \ |
1088 | * testing equality. */ \ |
1089 | Options.set##NAME(TYPE(0)); \ |
1090 | OverrideMask &= ~FPOptions::NAME##Mask; \ |
1091 | } \ |
1092 | void set##NAME##Override(TYPE value) { \ |
1093 | Options.set##NAME(value); \ |
1094 | OverrideMask |= FPOptions::NAME##Mask; \ |
1095 | } |
1096 | #include "clang/Basic/FPOptions.def" |
1097 | LLVM_DUMP_METHOD void dump(); |
1098 | }; |
1099 | |
1100 | inline FPOptionsOverride FPOptions::getChangesFrom(const FPOptions &Base) const { |
1101 | if (Value == Base.Value) |
1102 | return FPOptionsOverride(); |
1103 | return getChangesSlow(Base); |
1104 | } |
1105 | |
1106 | inline void FPOptions::applyChanges(FPOptionsOverride FPO) { |
1107 | *this = FPO.applyOverrides(Base: *this); |
1108 | } |
1109 | |
1110 | /// Describes the kind of translation unit being processed. |
1111 | enum TranslationUnitKind { |
1112 | /// The translation unit is a complete translation unit. |
1113 | TU_Complete, |
1114 | |
1115 | /// The translation unit is a prefix to a translation unit, and is |
1116 | /// not complete. |
1117 | TU_Prefix, |
1118 | |
1119 | /// The translation unit is a clang module. |
1120 | TU_ClangModule, |
1121 | |
1122 | /// The translation unit is a is a complete translation unit that we might |
1123 | /// incrementally extend later. |
1124 | TU_Incremental |
1125 | }; |
1126 | |
1127 | } // namespace clang |
1128 | |
1129 | #endif // LLVM_CLANG_BASIC_LANGOPTIONS_H |
1130 | |