aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaChecking.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-12-25[clang] Use StringRef::consume_front (NFC)Kazu Hirata1-2/+2
2023-12-18[RISCV] Remove experimental from Vector Crypto extensions (#74213)Eric Biggers1-1/+1
The RISC-V vector crypto extensions have been ratified. This patch updates the Clang and LLVM support for these extensions to be non-experimental, while leaving the C intrinsics as experimental since the C intrinsics are not yet standardized. Co-authored-by: Brandon Wu <brandon.wu@sifive.com>
2023-12-18[Clang][SME] Warn when a function doesn't have ZA state (#75805)Sam Tebbs1-0/+24
This patch adds a warning that's emitted when a builtin call uses ZA state but the calling function doesn't provide any. Patch by David Sherwood <david.sherwood@arm.com>.
2023-12-18[AArch64][SME] Warn when using a streaming builtin from a non-streaming ↵Sam Tebbs1-4/+47
function (#75487) This PR adds a warning that's emitted when a non-streaming or non-streaming-compatible builtin is called in an unsuitable function. Uses work by Kerry McLaughlin. This is a re-upload of #74064 and fixes a compile time increase.
2023-12-14[RISCV] Remove 'experimental-' from extension name in diagnostic message.Craig Topper1-3/+3
I'm not sure how to test this because the intrinsic availability already seems to check this.
2023-12-14[Sema] atomic_compare_exchange: check failure memory order (#74959)Fangrui Song1-8/+26
For `__atomic_compare_exchange{,_n}/__c11_atomic_compare_exchange_{strong,weak}`, GCC checks both the success memory order and the failure memory order under the default -Winvalid-memory-model ("memory model" is confusing here and "memory order" is much more common in the atomic context). * The failure memory order, if a constant, must be one of relaxed/consume/acquire/seq_cst. Clang checks just the success memory order under the default -Watomic-memory-ordering. This patch checks the failure memory order.
2023-12-14Revert "[AArch64][SME] Warn when using a streaming builtin from a ↵Sam Tebbs1-52/+4
non-streaming function" (#75449) Reverts llvm/llvm-project#74064
2023-12-14[AArch64][SME] Warn when using a streaming builtin from a non-streaming ↵Sam Tebbs1-4/+52
function (#74064) This PR adds a warning that's emitted when a non-streaming or non-streaming-compatible builtin is called in an unsuitable function. Uses work by Kerry McLaughlin.
2023-12-13[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)Kazu Hirata1-6/+5
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-12-11[RISCV] Correct the SEW=64 MUL diagnostic to refer to V as an extension.Craig Topper1-1/+1
This makes it consistent with other builtins that require a specific extension.
2023-12-11[RISCV] Simplify checking whether SEW=64 multiply builtins require V. NFCCraig Topper1-5/+3
We only need to check the result type. Use getBuiltinVectorTypeInfo to lookup the element size.
2023-12-11[RISCV] Use getBuiltinVectorTypeInfo to simplify code. NFCCraig Topper1-6/+4
2023-12-08[RISCV] Remove Type::isRVVType() and replace with ↵Craig Topper1-1/+1
isRVVSizelessBuiltinType(). NFC These both do the same thing, but some profiling on a Releast+Asserts build suggests isRVVSizelessBuiltinType() is the more efficient version so lets keep that one.
2023-12-07[Clang] Introduce scoped variants of GNU atomic functions (#72280)Joseph Huber1-2/+37
Summary: The standard GNU atomic operations are a very common way to target hardware atomics on the device. With more heterogenous devices being introduced, the concept of memory scopes has been in the LLVM language for awhile via the `syncscope` modifier. For targets, such as the GPU, this can change code generation depending on whether or not we only need to be consistent with the memory ordering with the entire system, the single GPU device, or lower. Previously these scopes were only exported via the `opencl` and `hip` variants of these functions. However, this made it difficult to use outside of those languages and the semantics were different from the standard GNU versions. This patch introduces a `__scoped_atomic` variant for the common functions. There was some discussion over whether or not these should be overloads of the existing ones, or simply new variants. I leant towards new variants to be less disruptive. The scope here can be one of the following ``` __MEMORY_SCOPE_SYSTEM // All devices and systems __MEMORY_SCOPE_DEVICE // Just this device __MEMORY_SCOPE_WRKGRP // A 'work-group' AKA CUDA block __MEMORY_SCOPE_WVFRNT // A 'wavefront' AKA CUDA warp __MEMORY_SCOPE_SINGLE // A single thread. ``` Naming consistency was attempted, but it is difficult to capture to full spectrum with no many names. Suggestions appreciated.
2023-12-06[Clang][NFC] Refactor out code from CheckSVEBuiltinFunctionCall into ↵Samuel Tebbs1-46/+51
ParseSVEImmChecks This moves code from CheckSVEBuiltinFunctionCall into ParseSVEImmChecks in preparation for #74064
2023-12-05[clang] Reject incomplete type arguments for __builtin_dump_struct (#72749)Younan Zhang1-2/+7
We used to assume that the CXXRecordDecl passed to the 1st argument always had a definition. This is not true since a pointer to an incomplete type was not excluded. Fixes https://github.com/llvm/llvm-project/issues/63506
2023-11-30[AArch64] Warn when calling a NEON builtin in a streaming function (#73672)Sam Tebbs1-0/+49
This patch introduces a warning that is emitted when a Neon builtin is called from a streaming function, as that situation is not supported. Uses work by Kerry McLaughlin.
2023-11-21[SVE2.1][Clang][LLVM]Add 128bits builtin in Clang and LLVM intrinisc (#71930)CarolineConcatto1-0/+12
This patch implements the builtins in Clang and the LLVM-IR intrinsic for the following: EXTQ // Variants are also available for: // _s8, _s16, _u16, _s32, _u32, _s64, _u64 // _bf16, _f16, _f32, _f64 svuint8_t svextq_lane[_u8](svuint8_t zdn, svuint8_t zm, uint64_t imm); TBLQ and TBXQ // Variants are also available for: // _u8, _u16, _s16, _u32, _s32, _u64, _s64 // _bf16, _f16, _f32, _f64 svint8_t svtblq[_s8](svint8_t zn, svuint8_t zm); svint8_t svtbxq[_s8](svint8_t zn, svuint8_t zm); UZPQ1, UZPQ2, ZIPQ1 and ZIPQ2 // Variants are also available for: // _s8, _u16, _s16, _u32, _s32, _u64, _s64 // _bf16, _f16, _f32, _f64 svuint8_t svuzpq1[_u8](svuint8_t zn, svuint8_t zm); svuint8_t svuzpq2[_u8](svuint8_t zn, svuint8_t zm); svuint8_t svzipq1[_u8](svuint8_t zn, svuint8_t zm); svuint8_t svzipq2[_u8](svuint8_t zn, svuint8_t zm); PMOV // Variants are available for: // _s8, _u16, _s16, _s32, _u32, _s64, _u64 svbool_t svpmov_lane[_u8](svuint8_t zn, uint64_t imm); svbool_t svpmov[_u8](svuint8_t zn); // The immediate is zero svuint8_t svpmov_u8_z(svbool_t pn); // The immediate is zero // Variants are available for: // _s16, _s32, _u32, _s64, _u64 svuint16_t svpmov_lane[_u16]_m(svuint16_t zd, svbool_t pn, uint64_t imm); According to the PR#257[1] [1]ARM-software/acle#257 Co-authored-by: Hassnaa Hamdi <hassnaa.hamdi@arm.com>
2023-11-06[RISCV] Introduce and use BF16 in Xsfvfwmaccqqq intrinsics (#71140)Shao-Ce SUN1-0/+5
BF16 implementation based on @joshua-arch1's https://reviews.llvm.org/D152498 Fixed the incorrect f16 type introduced in https://github.com/llvm/llvm-project/pull/68296 --------- Co-authored-by: Jun Sha (Joshua) <cooper.joshua@linux.alibaba.com>
2023-11-05[clang][NFC] Refactor `StringLiteral::StringKind`Vlad Serebrennikov1-1/+1
This patch converts `StringLiteral::StringKind` to a scoped enum in namespace scope. This enabled forward-declarations of this enum where necessary, e.g. for `preferred_type` annotation for bit-fields.
2023-11-02[clang][NFC] Refactor `clang::Linkage` (#71049)Vlad Serebrennikov1-1/+1
This patch introduces a new enumerator `Invalid = 0`, shifting other enumerators by +1. Contrary to how it might sound, this actually affirms status quo of how this enum is stored in `clang::Decl`: ``` /// If 0, we have not computed the linkage of this declaration. /// Otherwise, it is the linkage + 1. mutable unsigned CacheValidAndLinkage : 3; ``` This patch makes debuggers to not be mistaken about enumerator stored in this bit-field. It also converts `clang::Linkage` to a scoped enum.
2023-11-01[clang] Additional FP classification functions (#69041)Serge Pavlov1-0/+3
C language standard defined library functions `iszero`, `issignaling` and `issubnormal`, which did not have counterparts among clang builtin functions. This change adds new functions: __builtin_iszero __builtin_issubnormal __builtin_issignaling They provide builtin implementation for the missing standard functions. Pull request: https://github.com/llvm/llvm-project/pull/69041
2023-10-31[clang][NFC] Refactor `VectorType::VectorKind`Vlad Serebrennikov1-3/+3
This patch moves `VectorKind` to namespace scope, and make it complete at the point its bit-field is declared. It also converts it to a scoped enum.
2023-10-31[clang][NFC] Refactor `ArrayType::ArraySizeModifier`Vlad Serebrennikov1-1/+1
This patch moves `ArraySizeModifier` before `Type` declaration so that it's complete at `ArrayTypeBitfields` declaration. It's also converted to scoped enum along the way.
2023-10-31[Clang][LoongArch] Support the builtin functions for LASXlicongtian1-0/+227
This patch does the following work: - Define the builtin functions for LASX - Add the header files lasxintrin.h
2023-10-31[Clang][LoongArch] Support the builtin functions for LSXlicongtian1-1/+228
This patch does the following work: - Define the builtin functions for LSX - Add the header file lsxintrin.h - Add the immediate number range checking for LSX builtins
2023-10-23Revert "[Sema] Add check for bitfield assignments to integral types (#69049)"Kadir Cetinkaya1-12/+1
This reverts commit 708808e8532e7c3647356aec0664fcf94b1093d1 which is causing crashes on valid code, see https://github.com/llvm/llvm-project/pull/69049#issuecomment-1775538177.
2023-10-19[Clang] Add __builtin_vectorelements to get number of elements in vector ↵Lawrence Benson1-2/+3
(#69010) Adds a new `__builtin_vectorelements()` function which returns the number of elements for a given vector either at compile-time for fixed-sized vectors, e.g., created via `__attribute__((vector_size(N)))` or at runtime via a call to `@llvm.vscale.i32()` for scalable vectors, e.g., SVE or RISCV V. The new builtin follows a similar path as `sizeof()`, as it essentially does the same thing but for the number of elements in vector instead of the number of bytes. This allows us to re-use a lot of the existing logic to handle types etc. A small side addition is `Type::isSizelessVectorType()`, which we need to distinguish between sizeless vectors (SVE, RISCV V) and sizeless types (WASM). This is the [corresponding discussion](https://discourse.llvm.org/t/new-builtin-function-to-get-number-of-lanes-in-simd-vectors/73911).
2023-10-18[Sema] Add check for bitfield assignments to integral types (#69049)vabridgers1-1/+12
This change introduces the bitfield conversion check after fixes to the test case. The original submission unfortunately did not comprehend differences in architecture for the diagnostic messages, leading to unanticipated failures in the arm build bots. Original PR: https://github.com/llvm/llvm-project/pull/68276 Clang does not check for bitfield assignment widths, while gcc checks this. gcc produced a warning like so for it's -Wconversion flag: ``` $ gcc -Wconversion -c test.c test.c: In function 'foo': test.c:10:15: warning: conversion from 'int' to 'signed char:7' may change value [-Wconversion] 10 | vxx.bf = x; // no warning | ^ ``` This change simply adds this check for integral types under the -Wbitfield-conversion compiler option.
2023-10-17[Clang][SVE2.1] Add svcntp prototypeCaroline Concatto1-0/+5
As described in: https://github.com/ARM-software/acle/pull/257 Patch by : David Sherwood <david.sherwood@arm.com> Reviewed By: sdesmalen Differential Revision: https://reviews.llvm.org/D150961
2023-10-17[clang] Implement C23 <stdckdint.h>zijunzhao1-3/+31
https://github.com/llvm/llvm-project/issues/62248 Reviewed By: yabinc, aaron.ballman, #clang-language-wg Differential Revision: https://reviews.llvm.org/D157331
2023-10-13Revert "[Sema] Add check for bitfield assignments to integral types" (#68963)vabridgers1-12/+1
This reverts commit 47e36266e93de9c34ba3028951a58124864bb2b4. This change broke some arm8/arm7 build bots because int and void * have the same size. Co-authored-by: einvbri <vince.a.bridgers@ericsson.com>
2023-10-13[Clang] Fix tautological assertion in `Sema::CheckX86BuiltinTileDuplicate`Yingwei Zheng1-1/+1
Closes #68958.
2023-10-12[Sema] Add check for bitfield assignments to larger integral types (#68276)vabridgers1-1/+12
We noticed that clang does not check for bitfield assignment widths, while gcc does check this. gcc produced a warning like so for it's -Wconversion flag: ``` $ gcc -Wconversion -c test.c test.c: In function 'foo': test.c:10:15: warning: conversion from 'int' to 'signed char:7' may change value [-Wconversion] 10 | vxx.bf = x; // no warning | ^ ``` This change simply adds this check for integral types under the -Wbitfield-conversion compiler option.
2023-10-10[Sema] Handle large shift counts in GetExprRange (#68590)Björn Pettersson1-3/+2
GetExprRange did not expect that very large shift counts when narrowing the range based on logical right shifts. So with inputs such as *a >> 123456789012345678901uwb it would hit assertions about trying to convert a too large APInt into uint64_t. This patch fixes that by using the APInt value when determining if we should reduce the range by the shift count or not.
2023-10-05Revert "[X86] Change target of __builtin_ia32_cmp[p|s][s|d] from avx into ↵Bogdan Graur1-4/+0
sse/sse2 (#67410)" Does not respect `__attribute__((target("avx"))`. This reverts commit ccd5b8db48a4cfa9e6868301cbab5fe033434e46.
2023-10-05[Clang] Handle consteval expression in array bounds expressions (#66222)cor3ntin1-26/+31
The bounds of a c++ array is a _constant-expression_. And in C++ it is also a constant expression. But we also support VLAs, ie arrays with non-constant bounds. We need to take care to handle the case of a consteval function (which are specified to be only immediately called in non-constant contexts) that appear in arrays bounds. This introduces `Sema::isAlwayConstantEvaluatedContext`, and a flag in ExpressionEvaluationContextRecord, such that immediate functions in array bounds are always immediately invoked. Sema had both `isConstantEvaluatedContext` and `isConstantEvaluated`, so I took the opportunity to cleanup that. The change in `TimeProfilerTest.cpp` is an unfortunate manifestation of the problem that #66203 seeks to address. Fixes #65520
2023-10-02[Sema] Use underlying type of scoped enum for -Wformat diagnostics (#67378)Shoaib Meenai1-13/+12
Right now, `-Wformat` for a scoped enum will suggest a cast based on the format specifier being used. This can lead to incorrect results, e.g. attempting to format a scoped enum with `%s` would suggest casting to `char *` instead of fixing the specifier. Change the logic to treat the scoped enum's underlying type as the intended type to be printed, and suggest format specifier changes and casts based on that.
2023-10-02[C++] Implement "Deducing this" (P0847R7)Corentin Jabot1-21/+28
This patch implements P0847R7 (partially), CWG2561 and CWG2653. Reviewed By: aaron.ballman, #clang-language-wg Differential Revision: https://reviews.llvm.org/D140828
2023-09-27Revert "[clang][SemaCXX] Diagnose tautological uses of consteval if and ↵Sam McCall1-35/+14
is_constant_evaluated" This reverts commit 491b2810fb7fe5f080fa9c4f5945ed0a6909dc92. This change broke valid code and generated incorrect diagnostics, see https://reviews.llvm.org/D155064
2023-09-27[X86] Change target of __builtin_ia32_cmp[p|s][s|d] from avx into sse/sse2 ↵Freddy Ye1-0/+4
(#67410)
2023-09-27[clang][SemaCXX] Diagnose tautological uses of consteval if and ↵Takuya Shimizu1-14/+35
is_constant_evaluated This patch makes clang diagnose extensive cases of consteval if and is_constant_evaluated usage that are tautologically true or false. This introduces a new IsRuntimeEvaluated boolean flag to Sema::ExpressionEvaluationContextRecord that means the immediate appearance of if consteval or is_constant_evaluated are tautologically false(e.g. inside if !consteval {} block or non-constexpr-qualified function definition body) This patch also pushes new expression evaluation context when parsing the condition of if constexpr and initializer of constexpr variables so that Sema can be aware that the use of consteval if and is_consteval are tautologically true in if constexpr condition and constexpr variable initializers. BEFORE this patch, the warning for is_constant_evaluated was emitted from constant evaluator. This patch moves the warning logic to Sema in order to diagnose tautological use of is_constant_evaluated in the same way as consteval if. This patch separates initializer evaluation context from InitializerScopeRAII. This fixes a bug that was happening when user takes address of function address in initializers of non-local variables. Fixes https://github.com/llvm/llvm-project/issues/43760 Fixes https://github.com/llvm/llvm-project/issues/51567 Reviewed By: cor3ntin, ldionne Differential Revision: https://reviews.llvm.org/D155064
2023-09-25[clang][Sema] Make format size estimator aware of %p's existence in format ↵Takuya Shimizu1-5/+22
string (#65969) This change introduces `-Wformat-overflow` and `-Wformat-truncation` warning flags that were formerly diagnosed from `-Wfortify-source` warning group. This also introduces `-Wformat-overflow-non-kprintf` and `-Wformat-truncation-non-kprintf`, both of which will be used when the format string contains `%p` format string. The rationale for this is that Linux kernel has its own extension for `%p` format specifier, and we need some way to suppress false positives in kernel codebase. The approach of this patch aims NOT to affect non-kernel codebases. Note that GCC stops format size estimation upon `%p` format specifier. As requested in https://github.com/llvm/llvm-project/issues/64871
2023-09-20[Sema] Fix fixit cast printing inside macros (#66853)Shoaib Meenai1-1/+5
`Lexer::getLocForEndOfToken` is documented as returning an invalid source location when the end of the token is inside a macro expansion. We don't want that for this particular application, so just calculate the end location directly instead. Before this, format fix-its would omit the closing parenthesis (thus producing invalid code) for macros, e.g.: ``` $ cat format.cpp extern "C" int printf(const char *, ...); enum class Foo { Bar }; #define LOG(...) printf(__VA_ARGS__) void f(Foo foo) { LOG("%d\n", foo); } $ clang -fsyntax-only format.cpp format.cpp:4:29: warning: format specifies type 'int' but the argument has type 'Foo' [-Wformat] 4 | void f(Foo f) { LOG("%d\n", f); } | ~~ ^ | static_cast<int>( format.cpp:3:25: note: expanded from macro 'LOG' 3 | #define LOG(...) printf(__VA_ARGS__) | ^~~~~~~~~~~ 1 warning generated. ``` We now emit a valid fix-it: ``` $ clang -fsyntax-only format.cpp format.cpp:4:31: warning: format specifies type 'int' but the argument has type 'Foo' [-Wformat] 4 | void f(Foo foo) { LOG("%d\n", foo); } | ~~ ^~~ | static_cast<int>( ) format.cpp:3:25: note: expanded from macro 'LOG' 3 | #define LOG(...) printf(__VA_ARGS__) | ^~~~~~~~~~~ 1 warning generated. ``` Fixes https://github.com/llvm/llvm-project/issues/63462
2023-09-12[clang][Sema] Fix format size estimator's handling of %o, %x, %X with ↵Takuya Shimizu1-8/+21
alternative form The wrong handling of %x specifier with alternative form causes a false positive in linux kernel (https://github.com/ClangBuiltLinux/linux/issues/1923#issuecomment-1696075886) The kernel code: https://github.com/torvalds/linux/blob/651a00bc56403161351090a9d7ddbd7095975324/drivers/media/pci/cx18/cx18-mailbox.c#L99 This patch fixes this handling, and also adds some standard wordings as comments to clarify the reason. Reviewed By: nickdesaulniers Differential Revision: https://reviews.llvm.org/D159138
2023-09-11[Clang][RISCV] Use Decl for checkRVVTypeSupport (#65778)Yueh-Ting (eop) Chen1-1/+1
Using ValueDecl will cause error for OpenMP. Decl should do the work.
2023-09-02[clang] Support vectors in __builtin_isfpclassSerge Pavlov1-5/+25
Builtin function `__builtin_isfpclass` now can be called for a vector of floating-point values. In this case it is applied to the vector elementwise and produces vector of integer values. Differential Revision: https://reviews.llvm.org/D153339
2023-08-26[clang][Sema] Add truncation warning on fortified snprintfTakuya Shimizu1-31/+48
This patch warns on snprintf calls whose n argument is known to be smaller than the size of the formatted string like ``` char buf[5]; snprintf(buf, 5, "Hello"); ``` This is a counterpart of gcc's Wformat-truncation Fixes https://github.com/llvm/llvm-project/issues/64871 Reviewed By: aaron.ballman, nickdesaulniers Differential Revision: https://reviews.llvm.org/D158562
2023-08-23[RISCV] Add Zvfhmin extension for clangJianjian GUAN1-2/+3
This patch adds the Zvfhmin extension for clang. Reviewed By: craig.topper, michaelmaitland Differential Revision: https://reviews.llvm.org/D150253
2023-08-20[Sema] Modernize UsageInfo (NFC)Kazu Hirata1-2/+2