aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaChecking.cpp
AgeCommit message (Collapse)AuthorFilesLines
5 days[Clang][FIX] Fix type qualifiers on vector builtins (#160185)Joseph Huber1-16/+74
Summary: These were not stripping qualifiers when using them to infer the types, leading to errors when mixiing const and non-const.
6 days[clang][Sema] Accept gnu format attributes (#160255)Xing Guo1-11/+8
This patch teaches clang accepts gnu_printf, gnu_scanf, gnu_strftime and gnu_strfmon. These attributes are aliases for printf, scanf, strftime and strfmon. Ref: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html Fixes: #16219 --------- Co-authored-by: Sirraide <aeternalmail@gmail.com>
6 days[Clang] Change masked load / store builtin interface to take scalar pointer ↵Joseph Huber1-29/+13
(#156063) Summary: Right now these enformce alignment, which isn't convenient for the user on platforms that support unaligned accesses. The options are to either permit passing the alignment manually, or just assume it's unaligned unless the user specifies it. I've added https://github.com/llvm/llvm-project/pull/156057 which should make the requiested alignment show up on the intrinsic if the user passed `__builtin_assume_aligned`, however that's only with optimizations. This shouldn't cause issues unless the backend categorically decides to reject an unaligned access.
7 days[Clang] [Sema] Fix -Wdouble-promotion in C++ list-initialization (#159992)Marcel Jacobse1-1/+13
Resolves https://github.com/llvm/llvm-project/issues/33409. The information `IsListInit` is already passed to function `CheckImplicitConversion` for another use-case which makes adding a condition for the double-promotion case simple. Also adds tests, both for the changed list-initialization case as well as for normal explicit casts which already would have passed before this PR. These negative tests are added directly next to the positive tests in `warn-double-promotion.c` or for the C++-specific cases in a new .cpp version of that file.
8 days[os_log] Fix a CodeGen crash that occurs when arguments of struct, class, or ↵Akira Hatanaka1-5/+18
complex types are passed to _builtin_os_log_format (#158744) This change fixes the crash in clang's CodeGen by erroring out in Sema if those arguments are passed. rdar://139824423
8 days[Sema][AArch64] Emit error for mismatched VLs on streaming mode transitions ↵Mary Kassayova1-4/+24
(#159131) Update Sema::checkCall to handle the case where a call involves a streaming mode transition and passes or returns scalable vector types. Previously, Clang always issued a warning in this case, noting that the streaming and non-streaming vector lengths may differ at runtime. With this change: - if both `-msve-vector-bits` and `-msve-streaming-vector-bits` are specified and produce different fixed VL values, Clang now emits an error rather than a warning - If either flag is missing or vector lengths are equal, the diagnostic remains a warning
9 days[Clang] Add vector gather / scatter builtins to clang (#157895)Joseph Huber1-3/+104
Summary: This patch exposes `__builtin_masked_gather` and `__builtin_masked_scatter` to clang. These map to the underlying intrinsic relatively cleanly, needing only a level of indirection to take a vector of indices and a base pointer to a vector of pointers.
12 days[Clang] Rename elementwise builtins to `clzg` and `ctzg` (#157128)Joseph Huber1-2/+2
Summary: The added bit counting builtins for vectors used `cttz` and `ctlz`, which is consistent with the LLVM naming convention. However, these are clang builtins and implement exactly the `__builtin_ctzg` and `__builtin_clzg` behavior. It is confusing to people familiar with other other builtins that these are the only bit counting intrinsics named differently. This includes the additional operation for the undefined zero case, which was added as a `clzg` extension.
2025-09-17[clang][sema][NFC] Use a for-range loop in checkBuiltinVerboseTrap (#159114)Timm Baeder1-3/+1
We don't use `I` at all, so use a for-range loop.
2025-09-16[clang][ExprConst] Reject unary vector shuffles (#158589)Timm Baeder1-28/+27
This is not implemented at compile time and asserts in assertion builds, so reject it here. Fixed the coding style in `BuiltinShuffleVector` at the same time. Fixes #158471
2025-09-16[clang][sema][NFC] Clean up builtin arg checking functions (#158615)Timm Baeder1-16/+18
Always take an `unsigned` for the argument index, pull some locals in the closest scope and use `APInt::isPowerOf2()`.
2025-09-02[Clang] Permit half precision in `__builtin_complex` (#156479)Joseph Huber1-10/+0
Summary: This was forbidden previously, which made us divergent with the GCC implementation. Permit this by simply removing this Sema check. Fixes: https://github.com/llvm/llvm-project/issues/156463
2025-08-29[Clang] Add masked vector builtins for expand and compress access (#156042)Joseph Huber1-2/+8
Summary: The interface here is nearly indentical to the already added masked loads and stores. These bind to very similar intrinsics so we add them here.
2025-08-29[Clang] Update typechecking of builtin elementwise ternary math operators ↵Chaitanya Koparkar1-13/+52
(#155620) For scalars we directly compare their unqualified types. But even if we compare unqualified vector types, a difference in qualifiers in the element types can make the vector types be considered not equal. For example, vector of 4 'const float' values vs vector of 4 'float' values. So we compare unqualified types of their elements and number of elements. Fixes #155405
2025-08-28[clang] Fix crash when `__builtin_function_start` is given an invalid first ↵Vincent1-0/+3
parameter (#155506) Prevent a crash in `__builtin_function_start` by adding a check for an invalid first parameter. fixes #113323
2025-08-27[Clang] Update `__builtin_masked_load` to accept passthrough argument (#155652)Joseph Huber1-1/+10
Summary: It's important to be able to define the result of the masked-off lanes, add this as an optional argument to the builtin.
2025-08-27[clang] NFC: reintroduce clang/include/clang/AST/Type.h (#155050)Matheus Izvekov1-1/+1
This reintroduces `Type.h`, having earlier been renamed to `TypeBase.h`, as a redirection to `TypeBase.h`, and redirects most users to include the former instead. This is a preparatory patch for being able to provide inline definitions for `Type` methods which would otherwise cause a circular dependency with `Decl{,CXX}.h`. Doing these operations into their own NFC patch helps the git rename detection logic work, preserving the history. This patch makes clang just a little slower to build (~0.17%), just because it makes more code indirectly include `DeclCXX.h`.
2025-08-27[clang] NFC: rename clang/include/clang/AST/Type.h to TypeBase.h (#155049)Matheus Izvekov1-1/+1
This is a preparatory patch, to be able to provide inline definitions for `Type` functions which depend on `Decl{,CXX}.h`. As the latter also depends on `Type.h`, this would not be possible without some reorganizing. Splitting this rename into its own patch allows git to track this as a rename, and preserve all git history, and not force any code reformatting. A later NFC patch will reintroduce `Type.h` as redirection to `TypeBase.h`, rewriting most places back to directly including `Type.h` instead of `TypeBase.h`, leaving only a handful of places where this is necessary. Then yet a later patch will exploit this by making more stuff inline.
2025-08-27[clang] AST: fix getAs canonicalization of leaf types (#155028)Matheus Izvekov1-2/+2
2025-08-26[clang] NFC: introduce Type::getAsEnumDecl, and cast variants for all ↵Matheus Izvekov1-51/+25
TagDecls (#155463) And make use of those. These changes are split from prior PR #155028, in order to decrease the size of that PR and facilitate review.
2025-08-26[Clang] Support generic bit counting builtins on fixed boolean vectors (#154203)Joseph Huber1-2/+2
Summary: Boolean vectors as implemented in clang can be bit-casted to an integer that is rounded up to the next primitive sized integer. Users can do this themselves, but since the counting bits are very likely to be used with bitmasks like this and the generic forms are expected to be generic it seems reasonable that we handle this case directly.
2025-08-25[clang] NFC: change more places to use Type::getAsTagDecl and friends (#155313)Matheus Izvekov1-12/+5
This changes a bunch of places which use getAs<TagType>, including derived types, just to obtain the tag definition. This is preparation for #155028, offloading all the changes that PR used to introduce which don't depend on any new helpers.
2025-08-22[clang] Fix ignoring converted first arg of elementwise_fma (#154941)Timm Baeder1-0/+1
Fixes #154900
2025-08-21[Clang] Fix incorrect return type for `__builtin_shufflevector` (#154817)Joseph Huber1-2/+4
Summary: The `__builtin_shufflevector` call would return a GCC vector in all cases where the vector type was increased. Change this to preserve whether or not this was an extended vector. Fixes: https://github.com/llvm/llvm-project/issues/107981
2025-08-20[Clang] Add builtins for masked vector loads / stores (#154464)Joseph Huber1-0/+83
Summary: Clang has support for boolean vectors, these builtins expose the LLVM instruction of the same name. This differs from a manual load and select by potentially suppressing traps from deactivated lanes. Fixes: https://github.com/llvm/llvm-project/issues/107753
2025-08-20[clang] Introduce elementwise ctlz/cttz builtins (#131995)Fraser Cormack1-0/+13
These builtins are modeled on the clzg/ctzg builtins, which accept an optional second argument. This second argument is returned if the first argument is 0. These builtins unconditionally exhibit zero-is-undef behaviour, regardless of target preference for the other ctz/clz builtins. The builtins have constexpr support. Fixes #154113
2025-08-14[Sema] Fix false positive warnings for misaligned member access (#150025)Vladimir Vuksanovic1-7/+9
These warnings are reported on a per expression basis, however some potential misaligned accesses are discarded before that happens. The problem is when a new expression starts while processing another expression. The new expression will end first and emit all potential misaligned accesses collected up to that point. That includes candidates that were found in the parent expression, even though they might have gotten discarded later. Fixed by checking if the candidate is located withing the currently processed expression. Fixes #144729
2025-08-13Fix Clang bug that -Wformat-signedness is not reported properly. (#150962)DeanSturtevant11-18/+23
The goal is to correctly identify diagnostics that are emitted by virtue of -Wformat-signedness. Before this change, diagnostic messages triggered by -Wformat-signedness might look like: format specifies type 'unsigned int' but the argument has type 'int' [-Wformat] signedness of format specifier 'u' is incompatible with 'c' [-Wformat] With this change: format specifies type 'unsigned int' but the argument has type 'int', which differs in signedness [-Wformat-signedness] signedness of format specifier 'u' is incompatible with 'c' [-Wformat-signedness] Fix: - handleFormatSignedness can now return NoMatchSignedness. Callers handle this. - warn_format_conversion_argument_type extends the message it used to emit by a string that mentions "signedness". - warn_format_cmp_specifier_sign_mismatch is now correctly categorized as a diagnostic controlled by -Wformat-signedness.
2025-08-12[clang] Add elementwise fshl/fshr builtins (#153113)Chaitanya Koparkar1-0/+6
This patch implements `__builtin_elementwise_fshl` and `__builtin_elementwise_fshr` builtins. These map to the fshl/fshr intrinsics described here: - https://llvm.org/docs/LangRef.html#llvm-fshl-intrinsic - https://llvm.org/docs/LangRef.html#llvm-fshr-intrinsic Fixes https://github.com/llvm/llvm-project/issues/152555.
2025-08-09[clang] Improve nested name specifier AST representation (#147835)Matheus Izvekov1-35/+62
This is a major change on how we represent nested name qualifications in the AST. * The nested name specifier itself and how it's stored is changed. The prefixes for types are handled within the type hierarchy, which makes canonicalization for them super cheap, no memory allocation required. Also translating a type into nested name specifier form becomes a no-op. An identifier is stored as a DependentNameType. The nested name specifier gains a lightweight handle class, to be used instead of passing around pointers, which is similar to what is implemented for TemplateName. There is still one free bit available, and this handle can be used within a PointerUnion and PointerIntPair, which should keep bit-packing aficionados happy. * The ElaboratedType node is removed, all type nodes in which it could previously apply to can now store the elaborated keyword and name qualifier, tail allocating when present. * TagTypes can now point to the exact declaration found when producing these, as opposed to the previous situation of there only existing one TagType per entity. This increases the amount of type sugar retained, and can have several applications, for example in tracking module ownership, and other tools which care about source file origins, such as IWYU. These TagTypes are lazily allocated, in order to limit the increase in AST size. This patch offers a great performance benefit. It greatly improves compilation time for [stdexec](https://github.com/NVIDIA/stdexec). For one datapoint, for `test_on2.cpp` in that project, which is the slowest compiling test, this patch improves `-c` compilation time by about 7.2%, with the `-fsyntax-only` improvement being at ~12%. This has great results on compile-time-tracker as well: ![image](https://github.com/user-attachments/assets/700dce98-2cab-4aa8-97d1-b038c0bee831) This patch also further enables other optimziations in the future, and will reduce the performance impact of template specialization resugaring when that lands. It has some other miscelaneous drive-by fixes. About the review: Yes the patch is huge, sorry about that. Part of the reason is that I started by the nested name specifier part, before the ElaboratedType part, but that had a huge performance downside, as ElaboratedType is a big performance hog. I didn't have the steam to go back and change the patch after the fact. There is also a lot of internal API changes, and it made sense to remove ElaboratedType in one go, versus removing it from one type at a time, as that would present much more churn to the users. Also, the nested name specifier having a different API avoids missing changes related to how prefixes work now, which could make existing code compile but not work. How to review: The important changes are all in `clang/include/clang/AST` and `clang/lib/AST`, with also important changes in `clang/lib/Sema/TreeTransform.h`. The rest and bulk of the changes are mostly consequences of the changes in API. PS: TagType::getDecl is renamed to `getOriginalDecl` in this patch, just for easier to rebasing. I plan to rename it back after this lands. Fixes #136624 Fixes https://github.com/llvm/llvm-project/issues/43179 Fixes https://github.com/llvm/llvm-project/issues/68670 Fixes https://github.com/llvm/llvm-project/issues/92757
2025-08-04[Clang] Initial support for P2841 (Variable template and concept template ↵Corentin Jabot1-1/+2
parameters) (#150823) This is a first pass at implementing [P2841R7](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2841r7.pdf). The implementation is far from complete; however, I'm aiming to do that in chunks, to make our lives easier. In particular, this does not implement - Subsumption - Mangling - Satisfaction checking is minimal as we should focus on #141776 first (note that I'm currently very stuck) FTM, release notes, status page, etc, will be updated once the feature is more mature. Given the state of the feature, it is not yet allowed in older language modes. Of note: - Mismatches between template template arguments and template template parameters are a bit wonky. This is addressed by #130603 - We use `UnresolvedLookupExpr` to model template-id. While this is pre-existing, I have been wondering if we want to introduce a different OverloadExpr subclass for that. I did not make the change in this patch.
2025-07-31[clang][sema] Remove unused local SourceLocation (#151455)Timm Baeder1-3/+1
getIntegerConstantExpr() doesn't force us to pass one, so don't.
2025-07-23[Clang] Add elementwise maximumnum/minimumnum builtin functions (#149775)Wenju He1-0/+2
Addresses https://github.com/llvm/llvm-project/issues/112164. minimumnum and maximumnum intrinsics were added in 5bf81e53dbea. The new built-ins can be used for implementing OpenCL math function fmax and fmin in #128506.
2025-07-19Reland [Clang] Make the SizeType, SignedSizeType and PtrdiffType be named ↵YexuanXiao1-1/+3
sugar types (#149613) The checks for the 'z' and 't' format specifiers added in the original PR #143653 had some issues and were overly strict, causing some build failures and were consequently reverted at https://github.com/llvm/llvm-project/commit/4c85bf2fe8042c855c9dd5be4b02191e9d071ffd. In the latest commit https://github.com/llvm/llvm-project/pull/149613/commits/27c58629ec76a703fde9c0b99b170573170b4a7a, I relaxed the checks for the 'z' and 't' format specifiers, so warnings are now only issued when they are used with mismatched types. The original intent of these checks was to diagnose code that assumes the underlying type of `size_t` is `unsigned` or `unsigned long`, for example: ```c printf("%zu", 1ul); // Not portable, but not an error when size_t is unsigned long ``` However, it produced a significant number of false positives. This was partly because Clang does not treat the `typedef` `size_t` and `__size_t` as having a common "sugar" type, and partly because a large amount of existing code either assumes `unsigned` (or `unsigned long`) is `size_t`, or they define the equivalent of size_t in their own way (such as sanitizer_internal_defs.h).https://github.com/llvm/llvm-project/blob/2e67dcfdcd023df2f06e0823eeea23990ce41534/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h#L203
2025-07-17Revert "[Clang] Make the SizeType, SignedSizeType and PtrdiffType be named ↵Kazu Hirata1-3/+1
sugar types instead of built-in types (#143653)" This reverts commit c27e283cfbca2bd22f34592430e98ee76ed60ad8. A builbot failure has been reported: https://lab.llvm.org/buildbot/#/builders/186/builds/10819/steps/10/logs/stdio I'm also getting a large number of warnings related to %zu and %zx.
2025-07-17[Clang] Make the SizeType, SignedSizeType and PtrdiffType be named sugar ↵YexuanXiao1-1/+3
types instead of built-in types (#143653) Including the results of `sizeof`, `sizeof...`, `__datasizeof`, `__alignof`, `_Alignof`, `alignof`, `_Countof`, `size_t` literals, and signed `size_t` literals, the results of pointer-pointer subtraction and checks for standard library functions (and their calls). The goal is to enable clang and downstream tools such as clangd and clang-tidy to provide more portable hints and diagnostics. The previous discussion can be found at #136542. This PR implements this feature by introducing a new subtype of `Type` called `PredefinedSugarType`, which was considered appropriate in discussions. I tried to keep `PredefinedSugarType` simple enough yet not limited to `size_t` and `ptrdiff_t` so that it can be used for other purposes. `PredefinedSugarType` wraps a canonical `Type` and provides a name, conceptually similar to a compiler internal `TypedefType` but without depending on a `TypedefDecl` or a source file. Additionally, checks for the `z` and `t` format specifiers in format strings for `scanf` and `printf` were added. It will precisely match expressions using `typedef`s or built-in expressions. The affected tests indicates that it works very well. Several code require that `SizeType` is canonical, so I kept `SizeType` to its canonical form. The failed tests in CI are allowed to fail. See the [comment](https://github.com/llvm/llvm-project/pull/135386#issuecomment-3049426611) in another PR #135386.
2025-06-30[Clang] Fix '-Wformat-overflow' FP when floats had field-width and plus ↵Baranov Victor1-1/+4
prefix (#144274) If field width is specified, the sign/space is already accounted for within the field width, so no additional size is needed. Fixes https://github.com/llvm/llvm-project/issues/143951. --------- Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2025-06-29[Clang] Add __builtin_invoke and use it in libc++ (#116709)Nikolas Klauser1-0/+95
`std::invoke` is currently quite heavy compared to a function call, since it involves quite heavy SFINAE. This can be done significantly more efficient by the compiler, since most calls to `std::invoke` are simple function calls and 6 out of the seven overloads for `std::invoke` exist only to support member pointers. Even these boil down to a few relatively simple checks. Some real-world testing with this patch revealed some significant results. For example, instantiating `std::format("Banane")` (and its callees) went down from ~125ms on my system to ~104ms.
2025-06-26[Clang][AArch64] _interlockedbittestand{set,reset}64_{acq,rel,nf} support ↵Adam Glass1-0/+11
for AArch64 (#145980) Adds _interlockedbittestand{set,reset}64_{acq,rel,nf} support for AArch64
2025-06-26Cap IntRange::Width to MaxWidth (#145356)Akira Hatanaka1-5/+6
This commit addresses a fallout introduced by #126846. Previously, TryGetExprRange would return an IntRange that has an active range exceeding the maximum representable range for the expression's underlying type. This led to clang erroneously issuing warnings about implicit conversions losing integer precision. This commit fixes the bug by capping IntRange::Width to MaxWidth. rdar://149444029
2025-06-26[Sema] Avoid deep recursion in AnalyzeImplicitConversions (#145734)Ilya Biryukov1-11/+13
The function already exposes a work list to avoid deep recursion, this commit starts utilizing it in a helper that could also lead to a deep recursion. We have observed this crash on `clang/test/C/C99/n590.c` with our internal builds that enable aggressive optimizations and hit the limit earlier than default release builds of Clang. See the added test for an example with a deeper recursion that used to crash in upstream Clang before this change with the following stack trace: ``` #0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/local/google/home/ibiryukov/code/llvm-project/llvm/lib/Support/Unix/Signals.inc:804:13 #1 llvm::sys::RunSignalHandlers() /usr/local/google/home/ibiryukov/code/llvm-project/llvm/lib/Support/Signals.cpp:106:18 #2 SignalHandler(int, siginfo_t*, void*) /usr/local/google/home/ibiryukov/code/llvm-project/llvm/lib/Support/Unix/Signals.inc:0:3 #3 (/lib/x86_64-linux-gnu/libc.so.6+0x3fdf0) #4 AnalyzeImplicitConversions(clang::Sema&, clang::Expr*, clang::SourceLocation, bool) /usr/local/google/home/ibiryukov/code/llvm-project/clang/lib/Sema/SemaChecking.cpp:12772:0 #5 CheckCommaOperand /usr/local/google/home/ibiryukov/code/llvm-project/clang/lib/Sema/SemaChecking.cpp:0:3 #6 AnalyzeImplicitConversions /usr/local/google/home/ibiryukov/code/llvm-project/clang/lib/Sema/SemaChecking.cpp:12644:7 #7 AnalyzeImplicitConversions(clang::Sema&, clang::Expr*, clang::SourceLocation, bool) /usr/local/google/home/ibiryukov/code/llvm-project/clang/lib/Sema/SemaChecking.cpp:12776:5 #8 CheckCommaOperand /usr/local/google/home/ibiryukov/code/llvm-project/clang/lib/Sema/SemaChecking.cpp:0:3 #9 AnalyzeImplicitConversions /usr/local/google/home/ibiryukov/code/llvm-project/clang/lib/Sema/SemaChecking.cpp:12644:7 #10 AnalyzeImplicitConversions(clang::Sema&, clang::Expr*, clang::SourceLocation, bool) /usr/local/google/home/ibiryukov/code/llvm-project/clang/lib/Sema/SemaChecking.cpp:12776:5 #11 CheckCommaOperand /usr/local/google/home/ibiryukov/code/llvm-project/clang/lib/Sema/SemaChecking.cpp:0:3 #12 AnalyzeImplicitConversions /usr/local/google/home/ibiryukov/code/llvm-project/clang/lib/Sema/SemaChecking.cpp:12644:7 #13 AnalyzeImplicitConversions(clang::Sema&, clang::Expr*, clang::SourceLocation, bool) /usr/local/google/home/ibiryukov/code/llvm-project/clang/lib/Sema/SemaChecking.cpp:12776:5 #14 CheckCommaOperand /usr/local/google/home/ibiryukov/code/llvm-project/clang/lib/Sema/SemaChecking.cpp:0:3 #15 AnalyzeImplicitConversions /usr/local/google/home/ibiryukov/code/llvm-project/clang/lib/Sema/SemaChecking.cpp:12644:7 #16 AnalyzeImplicitConversions(clang::Sema&, clang::Expr*, clang::SourceLocation, bool) /usr/local/google/home/ibiryukov/code/llvm-project/clang/lib/Sema/SemaChecking.cpp:12776:5 #17 CheckCommaOperand /usr/local/google/home/ibiryukov/code/llvm-project/clang/lib/Sema/SemaChecking.cpp:0:3 #18 AnalyzeImplicitConversions /usr/local/google/home/ibiryukov/code/llvm-project/clang/lib/Sema/SemaChecking.cpp:12644:7 #19 AnalyzeImplicitConversions(clang::Sema&, clang::Expr*, clang::SourceLocation, bool) /usr/local/google/home/ibiryukov/code/llvm-project/clang/lib/Sema/SemaChecking.cpp:12776:5 ... 700+ more stack frames. ```
2025-06-24[NFC] Move areCompatibleSveTypes etc. from ASTContext to SemaARM. (#145429)Eli Friedman1-8/+8
In preparation for making these functions interact with the current context; see #144611.
2025-06-13Remove delayed typo expressions (#143423)Aaron Ballman1-2/+0
This removes the delayed typo correction functionality from Clang (regular typo correction still remains) due to fragility of the solution. An RFC was posted here: https://discourse.llvm.org/t/rfc-removing-support-for-delayed-typo-correction/86631 and while that RFC was asking for folks to consider stepping up to be maintainers, and we did have a few new contributors show some interest, experiments show that it's likely worth it to remove this functionality entirely and focus efforts on improving regular typo correction. This removal fixes ~20 open issues (quite possibly more), improves compile time performance by roughly .3-.4% (https://llvm-compile-time-tracker.com/?config=Overview&stat=instructions%3Au&remote=AaronBallman&sortBy=date), and does not appear to regress diagnostic behavior in a way we wouldn't find acceptable. Fixes #142457 Fixes #139913 Fixes #138850 Fixes #137867 Fixes #137860 Fixes #107840 Fixes #93308 Fixes #69470 Fixes #59391 Fixes #58172 Fixes #46215 Fixes #45915 Fixes #45891 Fixes #44490 Fixes #36703 Fixes #32903 Fixes #23312 Fixes #69874
2025-06-04[clang] Function type attribute to prevent CFI instrumentation (#135836)PiJoules1-0/+45
This introduces the attribute discussed in https://discourse.llvm.org/t/rfc-function-type-attribute-to-prevent-cfi-instrumentation/85458. The proposed name has been changed from `no_cfi` to `cfi_unchecked_callee` to help differentiate from `no_sanitize("cfi")` more easily. The proposed attribute has the following semantics: 1. Indirect calls to a function type with this attribute will not be instrumented with CFI. That is, the indirect call will not be checked. Note that this only changes the behavior for indirect calls on pointers to function types having this attribute. It does not prevent all indirect function calls for a given type from being checked. 2. All direct references to a function whose type has this attribute will always reference the true function definition rather than an entry in the CFI jump table. 3. When a pointer to a function with this attribute is implicitly cast to a pointer to a function without this attribute, the compiler will give a warning saying this attribute is discarded. This warning can be silenced with an explicit C-style cast or C++ static_cast.
2025-06-04[clang][PAC] Add __builtin_get_vtable_pointer (#139790)Oliver Hunt1-0/+38
With pointer authentication it becomes non-trivial to correctly load the vtable pointer of a polymorphic object. __builtin_get_vtable_pointer is a function that performs the load and performs the appropriate authentication operations if necessary.
2025-06-03[Clang][Sema] Add fortify warnings for stpcpy (#141646)Sharjeel Khan1-0/+3
As mentioned in https://github.com/llvm/llvm-project/issues/142230, I am adding fortify warnings for functions missing in Clang and I am starting with stpcpy.
2025-06-02[Clang] Separate implicit int conversion on negation sign to new diagnostic ↵Yutong Zhu1-0/+6
group (#139429) This PR reverts a change made in #126846. #126846 introduced an ``-Wimplicit-int-conversion`` diagnosis for ```c++ int8_t x = something; x = -x; // warning here ``` This is technically correct since -x could have a width of 9, but this pattern is common in codebases. Reverting this change would also introduce the false positive I fixed in #126846: ```c++ bool b(signed char c) { return -c >= 128; // -c can be 128 } ``` This false positive is uncommon, so I think it makes sense to revert the change.
2025-05-31Work around a build issue with MSVC; NFC (#142195)Aaron Ballman1-3/+3
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-05-30[Sema] Fix type mismatch error when arguments to elementwise math builtin ↵Acthink Yang1-1/+1
have different qualifiers, which should be well-formed (#141485) Fixes #141397 Element-wise math builtins (e.g. __builtin_elementwise_max/__builtin_elementwise_pow etc.) fail when their arguments have different qualifications, but should be well-formed. The fix is ​​to use hasSameUnqualifiedType to check if the arguments match.
2025-05-29[clang][SPIRV] Add builtin for OpGenericCastToPtrExplicit and its SPIR-V ↵Victor Lomuller1-1/+5
friendly binding (#137805) The patch introduce __builtin_spirv_generic_cast_to_ptr_explicit which is lowered to the llvm.spv.generic.cast.to.ptr.explicit intrinsic. The SPIR-V builtins are now split into 3 differents file: BuiltinsSPIRVCore.td, BuiltinsSPIRVVK.td for Vulkan specific builtins, BuiltinsSPIRVCL.td for OpenCL specific builtins and BuiltinsSPIRVCommon.td for common ones. The patch also introduces a new header defining its SPIR-V friendly equivalent (__spirv_GenericCastToPtrExplicit_ToGlobal, __spirv_GenericCastToPtrExplicit_ToLocal and __spirv_GenericCastToPtrExplicit_ToPrivate). The functions are declared as aliases to the new builtin allowing C-like languages to have a definition to rely on as well as gaining proper front-end diagnostics. The motivation for the header is to provide a stable binding for applications or library (such as SYCL) and allows non SPIR-V targets to provide an implementation (via libclc or similar to how it is done for gpuintrin.h).