clang 20.0.0git
LangOptions.h
Go to the documentation of this file.
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
19#include "clang/Basic/LLVM.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
32namespace clang {
33
34/// In the Microsoft ABI, this controls the placement of virtual displacement
35/// members used to implement virtual inheritance.
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.
42enum class ShaderStage {
43 Pixel = 0,
44 Vertex,
46 Hull,
47 Domain,
48 Compute,
49 Library,
52 AnyHit,
54 Miss,
56 Mesh,
58 Invalid,
59};
60
61enum class PointerAuthenticationMode : unsigned {
62 None,
63 Strip,
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.
71 friend class CompilerInvocation;
73
74public:
76 using RoundingMode = llvm::RoundingMode;
78
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.
86
88 // Default C standard behavior.
90
91 // -fwrapv
93
94 // -ftrapv
96 };
97
98 // FIXME: Unify with TUKind.
100 /// Not compiling a module interface at all.
102
103 /// Compiling a module from a module map.
105
106 /// Compiling a module header unit.
108
109 /// Compiling a C++ modules interface unit.
111 };
112
118 };
119
121
130 };
131
133
134 // Corresponds to _MSC_VER
136 MSVC2010 = 1600,
137 MSVC2012 = 1700,
138 MSVC2013 = 1800,
139 MSVC2015 = 1900,
140 MSVC2017 = 1910,
143 MSVC2019 = 1920,
147 };
148
153 // The "default" SYCL version to be used when none is specified on the
154 // frontend command line.
156 };
157
160 HLSL_2015 = 2015,
161 HLSL_2016 = 2016,
162 HLSL_2017 = 2017,
163 HLSL_2018 = 2018,
164 HLSL_2021 = 2021,
165 HLSL_202x = 2028,
166 HLSL_202y = 2029,
167 };
168
169 /// Clang versions with different platform ABI conformance.
170 enum class ClangABI {
171 /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
172 /// (SVN r257626). This causes <1 x long long> to be passed in an
173 /// integer register instead of an SSE register on x64_64.
174 Ver3_8,
175
176 /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
177 /// (SVN r291814). This causes move operations to be ignored when
178 /// determining whether a class type can be passed or returned directly.
179 Ver4,
180
181 /// Attempt to be ABI-compatible with code generated by Clang 6.0.x
182 /// (SVN r321711). This causes determination of whether a type is
183 /// standard-layout to ignore collisions between empty base classes
184 /// and between base classes and member subobjects, which affects
185 /// whether we reuse base class tail padding in some ABIs.
186 Ver6,
187
188 /// Attempt to be ABI-compatible with code generated by Clang 7.0.x
189 /// (SVN r338536). This causes alignof (C++) and _Alignof (C11) to be
190 /// compatible with __alignof (i.e., return the preferred alignment)
191 /// rather than returning the required alignment.
192 Ver7,
193
194 /// Attempt to be ABI-compatible with code generated by Clang 9.0.x
195 /// (SVN r351319). This causes vectors of __int128 to be passed in memory
196 /// instead of passing in multiple scalar registers on x86_64 on Linux and
197 /// NetBSD.
198 Ver9,
199
200 /// Attempt to be ABI-compatible with code generated by Clang 11.0.x
201 /// (git 2e10b7a39b93). This causes clang to pass unions with a 256-bit
202 /// vector member on the stack instead of using registers, to not properly
203 /// mangle substitutions for template names in some cases, and to mangle
204 /// declaration template arguments without a cast to the parameter type
205 /// even when that can lead to mangling collisions.
206 Ver11,
207
208 /// Attempt to be ABI-compatible with code generated by Clang 12.0.x
209 /// (git 8e464dd76bef). This causes clang to mangle lambdas within
210 /// global-scope inline variables incorrectly.
211 Ver12,
212
213 /// Attempt to be ABI-compatible with code generated by Clang 14.0.x.
214 /// This causes clang to:
215 /// - mangle dependent nested names incorrectly.
216 /// - make trivial only those defaulted copy constructors with a
217 /// parameter-type-list equivalent to the parameter-type-list of an
218 /// implicit declaration.
219 Ver14,
220
221 /// Attempt to be ABI-compatible with code generated by Clang 15.0.x.
222 /// This causes clang to:
223 /// - Reverse the implementation for DR692, DR1395 and DR1432.
224 /// - pack non-POD members of packed structs.
225 /// - consider classes with defaulted special member functions non-pod.
226 Ver15,
227
228 /// Attempt to be ABI-compatible with code generated by Clang 17.0.x.
229 /// This causes clang to revert some fixes to its implementation of the
230 /// Itanium name mangling scheme, with the consequence that overloaded
231 /// function templates are mangled the same if they differ only by:
232 /// - constraints
233 /// - whether a non-type template parameter has a deduced type
234 /// - the parameter list of a template template parameter
235 Ver17,
236
237 /// Attempt to be ABI-compatible with code generated by Clang 18.0.x.
238 /// This causes clang to revert some fixes to the mangling of lambdas
239 /// in the initializers of members of local classes.
240 Ver18,
241
242 /// Attempt to be ABI-compatible with code generated by Clang 19.0.x.
243 /// This causes clang to:
244 /// - Incorrectly mangle the 'base type' substitutions of the CXX
245 /// construction vtable because it hasn't added 'type' as a substitution.
246 /// - Skip mangling enclosing class templates of member-like friend
247 /// function templates.
248 Ver19,
249
250 /// Conform to the underlying platform's C and C++ ABIs as closely
251 /// as we can.
252 Latest
253 };
254
255 enum class CoreFoundationABI {
256 /// No interoperability ABI has been specified
258 /// CoreFoundation does not have any language interoperability
260 /// Interoperability with the ObjectiveC runtime
262 /// Interoperability with the latest known version of the Swift runtime
263 Swift,
264 /// Interoperability with the Swift 5.0 runtime
265 Swift5_0,
266 /// Interoperability with the Swift 4.2 runtime
267 Swift4_2,
268 /// Interoperability with the Swift 4.1 runtime
269 Swift4_1,
270 };
271
273 // Disable the floating point pragma
275
276 // Enable the floating point pragma
278
279 // Aggressively fuse FP ops (E.g. FMA) disregarding pragmas.
281
282 // Aggressively fuse FP ops and honor pragmas.
284 };
285
286 /// Possible floating point exception behavior.
288 /// Assume that floating-point exceptions are masked.
290 /// Transformations do not cause new exceptions but may hide some.
292 /// Strictly preserve the floating-point exception semantics.
294 /// Used internally to represent initial unspecified value.
296 };
297
298 /// Possible float expression evaluation method choices.
300 /// The evaluation method cannot be determined or is inconsistent for this
301 /// target.
303 /// Use the declared type for fp arithmetic.
305 /// Use the type double for fp arithmetic.
307 /// Use extended type for fp arithmetic.
309 /// Used only for FE option processing; this is only used to indicate that
310 /// the user did not specify an explicit evaluation method on the command
311 /// line and so the target should be queried for its default evaluation
312 /// method instead.
314 };
315
317
318 /// Possible exception handling behavior.
320
322 /// Permit no implicit vector bitcasts.
323 None,
324 /// Permit vector bitcasts between integer vectors with different numbers
325 /// of elements but the same total bit-width.
326 Integer,
327 /// Permit vector bitcasts between all vectors with the same total
328 /// bit-width.
329 All,
330 };
331
333 // All vector compares produce scalars except vector pixel and vector bool.
334 // The types vector pixel and vector bool return vector results.
335 Mixed,
336 // All vector compares produce vector results as in GCC.
337 GCC,
338 // All vector compares produce scalars as in XL.
339 XL,
340 // Default clang behaviour.
341 Default = Mixed,
342 };
343
345 /// No signing for any function.
346 None,
347 /// Sign the return address of functions that spill LR.
348 NonLeaf,
349 /// Sign the return address of all functions,
350 All
351 };
352
354 /// Return address signing uses APIA key.
355 AKey,
356 /// Return address signing uses APIB key.
357 BKey
358 };
359
360 enum class ThreadModelKind {
361 /// POSIX Threads.
362 POSIX,
363 /// Single Threaded Environment.
364 Single
365 };
366
367 enum class ExtendArgsKind {
368 /// Integer arguments are sign or zero extended to 32/64 bits
369 /// during default argument promotions.
372 };
373
375 /// Legacy default stream
376 Legacy,
377 /// Per-thread default stream
378 PerThread,
379 };
380
381 /// Exclude certain code patterns from being instrumented by arithmetic
382 /// overflow sanitizers
384 /// Don't exclude any overflow patterns from sanitizers
385 None = 1 << 0,
386 /// Exclude all overflow patterns (below)
387 All = 1 << 1,
388 /// if (a + b < a)
390 /// if (a + b < a)
392 /// -1UL
394 /// while (count--)
396 };
397
399 None,
400 /// map only explicit default visibilities to exported
401 Explicit,
402 /// map all default visibilities to exported
403 All,
404 };
405
407 /// Force hidden visibility
409 /// Force protected visibility
411 /// Force default visibility
413 /// Don't alter the visibility
414 Source,
415 };
416
418 /// Keep the IR-gen assigned visibility.
419 Keep,
420 /// Override the IR-gen assigned visibility with default visibility.
421 Default,
422 /// Override the IR-gen assigned visibility with hidden visibility.
423 Hidden,
424 /// Override the IR-gen assigned visibility with protected visibility.
425 Protected,
426 };
427
429 /// Any trailing array member is a FAM.
430 Default = 0,
431 /// Any trailing array member of undefined, 0, or 1 size is a FAM.
433 /// Any trailing array member of undefined or 0 size is a FAM.
435 /// Any trailing array member of undefined size is a FAM.
436 IncompleteOnly = 3,
437 };
438
439 /// Controls the various implementations for complex multiplication and
440 // division.
442 /// Implementation of complex division and multiplication using a call to
443 /// runtime library functions(generally the case, but the BE might
444 /// sometimes replace the library call if it knows enough about the
445 /// potential range of the inputs). Overflow and non-finite values are
446 /// handled by the library implementation. This is the default value.
448
449 /// Implementation of complex division offering an improved handling
450 /// for overflow in intermediate calculations with no special handling for
451 /// NaN and infinite values.
453
454 /// Implementation of complex division using algebraic formulas at
455 /// higher precision. Overflow is handled. Non-finite values are handled in
456 /// some cases. If the target hardware does not have native support for a
457 /// higher precision data type, an implementation for the complex operation
458 /// will be used to provide improved guards against intermediate overflow,
459 /// but overflow and underflow may still occur in some cases. NaN and
460 /// infinite values are not handled.
462
463 /// Implementation of complex division and multiplication using
464 /// algebraic formulas at source precision. No special handling to avoid
465 /// overflow. NaN and infinite values are not handled.
467
468 /// No range rule is enabled.
469 CX_None
470 };
471
472 /// Controls which variables have static destructors registered.
474 /// Register static destructors for all variables.
475 All,
476 /// Register static destructors only for thread-local variables.
478 /// Don't register static destructors for any variables.
479 None,
480 };
481
482 // Define simple language options (with no accessors).
483#define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
484#define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
485#include "clang/Basic/LangOptions.def"
486
487protected:
488 // Define language options of enumeration type. These are private, and will
489 // have accessors (below).
490#define LANGOPT(Name, Bits, Default, Description)
491#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
492 LLVM_PREFERRED_TYPE(Type) \
493 unsigned Name : Bits;
494#include "clang/Basic/LangOptions.def"
495};
496
497/// Keeps track of the various options that can be
498/// enabled, which controls the dialect of C or C++ that is accepted.
500public:
501 /// The used language standard.
503
504 /// Set of enabled sanitizers.
506 /// Is at least one coverage instrumentation type enabled.
507 bool SanitizeCoverage = false;
508
509 /// Paths to files specifying which objects
510 /// (files, functions, variables) should not be instrumented.
511 std::vector<std::string> NoSanitizeFiles;
512
513 /// Paths to the XRay "always instrument" files specifying which
514 /// objects (files, functions, variables) should be imbued with the XRay
515 /// "always instrument" attribute.
516 /// WARNING: This is a deprecated field and will go away in the future.
517 std::vector<std::string> XRayAlwaysInstrumentFiles;
518
519 /// Paths to the XRay "never instrument" files specifying which
520 /// objects (files, functions, variables) should be imbued with the XRay
521 /// "never instrument" attribute.
522 /// WARNING: This is a deprecated field and will go away in the future.
523 std::vector<std::string> XRayNeverInstrumentFiles;
524
525 /// Paths to the XRay attribute list files, specifying which objects
526 /// (files, functions, variables) should be imbued with the appropriate XRay
527 /// attribute(s).
528 std::vector<std::string> XRayAttrListFiles;
529
530 /// Paths to special case list files specifying which entities
531 /// (files, functions) should or should not be instrumented.
532 std::vector<std::string> ProfileListFiles;
533
535
537
539
540 /// The name of the handler function to be called when -ftrapv is
541 /// specified.
542 ///
543 /// If none is specified, abort (GCC-compatible behaviour).
544 std::string OverflowHandler;
545
546 /// The module currently being compiled as specified by -fmodule-name.
547 std::string ModuleName;
548
549 /// The name of the current module, of which the main source file
550 /// is a part. If CompilingModule is set, we are compiling the interface
551 /// of this module, otherwise we are compiling an implementation file of
552 /// it. This starts as ModuleName in case -fmodule-name is provided and
553 /// changes during compilation to reflect the current module.
554 std::string CurrentModule;
555
556 /// The names of any features to enable in module 'requires' decls
557 /// in addition to the hard-coded list in Module.cpp and the target features.
558 ///
559 /// This list is sorted.
560 std::vector<std::string> ModuleFeatures;
561
562 /// Options for parsing comments.
564
565 /// A list of all -fno-builtin-* function names (e.g., memset).
566 std::vector<std::string> NoBuiltinFuncs;
567
568 /// A prefix map for __FILE__, __BASE_FILE__ and __builtin_FILE().
569 std::map<std::string, std::string, std::greater<std::string>> MacroPrefixMap;
570
571 /// Triples of the OpenMP targets that the host code codegen should
572 /// take into account in order to generate accurate offloading descriptors.
573 std::vector<llvm::Triple> OMPTargetTriples;
574
575 /// Name of the IR file that contains the result of the OpenMP target
576 /// host code generation.
577 std::string OMPHostIRFile;
578
579 /// The user provided compilation unit ID, if non-empty. This is used to
580 /// externalize static variables which is needed to support accessing static
581 /// device variables in host code for single source offloading languages
582 /// like CUDA/HIP.
583 std::string CUID;
584
585 /// C++ ABI to compile with, if specified by the frontend through -fc++-abi=.
586 /// This overrides the default ABI used by the target.
587 std::optional<TargetCXXABI::Kind> CXXABI;
588
589 /// Indicates whether the front-end is explicitly told that the
590 /// input is a header file (i.e. -x c-header).
591 bool IsHeaderFile = false;
592
593 /// The default stream kind used for HIP kernel launching.
595
596 /// Which overflow patterns should be excluded from sanitizer instrumentation
598
599 std::vector<std::string> OverflowPatternExclusionValues;
600
601 /// The seed used by the randomize structure layout feature.
602 std::string RandstructSeed;
603
604 /// Indicates whether to use target's platform-specific file separator when
605 /// __FILE__ macro is used and when concatenating filename with directory or
606 /// to use build environment environment's platform-specific file separator.
607 ///
608 /// The plaform-specific path separator is the backslash(\‍) for Windows and
609 /// forward slash (/) elsewhere.
611
612 // Indicates whether we should keep all nullptr checks for pointers
613 // received as a result of a standard operator new (-fcheck-new)
614 bool CheckNew = false;
615
616 // In OpenACC mode, contains a user provided override for the _OPENACC macro.
617 // This exists so that we can override the macro value and test our incomplete
618 // implementation on real-world examples.
620
621 // Indicates if the wasm-opt binary must be ignored in the case of a
622 // WebAssembly target.
623 bool NoWasmOpt = false;
624
625 LangOptions();
626
627 /// Set language defaults for the given input language and
628 /// language standard in the given LangOptions object.
629 ///
630 /// \param Opts - The LangOptions object to set up.
631 /// \param Lang - The input language.
632 /// \param T - The target triple.
633 /// \param Includes - If the language requires extra headers to be implicitly
634 /// included, they will be appended to this list.
635 /// \param LangStd - The input language standard.
636 static void
637 setLangDefaults(LangOptions &Opts, Language Lang, const llvm::Triple &