aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaChecking.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-05-23[AMDGPU][Clang] Add check of size for __builtin_amdgcn_global_load_lds (#93064)Shilei Tian1-0/+22
2024-05-23[clang] Introduce `SemaX86` (#93098)Vlad Serebrennikov1-851/+2
This patch moves `Sema` functions that are specific for x86 into the new `SemaX86` class. This continues previous efforts to split `Sema` up. Additional context can be found in #84184 and #92682.
2024-05-23Revert "[X86] Remove knl/knm specific ISAs supports (#92883)" (#93123)Freddy Ye1-0/+30
This reverts commit 282d2ab58f56c89510f810a43d4569824a90c538.
2024-05-23[X86] Remove knl/knm specific ISAs supports (#92883)Freddy Ye1-30/+0
Cont. patch after https://github.com/llvm/llvm-project/pull/75580
2024-05-22[clang] Introduce `SemaRISCV` (#92682)Vlad Serebrennikov1-969/+78
This patch moves `Sema` functions that are specific for RISC-V into the new `SemaRISCV` class. This continues previous efforts to split `Sema` up. Additional context can be found in https://github.com/llvm/llvm-project/pull/84184. This PR is somewhat different from previous PRs on this topic: 1. Splitting out target-specific functions wasn't previously discussed. It felt quite natural to do, though. 2. I had to make some static function in `SemaChecking.cpp` member functions of `Sema` in order to use them in `SemaRISCV`. 3. I dropped "RISCV" from identifiers, but decided to leave "RVV" (RISC-V "V" vector extensions) intact. I think it's an idiomatic abbreviation at this point, but I'm open to input from contributors in that area. 4. I repurposed `SemaRISCVVectorLookup.cpp` for `SemaRISCV`. I think this was a successful experiment, which both helps the goal of splitting `Sema` up, and shows a way to approach `SemaChecking.cpp`, which I wasn't sure how to approach before. As we move more target-specific function out of there, we'll gradually make the checking "framework" inside `SemaChecking.cpp` public, which is currently a whole bunch of static functions. This would enable us to move more functions outside of `SemaChecking.cpp`.
2024-05-17[clang] Implement CWG2428 "Deprecating a concept" (#92295)Vlad Serebrennikov1-0/+6
This patch allows attributes to be attached to C++20 concepts, implementing [CWG2428](https://cplusplus.github.io/CWG/issues/2428.html).
2024-05-13[clang] Introduce `SemaObjC` (#89086)Vlad Serebrennikov1-516/+12
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-05-09[Clang] Fix P2564 handling of variable initializers (#89565)Daniel M. Katz1-5/+4
The following program produces a diagnostic in Clang and EDG, but compiles correctly in GCC and MSVC: ```cpp #include <vector> consteval std::vector<int> fn() { return {1,2,3}; } constexpr int a = fn()[1]; ``` Clang's diagnostic is as follows: ```cpp <source>:6:19: error: call to consteval function 'fn' is not a constant expression 6 | constexpr int a = fn()[1]; | ^ <source>:6:19: note: pointer to subobject of heap-allocated object is not a constant expression /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.1/../../../../include/c++/14.0.1/bits/allocator.h:193:31: note: heap allocation performed here 193 | return static_cast<_Tp*>(::operator new(__n)); | ^ 1 error generated. Compiler returned: 1 ``` Based on my understanding of [`[dcl.constexpr]/6`](https://eel.is/c++draft/dcl.constexpr#6): > In any constexpr variable declaration, the full-expression of the initialization shall be a constant expression It seems to me that GCC and MSVC are correct: the initializer `fn()[1]` does not evaluate to an lvalue referencing a heap-allocated value within the `vector` returned by `fn()`; it evaluates to an lvalue-to-rvalue conversion _from_ that heap-allocated value. This PR turns out to be a bug fix on the implementation of [P2564R3](https://wg21.link/p2564r3); as such, it only applies to C++23 and later. The core problem is that the definition of a constant-initialized variable ([`[expr.const/2]`](https://eel.is/c++draft/expr.const#2)) is contingent on whether the initializer can be evaluated as a constant expression: > A variable or temporary object o is _constant-initialized_ if [...] the full-expression of its initialization is a constant expression when interpreted as a _constant-expression_, [...] That can't be known until we've finished parsing the initializer, by which time we've already added immediate invocations and consteval references to the current expression evaluation context. This will have the effect of evaluating said invocations as full expressions when the context is popped, even if they're subexpressions of a larger constant expression initializer. If, however, the variable _is_ constant-initialized, then its initializer is [manifestly constant-evaluated](https://eel.is/c++draft/expr.const#20): > An expression or conversion is _manifestly constant-evaluated_ if it is [...] **the initializer of a variable that is usable in constant expressions or has constant initialization** [...] which in turn means that any subexpressions naming an immediate function are in an [immediate function context](https://eel.is/c++draft/expr.const#16): > An expression or conversion is in an immediate function context if it is potentially evaluated and either [...] it is a **subexpression of a manifestly constant-evaluated expression** or conversion and therefore _are not to be considered [immediate invocations](https://eel.is/c++draft/expr.const#16) or [immediate-escalating expressions](https://eel.is/c++draft/expr.const#17) in the first place_: > An invocation is an _immediate invocation_ if it is a potentially-evaluated explicit or implicit invocation of an immediate function and **is not in an immediate function context**. > An expression or conversion is _immediate-escalating_ if **it is not initially in an immediate function context** and [...] The approach that I'm therefore proposing is: 1. Create a new expression evaluation context for _every_ variable initializer (rather than only nonlocal ones). 2. Attach initializers to `VarDecl`s _prior_ to popping the expression evaluation context / scope / etc. This sequences the determination of whether the initializer is in an immediate function context _before_ any contained immediate invocations are evaluated. 3. When popping an expression evaluation context, elide all evaluations of constant invocations, and all checks for consteval references, if the context is an immediate function context. Note that if it could be ascertained that this was an immediate function context at parse-time, we [would never have registered](https://github.com/llvm/llvm-project/blob/760910ddb918d77e7632be1678f69909384d69ae/clang/lib/Sema/SemaExpr.cpp#L17799) these immediate invocations or consteval references in the first place. Most of the test changes previously made for this PR are now reverted and passing as-is. The only test updates needed are now as follows: - A few diagnostics in `consteval-cxx2a.cpp` are updated to reflect that it is the `consteval tester::tester` constructor, not the more narrow `make_name` function call, which fails to be evaluated as a constant expression. - The reclassification of `warn_impcast_integer_precision_constant` as a compile-time diagnostic adds a (somewhat duplicative) warning when attempting to define an enum constant using a narrowing conversion. It also, however, retains the existing diagnostics which @erichkeane (rightly) objected to being lost from an earlier revision of this PR. --------- Co-authored-by: cor3ntin <corentinjabot@gmail.com>
2024-05-07[clang][hlsl] Add tan intrinsic part 1 (#90276)Farzon Lotfi1-0/+2
This change is an implementation of #87367's investigation on supporting IEEE math operations as intrinsics. Which was discussed in this RFC: https://discourse.llvm.org/t/rfc-all-the-math-intrinsics/78294 If you want an overarching view of how this will all connect see: https://github.com/llvm/llvm-project/pull/90088 Changes: - `clang/docs/LanguageExtensions.rst` - Document the new elementwise tan builtin. - `clang/include/clang/Basic/Builtins.td` - Implement the tan builtin. - `clang/lib/CodeGen/CGBuiltin.cpp` - invoke the tan intrinsic on uses of the builtin - `clang/lib/Headers/hlsl/hlsl_intrinsics.h` - Associate the tan builtin with the equivalent hlsl apis - `clang/lib/Sema/SemaChecking.cpp` - Add generic sema checks as well as HLSL specifc sema checks to the tan builtin - `llvm/include/llvm/IR/Intrinsics.td` - Create the tan intrinsic - `llvm/docs/LangRef.rst` - Document the tan intrinsic
2024-05-03[AMDGPU] Allow the `__builtin_flt_rounds` functions on AMDGPU (#90994)Joseph Huber1-8/+8
Summary: Previous patches added support for the LLVM rounding intrinsic functions. This patch allows them to me emitted using the clang builtins when targeting AMDGPU.
2024-05-02Implement a subset of builtin_cpu_supports() features (#82809)zhijian lin1-4/+2
The PR implements a subset of features of function __builtin_cpu_support() for AIX OS based on the information which AIX kernel runtime variable `_system_configuration` and function call `getsystemcfg()` of /usr/include/sys/systemcfg.h in AIX OS can provide. Following subset of features are supported in the PR "arch_3_00", "arch_3_1","booke","cellbe","darn","dfp","dscr" ,"ebb","efpsingle","efpdouble","fpu","htm","isel", "mma","mmu","pa6t","power4","power5","power5+","power6x","ppc32","ppc601","ppc64","ppcle","smt", "spe","tar","true_le","ucache","vsx"
2024-04-29[Clang] Add diagnostic about "%P" specifier with Objective-C pointers (#89977)Jared Grubb1-0/+11
A Darwin extension '%P' combined with an Objective-C pointer seems to always be a bug. '%P' will dump bytes at the pointed-to address (in contrast to '%p' which dumps the pointer itself). This extension is only allowed in "OS Log" contexts and is intended to be used like `%{uuid_t}.*16P` or `%{timeval}.*P`. If an ObjC pointer is used, then the internal runtime structure (aka, the is-a pointer and other runtime metadata) will be dumped, which (IMO) is never the expectation. A simple diagnostic can help flag these scenarios. Resolves https://github.com/llvm/llvm-project/issues/89968 Co-authored-by: Jared Grubb <jgrubb@apple.com>
2024-04-29[Clang] Add support for scalable vectors in __builtin_reduce_* functions ↵Lawrence Benson1-4/+19
(#87750) Currently, a lot of `__builtin_reduce_*` function do not support scalable vectors, i.e., ARM SVE and RISCV V. This PR adds support for them. The main code change is to use a different path to extract the type from the vectors, the rest is the same and LLVM supports the reduce functions for `vscale` vectors. This PR adds scalable vector support for: - `__builtin_reduce_add` - `__builtin_reduce_mul` - `__builtin_reduce_xor` - `__builtin_reduce_or` - `__builtin_reduce_and` - `__builtin_reduce_min` - `__builtin_reduce_max` Note: For all except `min/max`, the element type must still be an integer value. Adding floating point support for `add` and `mul` is still an open TODO.
2024-04-25[NFC] Generalize ArraySections to work for OpenACC in the future (#89639)Erich Keane1-2/+4
OpenACC is going to need an array sections implementation that is a simpler version/more restrictive version of the OpenMP version. This patch moves `OMPArraySectionExpr` to `Expr.h` and renames it `ArraySectionExpr`, then adds an enum to choose between the two. This also fixes a couple of 'drive-by' issues that I discovered on the way, but leaves the OpenACC Sema parts reasonably unimplemented (no semantic analysis implementation), as that will be a followup patch.
2024-04-24[Clang][AArch64] Extend diagnostics when warning non/streaming about vector ↵Dinar Temirbulatov1-5/+13
size difference (#88380) Add separate messages about passing arguments or returning parameters with scalable types. --------- Co-authored-by: Sander de Smalen <sander.desmalen@arm.com>
2024-04-22Carving out -Wformat warning about scoped enums into a subwarning (#88595)ZijunZhaoCCK1-3/+8
Make it part of -Wformat-pedantic. Fixes #81647
2024-04-19Reapply "[Clang][AArch64] Warn when calling non/streaming about vector size ↵Dinar Temirbulatov1-1/+21
difference (#79842)" This reverts commit 950bb097e11d6ee26533c00519c62df994322228
2024-04-19[Sema] Check if types are resolved before querying function description.Dinar Temirbulatov1-5/+9
2024-04-18[clang][NFC] Fix FieldDecl::isUnnamedBitfield() capitalization (#89048)Timm Baeder1-1/+1
We always capitalize bitfield as "BitField".
2024-04-17Revert "[Clang][AArch64] Warn when calling non/streaming about vector size ↵Dinar Temirbulatov1-21/+1
difference (#79842)" This reverts commit 4e85e1ffcaf161736e27a24c291c1177be865976
2024-04-16[clang][builtin] Implement __builtin_allow_runtime_check (#87568)Vitaly Buka1-0/+11
RFC: https://discourse.llvm.org/t/rfc-introduce-new-clang-builtin-builtin-allow-runtime-check/78281 --------- Co-authored-by: Noah Goldstein <goldstein.w.n@gmail.com> Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2024-04-13[clang] Implement `__is_pointer_interconvertible_base_of()` (#88473)Vlad Serebrennikov1-0/+21
This patch implements intrinsic that supports `std::is_pointer_interconvertible_base_of` type trait from [P0466R5](https://wg21.link/p0466r5) "Layout-compatibility and Pointer-interconvertibility Traits". Normative wording: > Comment: If `Base` and Derived are non-union class types and are not (possibly _cv_-qualified) versions of the same type, `Derived` is a complete type. > Condition: `Derived` is unambiguously derived from `Base` without regard to _cv_-qualifiers, and each object of type `Derived` is pointer-interconvertible (6.7.2 [basic.compound]) with its `Base` subobject, or `Base` and `Derived` are not unions and name the same class type without regard to _cv_-qualifiers. The paper also express the following intent: > Note that `is_pointer_interconvertible_base_of_v<T,T>` is always true under this wording, even though `T` is not derived from itself. I find the treatment of unions in the wording contradictory to this intent, and I'm not able to find anything relevant in minutes or on the reflector. That said, this patch implements what the wording says, since it's very explicit about unions.
2024-04-10[Clang][AArch64] Warn when calling non/streaming about vector size ↵Dinar Temirbulatov1-1/+21
difference (#79842) The compiler doesn't know in advance if the streaming and non-streaming vector-lengths are different, so it should be safe to give a warning diagnostic to warn the user about possible undefined behaviour. If the user knows the vector lengths are equal, they can disable the warning separately.
2024-04-09[PowerPC] Implement 32-bit expansion for rldimi (#86783)Qiu Chaofan1-1/+0
rldimi is 64-bit instruction, due to backward compatibility, it needs to be expanded into series of rotate and masking in 32-bit environment. In the future, we may improve bit permutation selector and remove such direct codegen.
2024-04-07[clang][NFC] Remove "Sema" prefix from Sema-related functions (#87914)Vlad Serebrennikov1-420/+412
@AaronBallman once noted that this prefix is a historical accident, and shouldn't be there. I agree.
2024-04-04[HLSL][DXIL][SPIRV] Implementation of an abstraction for intrinsic selection ↵Farzon Lotfi1-0/+1
of HLSL backends (#87171) Start of #83882 - `Builtins.td` - add the `hlsl` `all` elementwise builtin. - `CGBuiltin.cpp` - Show a use case for CGHLSLUtils via an `all` intrinsic codegen. - `CGHLSLRuntime.cpp` - move `thread_id` to use CGHLSLUtils. - `CGHLSLRuntime.h` - Create a macro to help pick the right intrinsic for the backend. - `hlsl_intrinsics.h` - Add the `all` api. - `SemaChecking.cpp` - Add `all` builtin type checking - `IntrinsicsDirectX.td` - Add the `all` `dx` intrinsic - `IntrinsicsSPIRV.td` - Add the `all` `spv` intrinsic Work still needed: - `SPIRVInstructionSelector.cpp` - Add an implementation of `OpAll` for `spv_all` intrinsic
2024-04-02Reapply "[clang][nullability] allow _Nonnull etc on nullable class types ↵Sam McCall1-0/+9
(#82705)" (#87325) This reverts commit 28760b63bbf9e267713957105a8d17091fb0d20e. The last commit was missing the new testcase, now fixed.
2024-03-31[Sema] Implement support for -Wformat-signedness (#74440)Karl-Johan Karlsson1-2/+31
In gcc there exist a modifier option -Wformat-signedness that turns on additional signedness warnings in the already existing -Wformat warning. This patch implements that support in clang. This is done by adding a dummy warning diag::warn_format_conversion_argument_type_mismatch_signedness that is never emitted and only used as an option to toggle the signedness warning in -Wformat. This will ensure gcc compatibility.
2024-03-29[HLSL][DXIL] HLSL's `round` should follow `roundeven` behavior (#87078)Farzon Lotfi1-0/+1
fixes #86999
2024-03-29Revert "Reapply "[clang][nullability] allow _Nonnull etc on nullable class ↵dyung1-9/+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/+9
(#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-28[HLSL] prevent generation of wrong double intrinsics. (#86932)Andrii Levitskiy1-1/+5
As #86555, we should cover all of non-double builtins. Closes #86818
2024-03-27[HLSL] enforce unsigned types for reversebits (#86720)Farzon Lotfi1-0/+13
fixes #86719 - `SemaChecking.cpp` - Adds unsigned semaChecks to `__builtin_elementwise_bitreverse` - `hlsl_intrinsics.h` - remove signed `reversebits` apis
2024-03-27[clang][RISCV] Enable RVV with function attribute ↵Brandon Wu1-61/+9
__attribute__((target("arch=+v"))) (#83674) It is currently not possible to use "RVV type" and "RVV intrinsics" if the "zve32x" is not enabled globally. However in some cases we may want to use them only in some functions, for instance: ``` #include <riscv_vector.h> __attribute__((target("+zve32x"))) vint32m1_t rvv_add(vint32m1_t v1, vint32m1_t v2, size_t vl) { return __riscv_vadd(v1, v2, vl); } int other_add(int i1, int i2) { return i1 + i2; } ``` , it is supposed to be compilable even the vector is not specified, e.g. `clang -target riscv64 -march=rv64gc -S test.c`.
2024-03-26[NFC] Refactor ConstantArrayType size storage (#85716)Chris B1-4/+4
In PR #79382, I need to add a new type that derives from ConstantArrayType. This means that ConstantArrayType can no longer use `llvm::TrailingObjects` to store the trailing optional Expr*. This change refactors ConstantArrayType to store a 60-bit integer and 4-bits for the integer size in bytes. This replaces the APInt field previously in the type but preserves enough information to recreate it where needed. To reduce the number of places where the APInt is re-constructed I've also added some helper methods to the ConstantArrayType to allow some common use cases that operate on either the stored small integer or the APInt as appropriate. Resolves #85124.
2024-03-26[NFC][Clang] Fix potential dereferencing of nullptr (#85944)smanna121-1/+1
This patch replaces getAs<> with castAs<> to resolve potential static analyzer bugs for 1. Dereferencing a pointer issue with nullptr FPT when calling ResolveExceptionSpec() in checkEscapingByref(clang::VarDecl *, clang::Sema &). 3. Dereferencing a pointer issue with nullptr ElementTy->getAs() when calling getElementType() in clang::Sema::SemaBuiltinFPClassification(clang::CallExpr *, unsigned int). 4. Dereferencing a pointer issue with nullptr ConvType->getAs() when calling getKeyword() in clang::Sema::ActOnConversionDeclarator(clang::CXXConversionDecl *).
2024-03-25[HLSL] prevent generation of double intrinsics via the builtins (#86555)Farzon Lotfi1-0/+15
fixes #86551 closes #86552 Thanks to #86440 and #86407 it makes more sense for us to do type checks early via Sema to prevent the generation of invalid intrinsics.
2024-03-21[clang] Implement __builtin_{clzg,ctzg} (#83431)OverMighty1-0/+47
Fixes #83075, fixes #83076.
2024-03-19[HLSL] Fix for build break introduced by #85662 (#85839)Farzon Lotfi1-4/+2
This change fixes a test case failure caused by pr #85662
2024-03-19[DXIL] implement dot intrinsic lowering for integers (#85662)Farzon Lotfi1-0/+14
this implements part 1 of 2 for #83626 - `CGBuiltin.cpp` - modified to have seperate cases for signed and unsigned integers. - `SemaChecking.cpp` - modified to prevent the generation of a double dot product intrinsic if the builtin were to be called directly. - `IntrinsicsDirectX.td` creation of the signed and unsigned dot intrinsics needed for instruction expansion. - `DXILIntrinsicExpansion.cpp` - handle instruction expansion cases for integer dot product.
2024-03-18fix unnecessary warning when using bitand with boolean operators (#81976)Bhuminjay Soni1-6/+20
This pull request fixes #77601 where using the `bitand` operator with boolean operands should not trigger the warning, as it would indicate an intentional use of bitwise AND rather than a typo or error. Fixes #77601
2024-03-18[PowerPC] Fix behavior of rldimi/rlwimi/rlwnm builtins (#85040)Qiu Chaofan1-1/+4
rldimi is 64-bit instruction, so the corresponding builtin should not be available in 32-bit mode. Rotate amount should be in range and cases when mask is zero needs special handling. This change also swaps the first and second operands of rldimi/rlwimi to match previous behavior. For masks not ending at bit 63-SH, rotation will be inserted before rldimi.
2024-03-15[HLSL] implement `clamp` intrinsic (#85424)Farzon Lotfi1-1/+14
closes #70071 - `CGBuiltin.cpp` - Add the unsigned\generic clamp intrinsic emitter. - `IntrinsicsDirectX.td` - add the `dx.clamp` & `dx.uclamp` intrinsics - `DXILIntrinsicExpansion.cpp` - add the `clamp` instruction expansion while maintaining vector form. - `SemaChecking.cpp` - Add `clamp` builtin Sema Checks. - `Builtins.td` - add a `clamp` builtin - `hlsl_intrinsics.h` - add the `clamp` api Why `clamp` as instruction expansion for DXIL? 1. SPIR-V has a GLSL `clamp` extension via: - [FClamp](https://registry.khronos.org/SPIR-V/specs/1.0/GLSL.std.450.html#FClamp) - [UClamp](https://registry.khronos.org/SPIR-V/specs/1.0/GLSL.std.450.html#UClamp) - [SClamp](https://registry.khronos.org/SPIR-V/specs/1.0/GLSL.std.450.html#SClamp) 2. Further Clamp lowers to `min(max( x, min_range ), max_range)` which we have float, signed, & unsigned dixilOps.
2024-03-15[AArch64][PAC] Support ptrauth builtins and -fptrauth-intrinsics. (#65996)Ahmed Bougacha1-0/+197
This defines the basic set of pointer authentication clang builtins (provided in a new header, ptrauth.h), with diagnostics and IRGen support. The availability of the builtins is gated on a new flag, `-fptrauth-intrinsics`. Note that this only includes the basic intrinsics, and notably excludes `ptrauth_sign_constant`, `ptrauth_type_discriminator`, and `ptrauth_string_discriminator`, which need extra logic to be fully supported. This also introduces clang/docs/PointerAuthentication.rst, which describes the ptrauth model in general, in addition to these builtins. Co-Authored-By: Akira Hatanaka <ahatanaka@apple.com> Co-Authored-By: John McCall <rjmccall@apple.com>
2024-03-15Revert "[clang][nullability] allow _Nonnull etc on nullable class types ↵Sam McCall1-9/+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[DXIL] `exp`, `any`, `lerp`, & `rcp` Intrinsic Lowering (#84526)Farzon Lotfi1-14/+37
This change implements lowering for #70076, #70100, #70072, & #70102 `CGBuiltin.cpp` - - simplify `lerp` intrinsic `IntrinsicsDirectX.td` - simplify `lerp` intrinsic `SemaChecking.cpp` - remove unnecessary check `DXILIntrinsicExpansion.*` - add intrinsic to instruction expansion cases `DXILOpLowering.cpp` - make sure `DXILIntrinsicExpansion` happens first `DirectX.h` - changes to support new pass `DirectXTargetMachine.cpp` - changes to support new pass Why `any`, and `lerp` as instruction expansion just for DXIL? - SPIR-V there is an [OpAny](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpAny) - SPIR-V has a GLSL lerp extension via [Fmix](https://registry.khronos.org/SPIR-V/specs/1.0/GLSL.std.450.html#FMix) Why `exp` instruction expansion? - We have an `exp2` opcode and `exp` reuses that opcode. So instruction expansion is a convenient way to do preprocessing. - Further SPIR-V has a GLSL exp extension via [Exp](https://registry.khronos.org/SPIR-V/specs/1.0/GLSL.std.450.html#Exp) and [Exp2](https://registry.khronos.org/SPIR-V/specs/1.0/GLSL.std.450.html#Exp2) Why `rcp` as instruction expansion? This one is a bit of the odd man out and might have to move to `cgbuiltins` when we better understand SPIRV requirements. However I included it because it seems like [fast math mode has an AllowRecip flag](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_fp_fast_math_mode) which lets you compute the reciprocal without performing the division. We don't have that in DXIL so thought to include it.
2024-03-14[HLSL] implement the `isinf` intrinsic (#84927)Farzon Lotfi1-0/+17
This change implements part 1 of 2 for #70095 - `hlsl_intrinsics.h` - add the `isinf` api - `Builtins.td` - add an hlsl builtin for `isinf`. - `CGBuiltin.cpp` add the ir generation for `isinf` intrinsic. - `SemaChecking.cpp` - add a non-math elementwise checks because this is a bool return. - `IntrinsicsDirectX.td` - add an `isinf` intrinsic. `DXIL.td` lowering is left, but changes need to be made there before we can support this case.
2024-03-14[HLSL] Implement `rsqrt` intrinsic (#84820)Farzon Lotfi1-2/+3
This change implements #70074 - `hlsl_intrinsics.h` - add the `rsqrt` api - `DXIL.td` add the llvm intrinsic to DXIL op lowering map. - `Builtins.td` - add an hlsl builtin for rsqrt. - `CGBuiltin.cpp` add the ir generation for the rsqrt intrinsic. - `SemaChecking.cpp` - reuse the one arg float only checks. - `IntrinsicsDirectX.td` -add an `rsqrt` intrinsic.
2024-03-14[clang][nullability] allow _Nonnull etc on nullable class types (#82705)Sam McCall1-0/+9
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
2024-03-08[clang] Fix -Wunused-variable in SemaChecking.cpp (NFC)Jie Fu1-2/+4
llvm-project/clang/lib/Sema/SemaChecking.cpp:19192:15: error: unused variable 'Field1Parent' [-Werror,-Wunused-variable] const Type *Field1Parent = Field1->getParent()->getTypeForDecl(); ^ llvm-project/clang/lib/Sema/SemaChecking.cpp:19193:15: error: unused variable 'Field2Parent' [-Werror,-Wunused-variable] const Type *Field2Parent = Field2->getParent()->getTypeForDecl(); ^ 2 errors generated.