aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaAttr.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-07-01[Sema] Remove an unnecessary cast (NFC) (#146622)Kazu Hirata1-2/+1
Since both alignment and Alignment are of the same type, this patch renames alignment to Alignment while removing the cast statement.
2025-05-31Work around a build issue with MSVC; NFC (#142195)Aaron Ballman1-1/+1
Microsoft helpfully defines `THIS` to `void` in two different platform SDK headers, at least one of which is reachable via <Windows.h>. We have a user who ran into a build because of `THIS` unfortunate macro name collision. Rename the members to better match our naming conventions. Fixes #142186
2025-04-28[clang][NFC] Convert `Sema::PragmaOptionsAlignKind` to scoped enumVlad Serebrennikov1-6/+6
2025-04-28Revert "[clang][NFC] Convert `Sema::PragmaMsStackAction` to scoped enum"Vlad Serebrennikov1-43/+37
This reverts commit bd2a3f8d90368288a73dd2ef1926f714acd9eff3.
2025-04-28[clang][NFC] Convert `Sema::PragmaMsStackAction` to scoped enumVlad Serebrennikov1-37/+43
2025-04-28[clang][NFC] Convert `Sema::PragmaClangSectionAction` to scoped enumVlad Serebrennikov1-1/+1
2025-04-28[clang][NFC] Convert `Sema::PragmaClangSectionKind` to scoped enumVlad Serebrennikov1-5/+5
2025-03-24[clang] Do not infer lifetimebound for functions with void return type (#131997)Utkarsh Saxena1-0/+5
Fixes: https://github.com/llvm/llvm-project/issues/126231 Also found in : https://github.com/microsoft/STL/issues/5271
2025-03-22[clang] Use *Set::insert_range (NFC) (#132507)Kazu Hirata1-1/+1
DenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently gained C++23-style insert_range. This patch replaces: Dest.insert(Src.begin(), Src.end()); with: Dest.insert_range(Src); This patch does not touch custom begin like succ_begin for now.
2025-02-20[clang] print correct context for diagnostics suppressed by deduction (#125453)Matheus Izvekov1-3/+4
This patch makes it so the correct instantiation context is printed for diagnostics suppessed by template argument deduction. The context is saved along with the suppressed diagnostic, and when the declaration they were attached to becomes used, we print the correct context, instead of whatever context was at this point.
2025-02-11[Clang] disallow attributes on void parameters (#124920)Oleksandr T.1-0/+5
Fixes #108819 --- This PR introduces diagnostics to disallow the use of attributes on void parameters ```cpp void f([[deprecated]] void) {} ```
2025-02-04[clang] Remove an incorrect assertion in ConstantFoldAttrs (#105789)Timm Baeder1-1/+0
Evaluating the attribute expression can be successful without resulting in a value. Namely, when the expression is of type void. Fixes https://github.com/llvm/llvm-project/issues/119125
2025-01-09[clang] Don't infer lifetime_capture-by for reference of raw pointer types. ↵Haojian Wu1-1/+1
(#122240) When a vector is instantiated with a pointer type (`T` being `const Foo*`), the inferred annotation becomes `push_back(const Foo*& value [[clang::lifetime_capture_by(this)]])`. For reference parameters, the `lifetime_capture_by` attribute treats the lifetime as referring to the referenced object -- in this case, the **pointer** itself, not the pointee object. In the `push_back`, we copy the pointer's value, which does not establish a reference to the pointer. This behavior is safe and does not capture the pointer's lifetime. The annotation should not be inferred for cases where `T` is a pointer type, as the intended semantics do not align with the annotation. Fixes #121391
2025-01-08[clang] Infer capture_by for insert_or_assign (#122109)Utkarsh Saxena1-2/+2
Useful for maps: https://en.cppreference.com/w/cpp/container/map/insert_or_assign
2024-12-13[clang-cl] Don't add implicit NoBuiltinAttr to deleted or defaulted ↵VScigolevs1-0/+2
functions (#119719) In Clang `#pragma function` is implemented by adding an implicit NoBuiltin Attribute to all function definitions after the pragma. This (wrongly) includes also defaulted or deleted functions, which results in the error, shown in #116256. As this attribute has no effect on the deleted or defaulted functions, this commit fixes the previously mentioned issue by simply not adding the attribute in such cases. Fixes #116256
2024-12-02[clang] Infer lifetime_capture_by for map's subscript operator. (#118078)Haojian Wu1-22/+36
2024-11-29[clang] Fix incorrect inferred lifetime_capture_by attr on STL (#118013)Haojian Wu1-1/+6
We incorrectly annotate the iterator parameter for `insert` method (`void insert(const_iterator, const value_type& value)`), because iterator is also a gsl-pointer type. This patch fixes it.
2024-11-28[clang] Add a common definition of isPointerLikeType for lifetime analysis ↵Utkarsh Saxena1-13/+1
(#117315) Also checks for annotation for template specializations which sometimes may not have the annotation attached.
2024-11-22[clang] Infer lifetime_capture_by for STL containers (#117122)Utkarsh Saxena1-0/+39
This is behind `-Wdangling-capture` warning which is disabled by default.
2024-11-16[Sema] Remove unused includes (NFC) (#116461)Kazu Hirata1-1/+0
Identified with misc-include-cleaner.
2024-10-14[Sema] Avoid repeated hash lookups (NFC) (#112156)Kazu Hirata1-5/+3
2024-09-17[NFC] Move warning from CodeGen to Sema. (#107397)Zahira Ammarguellat1-0/+10
This is a warning that wasn't associated with the source location. Moved it to Sema and changed the warning message to a more verbose one.
2024-08-28[clang] Add lifetimebound attr to std::span/std::string_view constructor ↵Haojian Wu1-0/+53
(#103716) With this patch, clang now automatically adds ``[[clang::lifetimebound]]`` to the parameters of `std::span, std::string_view` constructors, this enables Clang to capture more cases where the returned reference outlives the object. Fixes #100567
2024-08-21Fix bug with -ffp-contract=fast-honor-pragmas (#104857)Andy Kaylor1-2/+1
This fixes a problem which caused clang to assert in the Sema pragma handling if it encountered "#pragma STDC FP_CONTRACT DEFAULT" when compiling with the -ffp-contract=fast-honor-pragmas option. This fixes https://github.com/llvm/llvm-project/issues/104830
2024-07-19[clang] Add the `const` to all default lists in SemaAttr.cpp, NFCHaojian Wu1-7/+7
Address the comment in https://github.com/llvm/llvm-project/pull/99622#issuecomment-2238800532
2024-07-19[clang] Add `std::span` to the default gsl pointer annotation list. (#99622)Haojian Wu1-0/+1
2024-07-01[clang][NFC] Move documentation of `Sema` functions into `Sema.h`Vlad Serebrennikov1-1/+0
This patch moves documentation of `Sema` functions from `.cpp` files to `Sema.h` when there was no documentation in the latter, or it can be trivially subsumed. More complicated cases when there's less trivial divergence between documentation attached to declaration and the one attached to implementation are left for a later PR that would require review. It appears that doxygen can find the documentation for a function defined out-of-line even if it's attached to an implementation, and not declaration. But other tools, e.g. clangd, are not as powerful. So this patch significantly improves autocompletion experience for (at least) clangd-based IDEs.
2024-05-13[clang] Introduce `SemaObjC` (#89086)Vlad Serebrennikov1-16/+0
This is continuation of efforts to split `Sema` up, following the example of OpenMP, OpenACC, etc. Context can be found in https://github.com/llvm/llvm-project/pull/82217 and https://github.com/llvm/llvm-project/pull/84184. I split formatting changes into a separate commit to help reviewing the actual changes.
2024-04-30Reapply "[Clang][Sema] Diagnose class member access expressions naming ↵Krystian Stasiowski1-1/+1
non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (#84050)" (#90152) Reapplies #84050, addressing a bug which cases a crash when an expression with the type of the current instantiation is used as the _postfix-expression_ in a class member access expression (arrow form).
2024-04-26Revert "[Clang][Sema] Diagnose class member access expressions naming ↵Pranav Kant1-1/+1
non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (#84050)" This reverts commit a8fd0d029dca7d17eee72d0445223c2fe1ee7758.
2024-04-25[Clang][Sema] Diagnose class member access expressions naming non-existent ↵Krystian Stasiowski1-1/+1
members of the current instantiation prior to instantiation in the absence of dependent base classes (#84050) Consider the following: ```cpp template<typename T> struct A { auto f() { return this->x; } }; ``` Although `A` has no dependent base classes and the lookup context for `x` is the current instantiation, we currently do not diagnose the absence of a member `x` until `A<T>::f` is instantiated. This patch moves the point of diagnosis for such expressions to occur at the point of definition (i.e. prior to instantiation).
2024-04-02Reapply "[clang][nullability] allow _Nonnull etc on nullable class types ↵Sam McCall1-0/+12
(#82705)" (#87325) This reverts commit 28760b63bbf9e267713957105a8d17091fb0d20e. The last commit was missing the new testcase, now fixed.
2024-03-29Revert "Reapply "[clang][nullability] allow _Nonnull etc on nullable class ↵dyung1-12/+0
types (#82705)"" (#87041) This reverts commit bbbcc1d99d08855069f4501c896c43a6d4d7b598. This change is causing the following build bots to fail due to a missing header file: - https://lab.llvm.org/buildbot/#/builders/188/builds/43765 - https://lab.llvm.org/buildbot/#/builders/176/builds/9428 - https://lab.llvm.org/buildbot/#/builders/187/builds/14696 - https://lab.llvm.org/buildbot/#/builders/186/builds/15551 - https://lab.llvm.org/buildbot/#/builders/182/builds/9413 - https://lab.llvm.org/buildbot/#/builders/245/builds/22507 - https://lab.llvm.org/buildbot/#/builders/258/builds/16026 - https://lab.llvm.org/buildbot/#/builders/249/builds/17221 - https://lab.llvm.org/buildbot/#/builders/38/builds/18566 - https://lab.llvm.org/buildbot/#/builders/214/builds/11735 - https://lab.llvm.org/buildbot/#/builders/231/builds/21947 - https://lab.llvm.org/buildbot/#/builders/230/builds/26675 - https://lab.llvm.org/buildbot/#/builders/57/builds/33922 - https://lab.llvm.org/buildbot/#/builders/124/builds/10311 - https://lab.llvm.org/buildbot/#/builders/109/builds/86173 - https://lab.llvm.org/buildbot/#/builders/280/builds/1043 - https://lab.llvm.org/buildbot/#/builders/283/builds/440 - https://lab.llvm.org/buildbot/#/builders/247/builds/16034 - https://lab.llvm.org/buildbot/#/builders/139/builds/62423 - https://lab.llvm.org/buildbot/#/builders/216/builds/36718 - https://lab.llvm.org/buildbot/#/builders/259/builds/2039 - https://lab.llvm.org/buildbot/#/builders/36/builds/44091 - https://lab.llvm.org/buildbot/#/builders/272/builds/12629 - https://lab.llvm.org/buildbot/#/builders/271/builds/6020 - https://lab.llvm.org/buildbot/#/builders/236/builds/10319
2024-03-28Reapply "[clang][nullability] allow _Nonnull etc on nullable class types ↵Sam McCall1-0/+12
(#82705)" This reverts commit ca4c4a6758d184f209cb5d88ef42ecc011b11642. This was intended not to introduce new consistency diagnostics for smart pointer types, but failed to ignore sugar around types when detecting this. Fixed and test added.
2024-03-15Revert "[clang][nullability] allow _Nonnull etc on nullable class types ↵Sam McCall1-12/+0
(#82705)" This reverts commit 92a09c0165b87032e1bd05020a78ed845cf35661. This is triggering a bunch of new -Wnullability-completeness warnings in code with existing raw pointer nullability annotations. The intent was the new nullability locations wouldn't affect those warnings, so this is a bug at least for now.
2024-03-14[clang][nullability] allow _Nonnull etc on nullable class types (#82705)Sam McCall1-0/+12
This enables clang and external nullability checkers to make use of these annotations on nullable C++ class types like unique_ptr. These types are recognized by the presence of the _Nullable attribute. Nullable standard library types implicitly receive this attribute. Existing static warnings for raw pointers are extended to smart pointers: - nullptr used as return value or argument for non-null functions (`-Wnonnull`) - assigning or initializing nonnull variables with nullable values (`-Wnullable-to-nonnull-conversion`) It doesn't implicitly add these attributes based on the assume_nonnull pragma, nor warn on missing attributes where the pragma would apply them. I'm not confident that the pragma's current behavior will work well for C++ (where type-based metaprogramming is much more common than C/ObjC). We'd like to revisit this once we have more implementation experience. Support can be detected as `__has_feature(nullability_on_classes)`. This is needed for back-compatibility, as previously clang would issue a hard error when _Nullable appears on a smart pointer. UBSan's `-fsanitize=nullability` will not check smart-pointer types. It can be made to do so by synthesizing calls to `operator bool`, but that's left for future work. Discussion: https://discourse.llvm.org/t/rfc-allowing-nonnull-etc-on-smart-pointers/77201/26
2023-12-11[clang] Add support for -fcx-limited-range, #pragma CX_LIMITED_RANGE and ↵Zahira Ammarguellat1-0/+8
-fcx-fortran-rules. (#70244) This patch adds the #pragma CX_LIMITED_RANGE defined in the C specification. It also adds the options -f[no]cx-limited-range and -f[no]cx-fortran-rules. -fcx-limited-range enables algebraic formulas for complex multiplication and division. This option is enabled with -ffast-math. -fcx-fortran-rules enables algebraic formulas for complex multiplication and enables Smith’s algorithm for complex division (SMITH, R. L. Algorithm 116: Complex division. Commun. ACM 5, 8 (1962)). --------- Signed-off-by: Med Ismail Bennani <ismail@bennani.ma> Co-authored-by: Joseph Huber <jhuber6@vols.utk.edu> Co-authored-by: Guray Ozen <guray.ozen@gmail.com> Co-authored-by: Nishant Patel <nishant.b.patel@intel.com> Co-authored-by: Jessica Clarke <jrtc27@jrtc27.com> Co-authored-by: Petr Hosek <phosek@google.com> Co-authored-by: Joseph Huber <35342157+jhuber6@users.noreply.github.com> Co-authored-by: Craig Topper <craig.topper@sifive.com> Co-authored-by: Alexander Yermolovich <43973793+ayermolo@users.noreply.github.com> Co-authored-by: Usama Hameed <u_hameed@apple.com> Co-authored-by: Philip Reames <preames@rivosinc.com> Co-authored-by: Evgenii Kudriashov <evgenii.kudriashov@intel.com> Co-authored-by: Fangrui Song <i@maskray.me> Co-authored-by: Aart Bik <39774503+aartbik@users.noreply.github.com> Co-authored-by: Valentin Clement <clementval@gmail.com> Co-authored-by: Youngsuk Kim <youngsuk.kim@hpe.com> Co-authored-by: Arthur Eubanks <aeubanks@google.com> Co-authored-by: Jan Svoboda <jan_svoboda@apple.com> Co-authored-by: Walter Erquinigo <a20012251@gmail.com> Co-authored-by: Eric <eric@efcs.ca> Co-authored-by: Fazlay Rabbi <106703039+mdfazlay@users.noreply.github.com> Co-authored-by: Pete Lawrence <plawrence@apple.com> Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com> Co-authored-by: Adrian Prantl <aprantl@apple.com> Co-authored-by: Owen Pan <owenpiano@gmail.com> Co-authored-by: LLVM GN Syncbot <llvmgnsyncbot@gmail.com> Co-authored-by: Med Ismail Bennani <ismail@bennani.ma> Co-authored-by: Congcong Cai <congcongcai0907@163.com> Co-authored-by: Rik Huijzer <github@huijzer.xyz> Co-authored-by: Wang Pengcheng <wangpengcheng.pp@bytedance.com> Co-authored-by: Yuanfang Chen <tabloid.adroit@gmail.com> Co-authored-by: Kazu Hirata <kazu@google.com> Co-authored-by: Mehdi Amini <joker.eph@gmail.com> Co-authored-by: Aiden Grossman <agrossman154@yahoo.com> Co-authored-by: Rana Pratap Reddy <109514914+ranapratap55@users.noreply.github.com> Co-authored-by: Yingwei Zheng <dtcxzyw2333@gmail.com> Co-authored-by: Piotr Zegar <me@piotrzegar.pl> Co-authored-by: KAWASHIMA Takahiro <t-kawashima@fujitsu.com> Co-authored-by: Tobias Hieta <tobias@hieta.se> Co-authored-by: Luke Lau <luke@igalia.com> Co-authored-by: Shivam Gupta <shivam98.tkg@gmail.com> Co-authored-by: cor3ntin <corentinjabot@gmail.com> Co-authored-by: Yeting Kuo <46629943+yetingk@users.noreply.github.com> Co-authored-by: Stanislav Mekhanoshin <rampitec@users.noreply.github.com> Co-authored-by: David Spickett <david.spickett@linaro.org> Co-authored-by: Matthew Devereau <matthew.devereau@arm.com> Co-authored-by: Martin Storsjö <martin@martin.st> Co-authored-by: Qiu Chaofan <qiucofan@cn.ibm.com> Co-authored-by: Pierre van Houtryve <pierre.vanhoutryve@amd.com> Co-authored-by: Mikael Holmen <mikael.holmen@ericsson.com> Co-authored-by: Uday Bondhugula <uday@polymagelabs.com> Co-authored-by: Nikita Popov <npopov@redhat.com> Co-authored-by: Johannes Reifferscheid <jreiffers@google.com> Co-authored-by: Benjamin Kramer <benny.kra@googlemail.com> Co-authored-by: Oliver Stannard <oliver.stannard@arm.com> Co-authored-by: Dmitry Vyukov <dvyukov@google.com> Co-authored-by: Benjamin Maxwell <benjamin.maxwell@arm.com> Co-authored-by: Piotr Sobczak <piotr.sobczak@amd.com> Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk> Co-authored-by: Timm Bäder <tbaeder@redhat.com> Co-authored-by: Sunil Kuravinakop <koops@hpe.com> Co-authored-by: zhongyunde 00443407 <zhongyunde@huawei.com> Co-authored-by: Christudasan Devadasan <Christudasan.Devadasan@amd.com> Co-authored-by: bjacob <jacob.benoit.1@gmail.com> Co-authored-by: Weining Lu <luweining@loongson.cn> Co-authored-by: Andrzej Warzyński <andrzej.warzynski@arm.com> Co-authored-by: Jay Foad <jay.foad@amd.com> Co-authored-by: Markus Mützel <markus.muetzel@gmx.de> Co-authored-by: Erik Jonsson <erik.j.jonsson@ericsson.com> Co-authored-by: Pete Steinfeld <47540744+psteinfeld@users.noreply.github.com> Co-authored-by: Alexey Bataev <a.bataev@outlook.com> Co-authored-by: Louis Dionne <ldionne.2@gmail.com> Co-authored-by: Qizhi Hu <836744285@qq.com>
2023-11-28clang: Add pragma clang fp reciprocal (#68267)Matt Arsenault1-3/+15
Just follow along with the reassociate pragma. This allows locally setting the arcp fast math flag. Previously you could only access this through the global -freciprocal-math. Fixes #64798
2023-04-13[clang] Type safety tweak for AttributeCommonInfo::FormRichard Sandiford1-1/+1
This patch adds static functions for constructing most AttributeCommonInfo::Forms. Direct construction is only retained where all fields (currently the syntax and spelling) are specified explicitly. This is a wash on its own. The purpose is to allow extra fields to be added to Form without disrupting all callers. In particular, it allows extra information to be stored about keywords without affecting non-keyword uses. No functional change intended. Differential Revision: https://reviews.llvm.org/D148104
2023-04-13[clang] Specify attribute syntax & spelling with a single argumentRichard Sandiford1-1/+0
When constructing an attribute, the syntactic form was specified using two arguments: an attribute-independent syntax type and an attribute-specific spelling index. This patch replaces them with a single argument. In most cases, that's done using a new Form class that combines the syntax and spelling into a single object. This has the minor benefit of removing a couple of constructors. But the main purpose is to allow additional information to be stored as well, beyond just the syntax and spelling enums. In the case of the attribute-specific Create and CreateImplicit functions, the patch instead uses the attribute-specific spelling enum. This helps to ensure that the syntax and spelling are consistent with each other and with the Attr.td definition. If a Create or CreateImplicit caller specified a syntax and a spelling, the patch drops the syntax argument and keeps the spelling. If the caller instead specified only a syntax (so that the spelling was SpellingNotCalculated), the patch simply drops the syntax argument. There were two cases of the latter: TargetVersion and Weak. TargetVersionAttrs were created with GNU syntax, which matches their definition in Attr.td, but which is also the default. WeakAttrs were created with Pragma syntax, which does not match their definition in Attr.td. Dropping the argument switches them to AS_GNU too (to match [GCC<"weak">]). Differential Revision: https://reviews.llvm.org/D148102
2023-04-12Set 'rounding_mode' to 'tonearest' with '#pragma STDC FENV_ACCESS OFF'.Zahira Ammarguellat1-0/+1
In strict mode the 'roundin_mode' is set to 'dynamic'. Using this pragma to get out of strict mode doesn't have any effect on the 'rounding_mode'. See https://godbolt.org/z/zoGTf4j1G This patch fixes that. Differential Revision: https://reviews.llvm.org/D147733
2023-03-28[clang][PowerPC] Remove remaining Darwin supportDavid Tenty1-2/+0
POWER Darwin support in the backend has been removed for some time: https://discourse.llvm.org/t/rfc-remove-darwin-support-from-power-backends but Clang still has the TargetInfo and other remnants lying around. This patch does some cleanup and removes those and other related frontend support still remaining. We adjust any tests using the triple to either remove the test if unneeded or switch to another Power triple. Reviewed By: MaskRay, nemanjai Differential Revision: https://reviews.llvm.org/D146459
2023-03-10Revert "Currently the control of the eval-method is mixed with fast-math."Zahira Ammarguellat1-17/+0
Setting __FLT_EVAL_METHOD__ to -1 with fast-math will set __GLIBC_FLT_EVAL_METHOD to 2 and long double ends up being used for float_t and double_t. This creates some ABI breakage with various C libraries. See details here: https://github.com/llvm/llvm-project/issues/60781 This reverts commit bbf0d1932a3c1be970ed8a580e51edf571b80fd5.
2023-01-14[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-4/+4
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14[clang] Add #include <optional> (NFC)Kazu Hirata1-0/+1
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03[Sema] Use std::nullopt instead of None (NFC)Kazu Hirata1-1/+1
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-09-19[clang] Add support for #pragma strict_gs_checkDavid Majnemer1-0/+13
2022-06-29[clang-cl] Handle some pragma alloc_text corner cases handled by MSVCStephen Long1-2/+7
MSVC's pragma alloc_text accepts a function that was redeclared in a non extern-C context if the previous declaration was in an extern-C context. i.e. ``` extern "C" { static void f(); } static void f(); ``` MSVC's pragma alloc_text also rejects non-functions. Reviewed By: hans Differential Revision: https://reviews.llvm.org/D128649
2022-06-24[MSVC] Add initial support for MSVC pragma optimizeStephen Long1-0/+16
MSVC's pragma optimize turns optimizations on or off based on the list passed. At the moment, we only support an empty optimization list. i.e. `#pragma optimize("", on | off)` From MSVC's docs: | Parameter | Type of optimization | |-----------|--------------------------------------------------| | g | Enable global optimizations. Deprecated | | s or t | Specify short or fast sequences of machine code | | y | Generate frame pointers on the program stack | https://docs.microsoft.com/en-us/cpp/preprocessor/optimize?view=msvc-170 Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D125723
2022-06-22Fix interaction of pragma FENV_ACCESS with other pragmasSerge Pavlov1-22/+8
Previously `#pragma STDC FENV_ACCESS ON` always set dynamic rounding mode and strict exception handling. It is not correct in the presence of other pragmas that also modify rounding mode and exception handling. For example, the effect of previous pragma FENV_ROUND could be cancelled, which is not conformant with the C standard. Also `#pragma STDC FENV_ACCESS OFF` turned off only FEnvAccess flag, leaving rounding mode and exception handling unchanged, which is incorrect in general case. Concrete rounding and exception mode depend on a combination of several factors like various pragmas and command-line options. During the review of this patch an idea was proposed that the semantic actions associated with such pragmas should only set appropriate flags. Actual rounding mode and exception handling should be calculated taking into account the state of all relevant options. In such implementation the pragma FENV_ACCESS should not override properties set by other pragmas but should set them if such setting is absent. To implement this approach the following main changes are made: - Field `FPRoundingMode` is removed from `LangOptions`. Actually there are no options that set it to arbitrary rounding mode, the choice was only `dynamic` or `tonearest`. Instead, a new boolean flag `RoundingMath` is added, with the same meaning as the corresponding command-line option. - Type `FPExceptionModeKind` now has possible value `FPE_Default`. It does not represent any particular exception mode but indicates that such mode was not set and default value should be used. It allows to distinguish the case: { #pragma STDC FENV_ACCESS ON ... } where the pragma must set FPE_Strict, from the case: { #pragma clang fp exceptions(ignore) #pragma STDC FENV_ACCESS ON ... } where exception mode should remain `FPE_Ignore`. - Class `FPOptions` has now methods `getRoundingMode` and `getExceptionMode`, which calculates the respective properties from other specified FP properties. - Class `LangOptions` has now methods `getDefaultRoundingMode` and `getDefaultExceptionMode`, which calculates default modes from the specified options and should be used instead of `getRoundingMode` and `getFPExceptionMode` of the same class. Differential Revision: https://reviews.llvm.org/D126364