aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaChecking.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-05-30[HIP] Add missing __hip_atomic_fetch_sub supportLuke Drummond1-0/+1
The rest of the fetch/op intrinsics were added in e13246a2ec3 but sub was conspicuous by its absence. Reviewed By: yaxunl Differential Revision: https://reviews.llvm.org/D151701
2023-05-28[Clang][AArch64][SME] Add vector load/store (ld1/st1) intrinsicsBryan Chan1-0/+11
This patch adds support for the following SME ACLE intrinsics (as defined in https://arm-software.github.io/acle/main/acle.html): - svld1_hor_za8 // also for _za16, _za32, _za64 and _za128 - svld1_hor_vnum_za8 // also for _za16, _za32, _za64 and _za128 - svld1_ver_za8 // also for _za16, _za32, _za64 and _za128 - svld1_ver_vnum_za8 // also for _za16, _za32, _za64 and _za128 - svst1_hor_za8 // also for _za16, _za32, _za64 and _za128 - svst1_hor_vnum_za8 // also for _za16, _za32, _za64 and _za128 - svst1_ver_za8 // also for _za16, _za32, _za64 and _za128 - svst1_ver_vnum_za8 // also for _za16, _za32, _za64 and _za128 SveEmitter.cpp is extended to generate arm_sme.h (currently named arm_sme_draft_spec_subject_to_change.h) and other SME definitions from arm_sme.td, which is modeled after arm_sve.td. Common TableGen definitions are moved into arm_sve_sme_incl.td. Co-authored-by: Sagar Kulkarni <sagar.kulkarni1@huawei.com> Reviewed By: sdesmalen, kmclaughlin Differential Revision: https://reviews.llvm.org/D127910
2023-05-24LLVM_FALLTHROUGH => [[fallthrough]]. NFCCraig Topper1-1/+1
Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D150996
2023-05-22[11/11][POC][Clang][RISCV] Define vset for tuple typeeopXD1-3/+6
For the cover letter of this patch-set, please checkout D146872. Depends on D147916. This is the 11th patch of the patch-set. This patch is a proof-of-concept and will be extended to full coverage in the future. Only vset for tuple type of NF=2, EEW=32, LMUL=1 is defined now. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D147917
2023-05-22[10/11][POC][Clang][RISCV] Define vget for tuple typeeopXD1-3/+6
For the cover letter of this patch-set, please checkout D146872. Depends on D147915. This is the 10th patch of the patch-set. This patch is a proof-of-concept and will be extended to full coverage in the future. Only vget for tuple type of NF=2, EEW=32, LMUL=1 is defined now. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D147916
2023-05-19[NVPTX/CUDA] added an optional src_size argument to __nvvm_cp_async*Artem Belevich1-0/+17
The optional argument is needed for CUDA-11+ headers when we're compiling for sm_80+ GPUs. Differential Revision: https://reviews.llvm.org/D150820
2023-05-18Revert "[NVPTX/CUDA] added an optional src_size argument to __nvvm_cp_async*"Artem Belevich1-17/+0
Breaks MLIR which happens to be using the intrinsics. This reverts commit e7b9c2f00fa04ef8d9b69ee0e36d7775823dbe6b.
2023-05-18[NVPTX/CUDA] added an optional src_size argument to __nvvm_cp_async*Artem Belevich1-0/+17
The optional argument is needed for CUDA-11+ headers when we're compiling for sm_80+ GPUs. Differential Revision: https://reviews.llvm.org/D150820
2023-05-16Migrate {starts,ends}with_insensitive to {starts,ends}_with_insensitive (NFC)Kazu Hirata1-5/+5
This patch migrates uses of StringRef::{starts,ends}with_insensitive to StringRef::{starts,ends}_with_insensitive so that we can use names similar to those used in std::string_view. Note that the llvm/ directory has migrated in commit 6c3ea866e93003e16fc55d3b5cedd3bc371d1fde. I'll post a separate patch to deprecate StringRef::{starts,ends}with_insensitive. Differential Revision: https://reviews.llvm.org/D150506
2023-05-10Reland "[PowerPC] Add target feature requirement to builtins"Qiu Chaofan1-139/+11
This relands D143467 after fixing build failure with GCC.
2023-05-08Revert "[PowerPC] Add target feature requirement to builtins"Vitaly Buka1-11/+139
Breaks PPC bots, see D143467. This reverts commit 651b0e2e7afca926c3d4f8d7f988db40b9832676.
2023-05-08[PowerPC] Add target feature requirement to builtinsQiu Chaofan1-139/+11
Clang has mechanism to specify required target features of a built-in function. This patch adds such definitions to Altivec, VSX, HTM, PairedVec and MMA builtins. This will help frontend to detect incompatible target features of bulitin when using target attribute syntax. Reviewed By: nemanjai, kamaub Differential Revision: https://reviews.llvm.org/D143467
2023-05-05Check if First argument in _builtin_assume_aligned_ is of pointer typeRishabh Bali1-1/+2
Currently clang doesn't verify if the first argument in `_builtin_assume_aligned` is of pointer type. This leads to an assertion build failure. This patch aims to add a check if the first argument is of pointer type or not and diagnose it with diag::err_typecheck_convert_incompatible if its not of pointer type. Fixes https://github.com/llvm/llvm-project/issues/62305 Differential Revision: https://reviews.llvm.org/D149514
2023-05-02[SiFive][RISCV][clang] Support C intrinsics for xsfvcp extension.Nelson Chu1-0/+121
Depends on D147934 and D147935 Differential Revision: https://reviews.llvm.org/D148223
2023-04-28[RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 ↵Craig Topper1-0/+7
arm_sve_vector_bits. This allows the user to set the size of the scalable vector so they can be used in structs and as the type of global variables. This works by representing the type as a fixed vector instead of a scalable vector in IR. Conversions to and from scalable vectors are made where necessary like function arguments/returns and intrinsics. This features has been requested here https://github.com/riscv-non-isa/rvv-intrinsic-doc/issues/176 I know arm_sve_vector_bits is used by the Eigen library so this could be used to port Eigen to RVV. This patch adds a new preprocessor define `__riscv_v_fixed_vlen` that is set when -mrvv_vector_bits is passed on the command line. The code is largely based on the AArch64 code. A lot of code was copy/pasted and then modiied to RVV. There may be some opportunities for sharing. This first patch only supports the LMUL=1 types. Additional changes will be needed to support other LMULs. I have also not supported mask vectors. Differential Revision: https://reviews.llvm.org/D145088
2023-04-24[RISCV] Support scalar/fix-length vector NTLH intrinsic with different domainPiyou Chen1-0/+59
This commit implements the two NTLH intrinsic functions. ``` type __riscv_ntl_load (type *ptr, int domain); void __riscv_ntl_store (type *ptr, type val, int domain); ``` ``` enum { __RISCV_NTLH_INNERMOST_PRIVATE = 2, __RISCV_NTLH_ALL_PRIVATE, __RISCV_NTLH_INNERMOST_SHARED, __RISCV_NTLH_ALL }; ``` We encode the non-temporal domain into MachineMemOperand flags. 1. Create the RISC-V built-in function with custom semantic checking. 2. Assume the domain argument is a compile time constant, and make it as LLVM IR metadata (nontemp_node). 3. Encode domain value as two bits MachineMemOperand TargetMMOflag. 4. According to MachineMemOperand TargetMMOflag, select corrsponding ntlh instruction. Currently, it supports scalar type and fixed-length vector type. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D143364
2023-04-06[Sema] Populate declarations inside TypeLocs for some invalid typesIlya Biryukov1-4/+1
This also reverts 282cae0b9a602267ad7ef622f770066491332a11 as the particular crash is now handled by the new code. Before this change Clang would always leave declarations inside the type-locs as `null` if the declarator had an invalid type. This patch populates declarations even for invalid types if the structure of the type and the type-locs match. There are certain cases that may still cause crashes. These happen when Clang recovers the type in a way that is not reflected in the declarator's structure, e.g. adding a pointer when it was not present in the code for ObjC interfaces or ignoring pointers written in the code in C++ with auto return type (`auto* foo() -> int`). Those cases look fixable with a better recovery strategy and I plan to follow up with more patches to address those. The first attempt caused 31 tests from `check-clang` to crash due to different structure of the types and type-locs after certain errors. The good news is that the failure is localized and mismatch in structures is discovered by assertions inside `DeclaratorLocFiller`. Some notable cases caught by existing tests: - Invalid chunks when type is fully ignored and replace with int or now. Crashed in `C/C2x/n2838.c`. - Invalid return types in lambdas. Crashed in `CXX/drs/dr6xx.cpp`. - Invalid member pointers. Crashed in `CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3-generic-lambda-1y.cpp` - ObjC recovery that adds pointers. Crashed in `SemaObjC/blocks.m` This change also updates the output of `Index/complete-blocks.m`. Not entirely sure what causes the change, but the new function signature is closer to the source code, so this seems like an improvement. Reviewed By: aaron.ballman, erichkeane Differential Revision: https://reviews.llvm.org/D146971
2023-04-05Fix a few clang-tidy warnings (container empty checks, function decl/def ↵David Blaikie1-11/+10
param naming)
2023-04-04[X86] Support AMX Complex instructionsXiang1 Zhang1-0/+2
Reviewed By: Wang Pengfei Differential Revision: https://reviews.llvm.org/D147420
2023-03-27Added checking for completeness of lvalue in conditional operatorAditya Singh1-0/+3
Given: ``` struct x y; int main(void) { (void)(1 ? y : y); } struct x {int i;}; ``` The conditional operator(?:) requires the second and third operands to be of compatible types. To be compatible, they also need to be complete (however, both can be void). Therefore, the expected response from clang after running the above code as a C program should be error dialogue pointing out that both the types are incomplete hence incompatible, but the code compiled without any errors. The patch ensures the completeness in the CheckCondtionalOperand function present in llvm-project/clang/lib/Sema/SemaChecking.cpp. Fixes https://github.com/llvm/llvm-project/issues/59718 Differential Revision: https://reviews.llvm.org/D144358
2023-03-21[Sema] Fix crash on __fp16 parameters in template instantiationsIlya Biryukov1-0/+4
Fixes #61441. Currently, Clang stores `nullptr` in the parameter lists inside `FunctionProtoTypeLoc` if `__fp16` is used without pointer qualifiers. Any code path that calls `Declarator::setInvalidType()` before `GetFullTypeForDeclarator` will lead to the same problem downstream. The relevant code is: ```cpp if (D.isInvalidType()) return Context.getTrivialTypeSourceInfo(T); return GetTypeSourceInfoForDeclarator(state, T, TInfo); ``` `GetTypeSourceInfoForDeclarator` sets the parameter `Decl`, but we can't call it when `isInvalidType() == true` as this causes other assertion failures that seem harder to fix. Reviewed By: kadircet Differential Revision: https://reviews.llvm.org/D146426
2023-03-17[clang][WebAssembly] Initial support for reference type funcref in clangPaulo Matos1-0/+21
This is the funcref counterpart to 890146b. We introduce a new attribute that marks a function pointer as a funcref. It also implements builtin __builtin_wasm_ref_null_func(), that returns a null funcref value. Differential Revision: https://reviews.llvm.org/D128440
2023-03-15Add __builtin_set_flt_roundsjinge901-0/+8
This builtin will be converted to llvm.set.rounding intrinsic in IR level and should be work with "#pragma STDC FENV_ACCESS ON" since it changes default FP environment. Users can change rounding mode via this builtin without introducing libc dependency. Reviewed by: andrew.w.kaylor, rjmccall, sepavloff, aaron.ballman Differential Revision: https://reviews.llvm.org/D145765 Signed-off-by: jinge90 <ge.jin@intel.com>
2023-03-09Add codegen for llvm exp/exp2 elementwise builtinsJoshua Batista1-0/+2
Add codegen for llvm exp/exp2 elementwise builtin The exp/exp2 elementwise builtins are necessary for HLSL codegen. Tests were added to make sure that the expected errors are encountered when these functions are given inputs of incompatible types. The new builtins are restricted to floating point types only. Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D145270
2023-03-09Revert "Add __builtin_set_flt_rounds"Aaron Ballman1-8/+0
This reverts commit 24b823554acd25009731b2519880aa18c7263550. These changes broke the PPC build bot.
2023-03-09Add __builtin_set_flt_roundsjinge901-0/+8
This builtin will be converted to llvm.set.rounding intrinsic in IR level and should be work with "#pragma STDC FENV_ACCESS ON" since it changes default FP environment. Users can change rounding mode via this builtin without introducing libc dependency. Reviewed by: andrew.w.kaylor, rjmccall, sepavloff Differential Revision: https://reviews.llvm.org/D144454 Signed-off-by: jinge90 <ge.jin@intel.com>
2023-02-24clang: Add __builtin_elementwise_fmaMatt Arsenault1-11/+41
I didn't understand why the other builtins have promotion logic, or how it would apply for a ternary operation. Implicit conversions are evil to begin with, and even more so when the purpose is to get an exact IR intrinsic. This checks all the arguments have the same type.
2023-02-21[clang]Fix warning for signed conversion on LP64Yaxun (Sam) Liu1-0/+6
Currently clang emits warning with -Wconversion for the following code on LP64 system e.g. x86_64-unknown-linux-gnu: long foo(long x) { return 1LL<<x; } warning: implicit conversion changes signedness: 'long long' to 'long' [-Wsign-conversion] return 1ll << x; ~~~~~~ ~~~~^~~~ This does not make sense since all operands are signed. This patch fixes that to match -m32 and GCC behaviour. Reviewed by: Fangrui Song Differential Revision: https://reviews.llvm.org/D144011
2023-02-19Use APInt::getSignificantBits instead of APInt::getMinSignedBits (NFC)Kazu Hirata1-2/+2
Note that getMinSignedBits has been soft-deprecated in favor of getSignificantBits.
2023-02-17[WebAssembly] Initial support for reference type externref in clangPaulo Matos1-0/+23
This patch introduces a new type __externref_t that denotes a WebAssembly opaque reference type. It also implements builtin __builtin_wasm_ref_null_extern(), that returns a null value of __externref_t. This lays the ground work for further builtins and reference types. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D122215
2023-02-07Add codegen for llvm log2/log10 elementwise builtinsJoshua Batista1-0/+2
Add codegen for llvm log2 / log10 elementwise builtin The log2/log10 elementwise builtin is necessary for HLSL codegen. Tests were added to make sure that the expected errors are encountered when these functions are given inputs of incompatible types. The new builtins are restricted to floating point types only. Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D143207
2023-02-07[NFC][TargetParser] Remove llvm/ADT/Triple.hArchibald Elliott1-1/+1
I also ran `git clang-format` to get the headers in the right order for the new location, which has changed the order of other headers in two files.
2023-02-05Revert "[clang][WebAssembly] Initial support for reference type externref in ↵Vitaly Buka1-23/+0
clang" Very likely breaks stage 3 of msan build bot. Good: 764c88a50ac76a2df2d051a0eb5badc6867aabb6 https://lab.llvm.org/buildbot/#/builders/74/builds/17058 Looks unrelated: 48b5a06dfcab12cf093a1a3df42cb5b684e2be4c Bad: 48b5a06dfcab12cf093a1a3df42cb5b684e2be4c https://lab.llvm.org/buildbot/#/builders/74/builds/17059 This reverts commit eb66833d19573df97034a81279eda31b8d19815b.
2023-02-03[Clang][SemaCXX][Coroutines] Fix misleading diagnostics with -WunsequencedBruno Cardoso Lopes1-0/+17
D115187 exposed CoroutineSuspendExpr's operand, which makes some nodes to show up twice during the traversal, confusing the check for unsequenced operations. Skip the operand since it's already handled as part of the common expression and get rid of the misleading warnings. https://github.com/llvm/llvm-project/issues/56768 Differential Revision: https://reviews.llvm.org/D142077
2023-02-03[Clang] Add builtin_nondeterministic_valueManuelJBrito1-0/+21
Differential Revision: https://reviews.llvm.org/D142388
2023-02-02Add builtin_elementwise_logJoshua Batista1-0/+1
Add codegen for llvm log elementwise builtin The log elementwise builtin is necessary for HLSL codegen. Tests were added to make sure that the expected errors are encountered when these functions are given inputs of incompatible types. The new builtin is restricted to floating point types only. Reviewed By: beanz Differential Revision: https://reviews.llvm.org/D140489
2023-02-02Revert "[Clang] Add builtin_nondeterministic_value"Nico Weber1-21/+0
This reverts commit 4a1832a5c801a61bf4c30891aaebe63993712fd9. Test fail on (at least) macOS and Windows, see https://reviews.llvm.org/D142388#4099441
2023-02-02[Clang] Add builtin_nondeterministic_valueManuelJBrito1-0/+21
Differential Revision: https://reviews.llvm.org/D142388
2023-01-31[Clang] Add machinery to catch overflow in unary minus outside of a constant ↵Shafik Yaghmour1-1/+1
expression context We provide several diagnostics for various undefined behaviors due to signed integer overflow outside of a constant expression context. We were missing the machinery to catch overflows due to unary minus. Fixes: https://github.com/llvm/llvm-project/issues/31643 Differential Revision: https://reviews.llvm.org/D142867
2023-01-31[clang][WebAssembly] Initial support for reference type externref in clangPaulo Matos1-0/+23
This patch introduces a new type __externref_t that denotes a WebAssembly opaque reference type. It also implements builtin __builtin_wasm_ref_null_extern(), that returns a null value of __externref_t. This lays the ground work for further builtins and reference types. Differential Revision: https://reviews.llvm.org/D122215
2023-01-29[Clang] Treat `std::forward_like` as builtinAlexander Shaposhnikov1-0/+1
This diff extends D123345 by adding support for std::forward_like. Test plan: ninja check-clang check-clang-tools check-llvm Differential revision: https://reviews.llvm.org/D142430
2023-01-23[AArch64] Check 128-bit Sysreg BuiltinsArchibald Elliott1-11/+45
This patch contains several related changes: 1. We move to using TARGET_BUILTIN for the 128-bit system register builtins to give better error messages when d128 has not been enabled, or has been enabled in a per-function manner. 2. We now validate the inputs to the 128-bit system register builtins, like we validate the other system register builtins. 3. We update the list of named PSTATE accessors for MSR (immediate), and now correctly enforce the expected ranges of the immediates. There is a long comment about how we chose to do this to comply with the ACLE when most of the PSTATE accessors for MSR (immediate) have aliased system registers for MRS/MSR which expect different values. In short, the MSR (immediate) names are prioritised, rather than falling-back to the register form when the value is out of range. Differential Revision: https://reviews.llvm.org/D140222
2023-01-14[clang] Remove remaining uses of llvm::Optional (NFC)Kazu Hirata1-1/+0
This patch removes several "using" declarations and #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] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-59/+74
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
2023-01-14Revert "[Clang][Sema] Enabled implicit conversion warning for ↵NAKAMURA Takumi1-18/+5
CompoundAssignment operator." This reverts commit 4c37671a7c946ac246b52fa44a6a649b89d6310b, aka llvmorg-16-init-17246-g4c37671a7c94 This caused many warnings in the current llvm codebase.
2023-01-13[Clang][Sema] Enabled implicit conversion warning for CompoundAssignment ↵Fahad Nayyar1-5/+18
operator. This change enables implicit conversion warnings (like Wshorten-64-to-32) for compound assignment operator with integral operands. rdar://10466193 Differential Revision: https://reviews.llvm.org/D139114
2023-01-10clang: Fix handling of __builtin_elementwise_copysignMatt Arsenault1-14/+56
I realized the handling of copysign made no sense at all. Only the type of the first operand should really matter, and it should not perform a conversion between them. Also fixes misleading errors and producing broken IR for integers. We could accept different FP types for the sign argument, if the intrinsic permitted different types like the DAG node. As it is we would need to insert a cast, which could have other effects (like trapping on snan) which should not happen for a copysign.
2023-01-09Move from llvm::makeArrayRef to ArrayRef deduction guides - clang/ partserge-sans-paille1-3/+3
This is a follow-up to https://reviews.llvm.org/D140896, split into several parts as it touches a lot of files. Differential Revision: https://reviews.llvm.org/D141139
2023-01-06[LoongArch] Add intrinsics for CACOP instructionXiaodong Liu1-0/+17
The CACOP instruction is mainly used for cache initialization and cache-consistency maintenance. Depends on D140872 Reviewed By: SixWeining Differential Revision: https://reviews.llvm.org/D140527