LangOptions.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- LangOptions.h - C Language Family Language Options -------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. /// \file
  15. /// Defines the clang::LangOptions interface.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CLANG_BASIC_LANGOPTIONS_H
  19. #define LLVM_CLANG_BASIC_LANGOPTIONS_H
  20. #include "clang/Basic/CommentOptions.h"
  21. #include "clang/Basic/LLVM.h"
  22. #include "clang/Basic/LangStandard.h"
  23. #include "clang/Basic/ObjCRuntime.h"
  24. #include "clang/Basic/Sanitizers.h"
  25. #include "clang/Basic/TargetCXXABI.h"
  26. #include "clang/Basic/Visibility.h"
  27. #include "llvm/ADT/FloatingPointMode.h"
  28. #include "llvm/ADT/StringRef.h"
  29. #include "llvm/ADT/Triple.h"
  30. #include <string>
  31. #include <vector>
  32. namespace clang {
  33. /// Bitfields of LangOptions, split out from LangOptions in order to ensure that
  34. /// this large collection of bitfields is a trivial class type.
  35. class LangOptionsBase {
  36. friend class CompilerInvocation;
  37. public:
  38. // Define simple language options (with no accessors).
  39. #define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
  40. #define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
  41. #include "clang/Basic/LangOptions.def"
  42. protected:
  43. // Define language options of enumeration type. These are private, and will
  44. // have accessors (below).
  45. #define LANGOPT(Name, Bits, Default, Description)
  46. #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
  47. unsigned Name : Bits;
  48. #include "clang/Basic/LangOptions.def"
  49. };
  50. /// In the Microsoft ABI, this controls the placement of virtual displacement
  51. /// members used to implement virtual inheritance.
  52. enum class MSVtorDispMode { Never, ForVBaseOverride, ForVFTable };
  53. /// Keeps track of the various options that can be
  54. /// enabled, which controls the dialect of C or C++ that is accepted.
  55. class LangOptions : public LangOptionsBase {
  56. public:
  57. using Visibility = clang::Visibility;
  58. using RoundingMode = llvm::RoundingMode;
  59. enum GCMode { NonGC, GCOnly, HybridGC };
  60. enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq };
  61. // Automatic variables live on the stack, and when trivial they're usually
  62. // uninitialized because it's undefined behavior to use them without
  63. // initializing them.
  64. enum class TrivialAutoVarInitKind { Uninitialized, Zero, Pattern };
  65. enum SignedOverflowBehaviorTy {
  66. // Default C standard behavior.
  67. SOB_Undefined,
  68. // -fwrapv
  69. SOB_Defined,
  70. // -ftrapv
  71. SOB_Trapping
  72. };
  73. // FIXME: Unify with TUKind.
  74. enum CompilingModuleKind {
  75. /// Not compiling a module interface at all.
  76. CMK_None,
  77. /// Compiling a module from a module map.
  78. CMK_ModuleMap,
  79. /// Compiling a module from a list of header files.
  80. CMK_HeaderModule,
  81. /// Compiling a C++ modules TS module interface unit.
  82. CMK_ModuleInterface,
  83. };
  84. enum PragmaMSPointersToMembersKind {
  85. PPTMK_BestCase,
  86. PPTMK_FullGeneralitySingleInheritance,
  87. PPTMK_FullGeneralityMultipleInheritance,
  88. PPTMK_FullGeneralityVirtualInheritance
  89. };
  90. using MSVtorDispMode = clang::MSVtorDispMode;
  91. enum DefaultCallingConvention {
  92. DCC_None,
  93. DCC_CDecl,
  94. DCC_FastCall,
  95. DCC_StdCall,
  96. DCC_VectorCall,
  97. DCC_RegCall
  98. };
  99. enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
  100. // Corresponds to _MSC_VER
  101. enum MSVCMajorVersion {
  102. MSVC2010 = 1600,
  103. MSVC2012 = 1700,
  104. MSVC2013 = 1800,
  105. MSVC2015 = 1900,
  106. MSVC2017 = 1910,
  107. MSVC2017_5 = 1912,
  108. MSVC2017_7 = 1914,
  109. MSVC2019 = 1920,
  110. MSVC2019_5 = 1925,
  111. MSVC2019_8 = 1928,
  112. };
  113. enum SYCLMajorVersion {
  114. SYCL_None,
  115. SYCL_2017,
  116. SYCL_2020,
  117. // The "default" SYCL version to be used when none is specified on the
  118. // frontend command line.
  119. SYCL_Default = SYCL_2020
  120. };
  121. /// Clang versions with different platform ABI conformance.
  122. enum class ClangABI {
  123. /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
  124. /// (SVN r257626). This causes <1 x long long> to be passed in an
  125. /// integer register instead of an SSE register on x64_64.
  126. Ver3_8,
  127. /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
  128. /// (SVN r291814). This causes move operations to be ignored when
  129. /// determining whether a class type can be passed or returned directly.
  130. Ver4,
  131. /// Attempt to be ABI-compatible with code generated by Clang 6.0.x
  132. /// (SVN r321711). This causes determination of whether a type is
  133. /// standard-layout to ignore collisions between empty base classes
  134. /// and between base classes and member subobjects, which affects
  135. /// whether we reuse base class tail padding in some ABIs.
  136. Ver6,
  137. /// Attempt to be ABI-compatible with code generated by Clang 7.0.x
  138. /// (SVN r338536). This causes alignof (C++) and _Alignof (C11) to be
  139. /// compatible with __alignof (i.e., return the preferred alignment)
  140. /// rather than returning the required alignment.
  141. Ver7,
  142. /// Attempt to be ABI-compatible with code generated by Clang 9.0.x
  143. /// (SVN r351319). This causes vectors of __int128 to be passed in memory
  144. /// instead of passing in multiple scalar registers on x86_64 on Linux and
  145. /// NetBSD.
  146. Ver9,
  147. /// Attempt to be ABI-compatible with code generated by Clang 11.0.x
  148. /// (git 2e10b7a39b93). This causes clang to pass unions with a 256-bit
  149. /// vector member on the stack instead of using registers, to not properly
  150. /// mangle substitutions for template names in some cases, and to mangle
  151. /// declaration template arguments without a cast to the parameter type
  152. /// even when that can lead to mangling collisions.
  153. Ver11,
  154. /// Attempt to be ABI-compatible with code generated by Clang 12.0.x
  155. /// (git 8e464dd76bef). This causes clang to mangle lambdas within
  156. /// global-scope inline variables incorrectly.
  157. Ver12,
  158. /// Conform to the underlying platform's C and C++ ABIs as closely
  159. /// as we can.
  160. Latest
  161. };
  162. enum class CoreFoundationABI {
  163. /// No interoperability ABI has been specified
  164. Unspecified,
  165. /// CoreFoundation does not have any language interoperability
  166. Standalone,
  167. /// Interoperability with the ObjectiveC runtime
  168. ObjectiveC,
  169. /// Interoperability with the latest known version of the Swift runtime
  170. Swift,
  171. /// Interoperability with the Swift 5.0 runtime
  172. Swift5_0,
  173. /// Interoperability with the Swift 4.2 runtime
  174. Swift4_2,
  175. /// Interoperability with the Swift 4.1 runtime
  176. Swift4_1,
  177. };
  178. enum FPModeKind {
  179. // Disable the floating point pragma
  180. FPM_Off,
  181. // Enable the floating point pragma
  182. FPM_On,
  183. // Aggressively fuse FP ops (E.g. FMA) disregarding pragmas.
  184. FPM_Fast,
  185. // Aggressively fuse FP ops and honor pragmas.
  186. FPM_FastHonorPragmas
  187. };
  188. /// Alias for RoundingMode::NearestTiesToEven.
  189. static constexpr unsigned FPR_ToNearest =
  190. static_cast<unsigned>(llvm::RoundingMode::NearestTiesToEven);
  191. /// Possible floating point exception behavior.
  192. enum FPExceptionModeKind {
  193. /// Assume that floating-point exceptions are masked.
  194. FPE_Ignore,
  195. /// Transformations do not cause new exceptions but may hide some.
  196. FPE_MayTrap,
  197. /// Strictly preserve the floating-point exception semantics.
  198. FPE_Strict
  199. };
  200. /// Possible exception handling behavior.
  201. enum class ExceptionHandlingKind { None, SjLj, WinEH, DwarfCFI, Wasm };
  202. enum class LaxVectorConversionKind {
  203. /// Permit no implicit vector bitcasts.
  204. None,
  205. /// Permit vector bitcasts between integer vectors with different numbers
  206. /// of elements but the same total bit-width.
  207. Integer,
  208. /// Permit vector bitcasts between all vectors with the same total
  209. /// bit-width.
  210. All,
  211. };
  212. enum class AltivecSrcCompatKind {
  213. // All vector compares produce scalars except vector pixel and vector bool.
  214. // The types vector pixel and vector bool return vector results.
  215. Mixed,
  216. // All vector compares produce vector results as in GCC.
  217. GCC,
  218. // All vector compares produce scalars as in XL.
  219. XL,
  220. // Default clang behaviour.
  221. Default = Mixed,
  222. };
  223. enum class SignReturnAddressScopeKind {
  224. /// No signing for any function.
  225. None,
  226. /// Sign the return address of functions that spill LR.
  227. NonLeaf,
  228. /// Sign the return address of all functions,
  229. All
  230. };
  231. enum class SignReturnAddressKeyKind {
  232. /// Return address signing uses APIA key.
  233. AKey,
  234. /// Return address signing uses APIB key.
  235. BKey
  236. };
  237. enum class ThreadModelKind {
  238. /// POSIX Threads.
  239. POSIX,
  240. /// Single Threaded Environment.
  241. Single
  242. };
  243. enum class ExtendArgsKind {
  244. /// Integer arguments are sign or zero extended to 32/64 bits
  245. /// during default argument promotions.
  246. ExtendTo32,
  247. ExtendTo64
  248. };
  249. public:
  250. /// The used language standard.
  251. LangStandard::Kind LangStd;
  252. /// Set of enabled sanitizers.
  253. SanitizerSet Sanitize;
  254. /// Is at least one coverage instrumentation type enabled.
  255. bool SanitizeCoverage = false;
  256. /// Paths to files specifying which objects
  257. /// (files, functions, variables) should not be instrumented.
  258. std::vector<std::string> NoSanitizeFiles;
  259. /// Paths to the XRay "always instrument" files specifying which
  260. /// objects (files, functions, variables) should be imbued with the XRay
  261. /// "always instrument" attribute.
  262. /// WARNING: This is a deprecated field and will go away in the future.
  263. std::vector<std::string> XRayAlwaysInstrumentFiles;
  264. /// Paths to the XRay "never instrument" files specifying which
  265. /// objects (files, functions, variables) should be imbued with the XRay
  266. /// "never instrument" attribute.
  267. /// WARNING: This is a deprecated field and will go away in the future.
  268. std::vector<std::string> XRayNeverInstrumentFiles;
  269. /// Paths to the XRay attribute list files, specifying which objects
  270. /// (files, functions, variables) should be imbued with the appropriate XRay
  271. /// attribute(s).
  272. std::vector<std::string> XRayAttrListFiles;
  273. /// Paths to special case list files specifying which entities
  274. /// (files, functions) should or should not be instrumented.
  275. std::vector<std::string> ProfileListFiles;
  276. clang::ObjCRuntime ObjCRuntime;
  277. CoreFoundationABI CFRuntime = CoreFoundationABI::Unspecified;
  278. std::string ObjCConstantStringClass;
  279. /// The name of the handler function to be called when -ftrapv is
  280. /// specified.
  281. ///
  282. /// If none is specified, abort (GCC-compatible behaviour).
  283. std::string OverflowHandler;
  284. /// The module currently being compiled as specified by -fmodule-name.
  285. std::string ModuleName;
  286. /// The name of the current module, of which the main source file
  287. /// is a part. If CompilingModule is set, we are compiling the interface
  288. /// of this module, otherwise we are compiling an implementation file of
  289. /// it. This starts as ModuleName in case -fmodule-name is provided and
  290. /// changes during compilation to reflect the current module.
  291. std::string CurrentModule;
  292. /// The names of any features to enable in module 'requires' decls
  293. /// in addition to the hard-coded list in Module.cpp and the target features.
  294. ///
  295. /// This list is sorted.
  296. std::vector<std::string> ModuleFeatures;
  297. /// Options for parsing comments.
  298. CommentOptions CommentOpts;
  299. /// A list of all -fno-builtin-* function names (e.g., memset).
  300. std::vector<std::string> NoBuiltinFuncs;
  301. /// A prefix map for __FILE__, __BASE_FILE__ and __builtin_FILE().
  302. std::map<std::string, std::string, std::greater<std::string>> MacroPrefixMap;
  303. /// Triples of the OpenMP targets that the host code codegen should
  304. /// take into account in order to generate accurate offloading descriptors.
  305. std::vector<llvm::Triple> OMPTargetTriples;
  306. /// Name of the IR file that contains the result of the OpenMP target
  307. /// host code generation.
  308. std::string OMPHostIRFile;
  309. /// The user provided compilation unit ID, if non-empty. This is used to
  310. /// externalize static variables which is needed to support accessing static
  311. /// device variables in host code for single source offloading languages
  312. /// like CUDA/HIP.
  313. std::string CUID;
  314. /// C++ ABI to compile with, if specified by the frontend through -fc++-abi=.
  315. /// This overrides the default ABI used by the target.
  316. llvm::Optional<TargetCXXABI::Kind> CXXABI;
  317. /// Indicates whether the front-end is explicitly told that the
  318. /// input is a header file (i.e. -x c-header).
  319. bool IsHeaderFile = false;
  320. LangOptions();
  321. // Define accessors/mutators for language options of enumeration type.
  322. #define LANGOPT(Name, Bits, Default, Description)
  323. #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
  324. Type get##Name() const { return static_cast<Type>(Name); } \
  325. void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
  326. #include "clang/Basic/LangOptions.def"
  327. /// Are we compiling a module interface (.cppm or module map)?
  328. bool isCompilingModule() const {
  329. return getCompilingModule() != CMK_None;
  330. }
  331. /// Do we need to track the owning module for a local declaration?
  332. bool trackLocalOwningModule() const {
  333. return isCompilingModule() || ModulesLocalVisibility;
  334. }
  335. bool isSignedOverflowDefined() const {
  336. return getSignedOverflowBehavior() == SOB_Defined;
  337. }
  338. bool isSubscriptPointerArithmetic() const {
  339. return ObjCRuntime.isSubscriptPointerArithmetic() &&
  340. !ObjCSubscriptingLegacyRuntime;
  341. }
  342. bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
  343. return MSCompatibilityVersion >= MajorVersion * 100000U;
  344. }
  345. /// Reset all of the options that are not considered when building a
  346. /// module.
  347. void resetNonModularOptions();
  348. /// Is this a libc/libm function that is no longer recognized as a
  349. /// builtin because a -fno-builtin-* option has been specified?
  350. bool isNoBuiltinFunc(StringRef Name) const;
  351. /// True if any ObjC types may have non-trivial lifetime qualifiers.
  352. bool allowsNonTrivialObjCLifetimeQualifiers() const {
  353. return ObjCAutoRefCount || ObjCWeak;
  354. }
  355. bool assumeFunctionsAreConvergent() const {
  356. return ConvergentFunctions;
  357. }
  358. /// Return the OpenCL C or C++ version as a VersionTuple.
  359. VersionTuple getOpenCLVersionTuple() const;
  360. /// Return the OpenCL version that kernel language is compatible with
  361. unsigned getOpenCLCompatibleVersion() const;
  362. /// Return the OpenCL C or C++ for OpenCL language name and version
  363. /// as a string.
  364. std::string getOpenCLVersionString() const;
  365. /// Check if return address signing is enabled.
  366. bool hasSignReturnAddress() const {
  367. return getSignReturnAddressScope() != SignReturnAddressScopeKind::None;
  368. }
  369. /// Check if return address signing uses AKey.
  370. bool isSignReturnAddressWithAKey() const {
  371. return getSignReturnAddressKey() == SignReturnAddressKeyKind::AKey;
  372. }
  373. /// Check if leaf functions are also signed.
  374. bool isSignReturnAddressScopeAll() const {
  375. return getSignReturnAddressScope() == SignReturnAddressScopeKind::All;
  376. }
  377. bool hasSjLjExceptions() const {
  378. return getExceptionHandling() == ExceptionHandlingKind::SjLj;
  379. }
  380. bool hasSEHExceptions() const {
  381. return getExceptionHandling() == ExceptionHandlingKind::WinEH;
  382. }
  383. bool hasDWARFExceptions() const {
  384. return getExceptionHandling() == ExceptionHandlingKind::DwarfCFI;
  385. }
  386. bool hasWasmExceptions() const {
  387. return getExceptionHandling() == ExceptionHandlingKind::Wasm;
  388. }
  389. bool isSYCL() const { return SYCLIsDevice || SYCLIsHost; }
  390. /// Remap path prefix according to -fmacro-prefix-path option.
  391. void remapPathPrefix(SmallString<256> &Path) const;
  392. };
  393. /// Floating point control options
  394. class FPOptionsOverride;
  395. class FPOptions {
  396. public:
  397. // We start by defining the layout.
  398. using storage_type = uint16_t;
  399. using RoundingMode = llvm::RoundingMode;
  400. static constexpr unsigned StorageBitSize = 8 * sizeof(storage_type);
  401. // Define a fake option named "First" so that we have a PREVIOUS even for the
  402. // real first option.
  403. static constexpr storage_type FirstShift = 0, FirstWidth = 0;
  404. #define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
  405. static constexpr storage_type NAME##Shift = \
  406. PREVIOUS##Shift + PREVIOUS##Width; \
  407. static constexpr storage_type NAME##Width = WIDTH; \
  408. static constexpr storage_type NAME##Mask = ((1 << NAME##Width) - 1) \
  409. << NAME##Shift;
  410. #include "clang/Basic/FPOptions.def"
  411. static constexpr storage_type TotalWidth = 0
  412. #define OPTION(NAME, TYPE, WIDTH, PREVIOUS) +WIDTH
  413. #include "clang/Basic/FPOptions.def"
  414. ;
  415. static_assert(TotalWidth <= StorageBitSize, "Too short type for FPOptions");
  416. private:
  417. storage_type Value;
  418. public:
  419. FPOptions() : Value(0) {
  420. setFPContractMode(LangOptions::FPM_Off);
  421. setRoundingMode(static_cast<RoundingMode>(LangOptions::FPR_ToNearest));
  422. setFPExceptionMode(LangOptions::FPE_Ignore);
  423. }
  424. explicit FPOptions(const LangOptions &LO) {
  425. Value = 0;
  426. // The language fp contract option FPM_FastHonorPragmas has the same effect
  427. // as FPM_Fast in frontend. For simplicity, use FPM_Fast uniformly in
  428. // frontend.
  429. auto LangOptContractMode = LO.getDefaultFPContractMode();
  430. if (LangOptContractMode == LangOptions::FPM_FastHonorPragmas)
  431. LangOptContractMode = LangOptions::FPM_Fast;
  432. setFPContractMode(LangOptContractMode);
  433. setRoundingMode(LO.getFPRoundingMode());
  434. setFPExceptionMode(LO.getFPExceptionMode());
  435. setAllowFPReassociate(LO.AllowFPReassoc);
  436. setNoHonorNaNs(LO.NoHonorNaNs);
  437. setNoHonorInfs(LO.NoHonorInfs);
  438. setNoSignedZero(LO.NoSignedZero);
  439. setAllowReciprocal(LO.AllowRecip);
  440. setAllowApproxFunc(LO.ApproxFunc);
  441. if (getFPContractMode() == LangOptions::FPM_On &&
  442. getRoundingMode() == llvm::RoundingMode::Dynamic &&
  443. getFPExceptionMode() == LangOptions::FPE_Strict)
  444. // If the FP settings are set to the "strict" model, then
  445. // FENV access is set to true. (ffp-model=strict)
  446. setAllowFEnvAccess(true);
  447. else
  448. setAllowFEnvAccess(LangOptions::FPM_Off);
  449. }
  450. bool allowFPContractWithinStatement() const {
  451. return getFPContractMode() == LangOptions::FPM_On;
  452. }
  453. void setAllowFPContractWithinStatement() {
  454. setFPContractMode(LangOptions::FPM_On);
  455. }
  456. bool allowFPContractAcrossStatement() const {
  457. return getFPContractMode() == LangOptions::FPM_Fast;
  458. }
  459. void setAllowFPContractAcrossStatement() {
  460. setFPContractMode(LangOptions::FPM_Fast);
  461. }
  462. bool isFPConstrained() const {
  463. return getRoundingMode() != llvm::RoundingMode::NearestTiesToEven ||
  464. getFPExceptionMode() != LangOptions::FPE_Ignore ||
  465. getAllowFEnvAccess();
  466. }
  467. bool operator==(FPOptions other) const { return Value == other.Value; }
  468. /// Return the default value of FPOptions that's used when trailing
  469. /// storage isn't required.
  470. static FPOptions defaultWithoutTrailingStorage(const LangOptions &LO);
  471. storage_type getAsOpaqueInt() const { return Value; }
  472. static FPOptions getFromOpaqueInt(storage_type Value) {
  473. FPOptions Opts;
  474. Opts.Value = Value;
  475. return Opts;
  476. }
  477. // We can define most of the accessors automatically:
  478. #define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
  479. TYPE get##NAME() const { \
  480. return static_cast<TYPE>((Value & NAME##Mask) >> NAME##Shift); \
  481. } \
  482. void set##NAME(TYPE value) { \
  483. Value = (Value & ~NAME##Mask) | (storage_type(value) << NAME##Shift); \
  484. }
  485. #include "clang/Basic/FPOptions.def"
  486. LLVM_DUMP_METHOD void dump();
  487. };
  488. /// Represents difference between two FPOptions values.
  489. ///
  490. /// The effect of language constructs changing the set of floating point options
  491. /// is usually a change of some FP properties while leaving others intact. This
  492. /// class describes such changes by keeping information about what FP options
  493. /// are overridden.
  494. ///
  495. /// The integral set of FP options, described by the class FPOptions, may be
  496. /// represented as a default FP option set, defined by language standard and
  497. /// command line options, with the overrides introduced by pragmas.
  498. ///
  499. /// The is implemented as a value of the new FPOptions plus a mask showing which
  500. /// fields are actually set in it.
  501. class FPOptionsOverride {
  502. FPOptions Options = FPOptions::getFromOpaqueInt(0);
  503. FPOptions::storage_type OverrideMask = 0;
  504. public:
  505. using RoundingMode = llvm::RoundingMode;
  506. /// The type suitable for storing values of FPOptionsOverride. Must be twice
  507. /// as wide as bit size of FPOption.
  508. using storage_type = uint32_t;
  509. static_assert(sizeof(storage_type) >= 2 * sizeof(FPOptions::storage_type),
  510. "Too short type for FPOptionsOverride");
  511. /// Bit mask selecting bits of OverrideMask in serialized representation of
  512. /// FPOptionsOverride.
  513. static constexpr storage_type OverrideMaskBits =
  514. (static_cast<storage_type>(1) << FPOptions::StorageBitSize) - 1;
  515. FPOptionsOverride() {}
  516. FPOptionsOverride(const LangOptions &LO)
  517. : Options(LO), OverrideMask(OverrideMaskBits) {}
  518. FPOptionsOverride(FPOptions FPO)
  519. : Options(FPO), OverrideMask(OverrideMaskBits) {}
  520. bool requiresTrailingStorage() const { return OverrideMask != 0; }
  521. void setAllowFPContractWithinStatement() {
  522. setFPContractModeOverride(LangOptions::FPM_On);
  523. }
  524. void setAllowFPContractAcrossStatement() {
  525. setFPContractModeOverride(LangOptions::FPM_Fast);
  526. }
  527. void setDisallowFPContract() {
  528. setFPContractModeOverride(LangOptions::FPM_Off);
  529. }
  530. void setFPPreciseEnabled(bool Value) {
  531. setAllowFPReassociateOverride(!Value);
  532. setNoHonorNaNsOverride(!Value);
  533. setNoHonorInfsOverride(!Value);
  534. setNoSignedZeroOverride(!Value);
  535. setAllowReciprocalOverride(!Value);
  536. setAllowApproxFuncOverride(!Value);
  537. if (Value)
  538. /* Precise mode implies fp_contract=on and disables ffast-math */
  539. setAllowFPContractWithinStatement();
  540. else
  541. /* Precise mode disabled sets fp_contract=fast and enables ffast-math */
  542. setAllowFPContractAcrossStatement();
  543. }
  544. storage_type getAsOpaqueInt() const {
  545. return (static_cast<storage_type>(Options.getAsOpaqueInt())
  546. << FPOptions::StorageBitSize) |
  547. OverrideMask;
  548. }
  549. static FPOptionsOverride getFromOpaqueInt(storage_type I) {
  550. FPOptionsOverride Opts;
  551. Opts.OverrideMask = I & OverrideMaskBits;
  552. Opts.Options = FPOptions::getFromOpaqueInt(I >> FPOptions::StorageBitSize);
  553. return Opts;
  554. }
  555. FPOptions applyOverrides(FPOptions Base) {
  556. FPOptions Result =
  557. FPOptions::getFromOpaqueInt((Base.getAsOpaqueInt() & ~OverrideMask) |
  558. (Options.getAsOpaqueInt() & OverrideMask));
  559. return Result;
  560. }
  561. FPOptions applyOverrides(const LangOptions &LO) {
  562. return applyOverrides(FPOptions(LO));
  563. }
  564. bool operator==(FPOptionsOverride other) const {
  565. return Options == other.Options && OverrideMask == other.OverrideMask;
  566. }
  567. bool operator!=(FPOptionsOverride other) const { return !(*this == other); }
  568. #define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
  569. bool has##NAME##Override() const { \
  570. return OverrideMask & FPOptions::NAME##Mask; \
  571. } \
  572. TYPE get##NAME##Override() const { \
  573. assert(has##NAME##Override()); \
  574. return Options.get##NAME(); \
  575. } \
  576. void clear##NAME##Override() { \
  577. /* Clear the actual value so that we don't have spurious differences when \
  578. * testing equality. */ \
  579. Options.set##NAME(TYPE(0)); \
  580. OverrideMask &= ~FPOptions::NAME##Mask; \
  581. } \
  582. void set##NAME##Override(TYPE value) { \
  583. Options.set##NAME(value); \
  584. OverrideMask |= FPOptions::NAME##Mask; \
  585. }
  586. #include "clang/Basic/FPOptions.def"
  587. LLVM_DUMP_METHOD void dump();
  588. };
  589. /// Describes the kind of translation unit being processed.
  590. enum TranslationUnitKind {
  591. /// The translation unit is a complete translation unit.
  592. TU_Complete,
  593. /// The translation unit is a prefix to a translation unit, and is
  594. /// not complete.
  595. TU_Prefix,
  596. /// The translation unit is a module.
  597. TU_Module,
  598. /// The translation unit is a is a complete translation unit that we might
  599. /// incrementally extend later.
  600. TU_Incremental
  601. };
  602. } // namespace clang
  603. #endif // LLVM_CLANG_BASIC_LANGOPTIONS_H
  604. #ifdef __GNUC__
  605. #pragma GCC diagnostic pop
  606. #endif