aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaDecl.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-06-18[HLSL][SPIRV] Add vk::constant_id attribute. (#143544)Steven Perron1-0/+13
The vk::constant_id attribute is used to indicate that a global const variable represents a specialization constant in SPIR-V. This PR adds this attribute to clang. The documentation for the attribute is [here](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/SPIR-V.rst#specialization-constants). The strategy is to to modify the initializer to get the value of a specialize constant for a builtin defined in the SPIR-V backend. Implements https://github.com/llvm/wg-hlsl/pull/287 Fixes https://github.com/llvm/llvm-project/issues/142448 --------- Co-authored-by: Nathan Gauër <github@keenuts.net>
2025-06-17[clang] Remove separate evaluation step for static class member init. (#142713)Eli Friedman1-21/+18
We already evaluate the initializers for all global variables, as required by the standard. Leverage that evaluation instead of trying to separately validate static class members. This has a few benefits: - Improved diagnostics; we now get notes explaining what failed to evaluate. - Improved correctness: is_constant_evaluated is handled correctly. The behavior follows the proposed resolution for CWG1721. Fixes #88462. Fixes #99680.
2025-06-17[NFC][HLSL] Move Sema work from `ParseMicrosoftRootSignatureAttributeArgs` ↵Finn Plummer1-0/+1
(#143184) This separates semantic analysis from parsing by moving `RootSignatureDecl` creation, scope storage, and lookup logic into `SemaHLSL`. For more context see: https://github.com/llvm/llvm-project/issues/142834. - Define `ActOnStartRootSignatureDecl` and `ActOnFinishRootSignatureDecl` on `SemaHLSL` - NFC so no test changes. Resolves: https://github.com/llvm/llvm-project/issues/142834 --------- Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2025-06-13Enable unique-object-duplication warning for windows (#143537)Devon Loehr1-7/+24
Followup to #125526. This expands the logic of the unique-object-duplication warning so that it also works for windows code. For the most part, the logic is unchanged, merely substituting "has no import/export annotation" in place of "has hidden visibility". However, there are some small inconsistencies between the two; namely, visibility is propagated through nested classes, while import/export annotations aren't. This PR: 1. Updates the logic for the warning to account for the differences between posix and windows 2. Changes the warning message and documentation appropriately 3. Updates the tests to cover windows, and adds new test cases for the places where behavior differs. This PR was tested by building chromium (cross compiling linux->windows) with the changes in place. After accounting for the differences in semantics, no new warnings were discovered.
2025-06-13Remove delayed typo expressions (#143423)Aaron Ballman1-36/+3
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-08[Clang] Support constexpr asm at global scope. (#143268)Corentin Jabot1-6/+3
I previously failed to realize this feature existed... Fixes #137459 Fixes #143242
2025-06-05[clang] Simplify device kernel attributes (#137882)Nick Sarnie1-8/+6
We have multiple different attributes in clang representing device kernels for specific targets/languages. Refactor them into one attribute with different spellings to make it more easily scalable for new languages/targets. --------- Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-06-04[HLSL][SPIR-V] Implement vk::ext_builtin_input attribute (#138530)Nathan Gauër1-0/+6
This variable attribute is used in HLSL to add Vulkan specific builtins in a shader. The attribute is documented here: https://github.com/microsoft/hlsl-specs/blob/17727e88fd1cb09013cb3a144110826af05f4dd5/proposals/0011-inline-spirv.md Those variable, even if marked as `static` are externally initialized by the pipeline/driver/GPU. This is handled by moving them to a specific address space `hlsl_input`, also added by this commit. The design for input variables in Clang can be found here: https://github.com/llvm/wg-hlsl/blob/355771361ef69259fef39a65caef8bff9cb4046d/proposals/0019-spirv-input-builtin.md Co-authored-by: Justin Bogner <mail@justinbogner.com>
2025-05-28[Clang] Fix a regression introduced by #138518 (#141342)cor3ntin1-8/+12
We did not handle the case where a variable could be initialized by a CXXParenListInitExpr. --------- Co-authored-by: Shafik Yaghmour <shafik.yaghmour@intel.com>
2025-05-25[Sema] Remove unused includes (NFC) (#141419)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-05-23[OpenCL] No need to check array of struct for kernel arguments (#138894)Jiefeng Wang1-10/+6
Since arrays decay into pointers, no need to check them for arguments. This commit reverts part of the changes from the commit "[OpenCL] Check for invalid kernel arguments in array types" 3b238ed6626983beb238b95eada4172184fb2d29.
2025-05-22[C] Fix crash-on-invalid due to infinite recursion (#140925)Aaron Ballman1-1/+2
There are two related issues being fixed in this patch. Both issues relate to use of an invalid structure which contains a member that we error recover such that the field has the same type as the structure. In both cases, we would hit an infinite loop while analyzing the fields because the type of the field matches the type of the record. Fixes #140887
2025-05-20[Clang] Functions called in discarded statements should not be instantiated ↵cor3ntin1-18/+2
(#140576) Functions referenced in discarded statements could be treated as odr-used because we did not properly set the correct evaluation context in some places. Fixes https://github.com/llvm/llvm-project/issues/140449
2025-05-19[C++] Fix a crash with __thread and dependent types (#140542)Aaron Ballman1-0/+4
We were checking whether the initializer is a valid constant expression even if the variable was dependent. Now we delay that checking until after the template has been instantiated. Fixes #140509
2025-05-19[clang] Use *Map::try_emplace (NFC) (#140477)Kazu Hirata1-1/+1
We can simplify the code with *Map::try_emplace where we need default-constructed values while avoding calling constructors when keys are already present.
2025-05-16[clang] Add new warning: not eliding copy on return (missed NRVO) (#139973)Grigory Pastukhov1-1/+4
2025-05-13Add an off-by-default warning to complain about MSVC bitfield padding (#117428)Oliver Hunt1-2/+25
This just adds a warning for bitfields placed next to other bitfields where the underlying type has different storage. Under the MS struct bitfield packing ABI such bitfields are not packed.
2025-05-13[C] Fix a false-positive with tentative defn compat (#139738)Aaron Ballman1-2/+10
C++ has a carve-out that makes a declaration with 'extern' explicitly specified and no initializer be a declaration rather than a definition. We now account for that to silence a diagnostic with: ``` extern const int i; const int i = 12; ``` which is valid C++. Addresses an issue that was brought up via post-commit review.
2025-05-08[Clang] Fix the warning group of several compatibilty diagnostics (#138872)Sirraide1-6/+5
There are a few diagnostics that are incorrectly grouped under `-Wc++20-compat` instead of `-Wpre-c++20-compat`. I grepped for any remaining `-Wc++xy-compat` diagnostics, but they all seem to actually be about compatibility with C++XY. Fixes #138775.
2025-05-06[Clang] Implement the core language parts of P2786 - Trivial relocation ↵cor3ntin1-5/+12
(#127636) This adds - The parsing of `trivially_relocatable_if_eligible`, `replaceable_if_eligible` keywords - `__builtin_trivially_relocate`, implemented in terms of memmove. In the future this should - Add the appropriate start/end lifetime markers that llvm does not have (`start_lifetime_as`) - Add support for ptrauth when that's upstreamed - the `__builtin_is_cpp_trivially_relocatable` and `__builtin_is_replaceable` traits Fixes #127609
2025-05-05[randstruct] Also randomize composite function pointer structs (#138385)Kees Cook1-31/+40
Check for struct members that are structs filled only with function pointers by recursively examining it. Since the lamba IsFunctionPointerOrForwardDecl cannot call itself directly, move it into a helper function, EntirelyFunctionPointers, so it can be called from the lambda. Add test for composite function pointer structs getting automatically randomized. Add more tests for validating automatic randomization vs explicitly annotated with "randomize_layout", and excluded with "no_randomize_layout". Reorder the "should we randomize?" "if" statement to check for enablement before checking for Record details. Fixes #138355
2025-05-05[C23] Disable diagnostic on struct defn in prototype (#138516)Aaron Ballman1-2/+8
Thanks to changes to type compatibility rules via WG14 N3007, these functions can now be called with a compatible type even within the same TU, which makes the -Wvisibility diagnostic too chatty to have on by default. So in C23 mode, -Wvisibility will only diagnose an incomplete tag type declared in a function prototype. If the tag is defined in the prototype, the diagnostic is silenced.
2025-05-02[Clang] Implement CWG3005 Function parameters should never be ↵cor3ntin1-3/+7
name-independent (#138245) We already attempted to implement this (it was the intent of the paper), in that parameters were never considered name-independent. However, we failed to check that any previously found parameter declaration was also name-independent. Note that, as worded, the current resolution is insufficient (I wrote to CWG with better wording), but there is some consensus on the design outcome. Fixes #136373
2025-05-02[C] Update the -Wdefault-const-init-unsafe wording (#138266)Aaron Ballman1-1/+6
This drops the "and is incompatible with C++" phrasing from the diagnostic unless -Wc++-compat is explicitly passed. This makes the diagnostic less confusing when it is on by default rather than enabled because of C++ compatibility concerns
2025-05-02[C23] Implement WG14 N3037 (#132939)Aaron Ballman1-3/+7
This changes the type compatibility rules so that it is permitted to redefine tag types within the same TU so long as they are equivalent definitions. It is intentionally not being exposed as an extension in older C language modes. GCC does not do so and the feature doesn't seem compelling enough to warrant it.
2025-05-02[C] Add -Wjump-bypasses-init (#138009)Aaron Ballman1-3/+5
We already diagnose when a jump bypasses initialization in C++ because such code is ill-formed there. However, we were not using this to diagnose those same jumps in C. -Wjump-bypasses-init is grouped under -Wc++-compat and diagnoses this situation as a compatibility issue with C++. This diagnostic is off by default. The diagnostic could perhaps be enabled by default for C, but due to the design of jump diagnostic handling, it not a trivial task. For now, we'll add the diagnostic as off-by-default so we get incremental improvement, but a follow-up could try to refactor jump diagnostics so we can enable this by default in C and have it as a C++ compatibility diagnostic as well.
2025-05-02[C] Diagnose use of C++ keywords in C (#137234)Aaron Ballman1-0/+11
This adds a new diagnostic group, -Wc++-keyword, which is off by default and grouped under -Wc++-compat. The diagnostic catches use of C++ keywords in C code. This change additionally fixes an issue with -Wreserved-identifier not diagnosing use of reserved identifiers in function parameter lists in a function declaration which is not a definition. Fixes https://github.com/llvm/llvm-project/issues/21898
2025-05-02[clang][NFC] Convert `Sema::CCEKind` to scoped enumVlad Serebrennikov1-3/+2
2025-05-02[clang][NFC] Convert `Sema::OverloadKind` to scoped enumVlad Serebrennikov1-3/+3
2025-05-02[clang][NFC] Convert `Sema::CorrectTypoKind` to scoped enumVlad Serebrennikov1-6/+8
2025-05-02[clang][NFC] Convert `Sema::AllowFoldKind` to scoped enumVlad Serebrennikov1-4/+5
2025-05-02[clang][NFC] Convert `Sema::AvailabilityMergeKind` to scoped enumVlad Serebrennikov1-14/+16
2025-05-02[clang][NFC] Convert `Sema::OffsetOfKind` to scoped enumVlad Serebrennikov1-2/+2
2025-05-02[clang][NFC] Convert `Sema::NonTagKind` to scoped enumVlad Serebrennikov1-10/+10
2025-05-02[clang][NFC] Convert `Sema::NonTrivialCUnionContext` to scoped enumVlad Serebrennikov1-18/+21
2025-05-01[clang] Add scoped enum support to `StreamingDiagnostic` (#138089)Vlad Serebrennikov1-15/+12
This patch adds templated `operator<<` for diagnostics that pass scoped enums, saving people from `llvm::to_underlying()` clutter on the side of emitting the diagnostic. This eliminates 80 out of 220 usages of `llvm::to_underlying()` in Clang. I also backported `std::is_scoped_enum_v` from C++23.
2025-05-01[C] Add -Wtentative-definition-compat (#137967)Aaron Ballman1-0/+3
This adds a new diagnostic to warn about redeclaration of a tentative definition in C. This is incompatible with C++, so the new diagnostic group is under -Wc++-compat.
2025-05-01[C] Modify -Wdefault-const-init (#137961)Aaron Ballman1-1/+1
Post-commit review feedback on https://github.com/llvm/llvm-project/pull/137166 raised a concern from the Linux kernel about wanting to silence the new diagnostic when the uninitialized object is a const member of a structure. These members can be initialized later if the containing object is non-const, such as through a call to memset, for example. This splits the diagnostic groups into: ``` -Wc++-compat -Wdefault-const-init -Wdefault-const-init-field -Wdefault-const-init-var -Wdefault-const-init-unsafe -Wdefault-const-init-field-unsafe -Wdefault-const-init-var-unsafe ``` --------- Co-authored-by: Mariya Podchishchaeva <mariya.podchishchaeva@intel.com>
2025-05-01[clang][NFC] Convert `Sema::BuiltinCountedByRefKind` to scoped enumVlad Serebrennikov1-1/+2
2025-04-29[HLSL] Resource initialization by constructors (#135120)Helena Kotas1-4/+2
- Adds resource constructor that takes explicit binding for all resource classes. - Updates implementation of default resource constructor to initialize resource handle to `poison`. - Removes initialization of resource classes from Codegen. - Initialization of `cbuffer` still needs to happen in `CGHLSLRuntime` because it does not have a corresponding resource class type. - Adds `ImplicitCastExpr` for builtin function calls. Sema adds these automatically when a method of a template class is instantiated, but some resource classes like `ByteAddressBuffer` are not templates so they need to have this added explicitly. Design proposal: llvm/wg-hlsl#197 Closes #134154
2025-04-29[C] Diagnose declarations hidden in C++ (#137368)Aaron Ballman1-0/+33
This introduces a new diagnostic, -Wc++-hidden-decl, which is grouped under -Wc++-compat, that diagnoses declarations which are valid in C but invalid in C++ due to the type being at the wrong scope. e.g., ``` struct S { struct T { int x; } t; }; struct T t; // Valid C, invalid C++ ``` This is implementing the other half of #21898
2025-04-28[HLSL] Treat classes and structs as packed by default (#137391)Justin Bogner1-0/+4
Fixes #121010.
2025-04-28[clang][NFC] Convert LookupResultKind to scoped enumVlad Serebrennikov1-29/+29
2025-04-28[clang][NFC] Convert `LookupResult::AmbiguityKind` to scoped enumVlad Serebrennikov1-1/+1
2025-04-25[C] Warn on uninitialized const objects (#137166)Aaron Ballman1-0/+10
Unlike C++, C allows the definition of an uninitialized `const` object. If the object has static or thread storage duration, it is still zero-initialized, otherwise, the object is left uninitialized. In either case, the code is not compatible with C++. This adds a new diagnostic group, `-Wdefault-const-init-unsafe`, which is on by default and diagnoses any definition of a `const` object which remains uninitialized. It also adds another new diagnostic group, `-Wdefault-const-init` (which also enabled the `unsafe` variant) that diagnoses any definition of a `const` object (including ones which are zero-initialized). This diagnostic is off by default. Finally, it adds `-Wdefault-const-init` to `-Wc++-compat`. GCC diagnoses these situations under this flag. Fixes #19297
2025-04-24[clang] Ensure correct copying of records with authenticated fields (#136783)Oliver Hunt1-0/+6
When records contain fields with pointer authentication, even simple copies can require additional work be performed. This patch contains the core functionality required to handle user defined structs, as well as the implicitly constructed structs for blocks, etc. Co-authored-by: Ahmed Bougacha Co-authored-by: Akira Hatanaka Co-authored-by: John Mccall
2025-04-23Control analysis-based diagnostics with #pragma (#136323)Aaron Ballman1-1/+7
Previously, analysis-based diagnostics (like -Wconsumed) had to be enabled at file scope in order to be run at the end of each function body. This meant that they did not respect #pragma clang diagnostic enabling or disabling the diagnostic. Now, these pragmas can control the diagnostic emission. Fixes #42199
2025-04-16[clang] Fix elaborated keyword canonicalization (#135916)Matheus Izvekov1-3/+3
2025-04-16[Clang] [Sema] Fix a crash when a `friend` function is redefined as deleted ↵Sirraide1-10/+5
(#135679) NB: This only fixes the crash introduced in Clang 19; we still accept this code even though we shouldn’t: ```c++ struct S { friend int f() { return 3; } friend int f() = delete; }; ``` I tried figuring out a way to diagnose this redeclaration, but it seems tricky because I kept running into issues around defaulted comparison operators. From my testing, however, this fix here would still be required even once we do start diagnosing this. Fixes #135506.
2025-04-15[PAC] Add support for __ptrauth type qualifier (#100830)Akira Hatanaka1-1/+12
The qualifier allows programmer to directly control how pointers are signed when they are stored in a particular variable. The qualifier takes three arguments: the signing key, a flag specifying whether address discrimination should be used, and a non-negative integer that is used for additional discrimination. ``` typedef void (*my_callback)(const void*); my_callback __ptrauth(ptrauth_key_process_dependent_code, 1, 0xe27a) callback; ``` Co-Authored-By: John McCall rjmccall@apple.com