aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaLambda.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-26[clang] NFC: introduce Type::getAsEnumDecl, and cast variants for all ↵Matheus Izvekov1-3/+2
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-20[Clang] Reapply "Only remove lambda scope after computing evaluation ↵Younan Zhang1-137/+131
context" (#154458) The immediate evaluation context needs the lambda scope info to propagate some flags, however that LSI was removed in ActOnFinishFunctionBody which happened before rebuilding a lambda expression. The last attempt destroyed LSI at the end of the block scope, after which we still need it in DiagnoseShadowingLambdaDecls. This also converts the wrapper function to default arguments as a drive-by fix, as well as does some cleanup. Fixes https://github.com/llvm/llvm-project/issues/145776
2025-08-20Revert "[Clang] Only remove lambda scope after computing evaluation context" ↵Younan Zhang1-13/+5
(#154382) Revert due to breakage as reported in https://github.com/llvm/llvm-project/pull/154106#discussion_r2285824084 Reverts llvm/llvm-project#154106
2025-08-19[Clang] Only remove lambda scope after computing evaluation context (#154106)Younan Zhang1-5/+13
The immediate evaluation context needs the lambda scope info to propagate some flags, however that LSI was removed in ActOnFinishFunctionBody which happened before rebuilding a lambda expression. This also converts the wrapper function to default arguments as a drive-by fix. Fixes https://github.com/llvm/llvm-project/issues/145776
2025-08-09[clang] Improve nested name specifier AST representation (#147835)Matheus Izvekov1-4/+4
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-07-10[Clang] Do not skip over `RequiresExprBodyDecl` when creating lambdas (#147764)Corentin Jabot1-2/+0
When we create a lambda, we would skip over declaration contexts representing a require expression body, which would lead to wrong lookup. Note that I wasn't able to establish why the code in `Sema::createLambdaClosureType` was there to begin with (it's not exactly recent) The changes to mangling only ensure the status quo is preserved and do not attempt to address the known issues of mangling lambdas in require clauses. In particular the itanium mangling is consistent with Clang before this patch but differs from GCC's. Fixes #147650
2025-06-03[clang] Correct FixIt ranges for unused capture warnings (#141148)Oliver Hunt1-16/+45
Fixes #106445 by using the lexer to find the correct range for the removal FixIts. Previously the ranges that were generated assuming no unsurprising formatting, which for the most part works. Being correct in all cases requires using the lexer to find the bounding tokens for the region to remove. As part of this it adds Sema::getRangeForNextToken to wrap Lexer::findNextToken.
2025-05-20[Clang] Functions called in discarded statements should not be instantiated ↵cor3ntin1-8/+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-18[clang] Use llvm::unique (NFC) (#140459)Kazu Hirata1-2/+2
2025-05-02[clang][NFC] Reland "Convert `Sema::TryCaptureKind` to scoped enum"Vlad Serebrennikov1-9/+9
2025-05-02Revert "[clang][NFC] Convert `Sema::TryCaptureKind` to scoped enum"Vlad Serebrennikov1-9/+9
This reverts commit be6497ff7583248d76a6710dd48cfeb63dd68f27.
2025-05-02[clang][NFC] Convert `Sema::TryCaptureKind` to scoped enumVlad Serebrennikov1-9/+9
2025-04-03[clang] NFC: introduce UnsignedOrNone as a replacement for ↵Matheus Izvekov1-14/+11
std::optional<unsigned> (#134142) This introduces a new class 'UnsignedOrNone', which models a lite version of `std::optional<unsigned>`, but has the same size as 'unsigned'. This replaces most uses of `std::optional<unsigned>`, and similar schemes utilizing 'int' and '-1' as sentinel. Besides the smaller size advantage, this is simpler to serialize, as its internal representation is a single unsigned int as well.
2025-04-03[clang] support pack expansions for trailing requires clauses (#133190)Matheus Izvekov1-7/+11
2025-04-03[Clang] Fix a lambda pattern comparison mismatch after ecc7e6ce4 (#133863)Younan Zhang1-0/+68
In ecc7e6ce4, we tried to inspect the `LambdaScopeInfo` on stack to recover the instantiating lambda captures. However, there was a mismatch in how we compared the pattern declarations of lambdas: the constraint instantiation used a tailored `getPatternFunctionDecl()` which is localized in SemaLambda that finds the very primal template declaration of a lambda, while `FunctionDecl::getTemplateInstantiationPattern` finds the latest template pattern of a lambda. This difference causes issues when lambdas are nested, as we always want the primary template declaration. This corrects that by moving `Sema::addInstantiatedCapturesToScope` from SemaConcept to SemaLambda, allowing it to use the localized version of `getPatternFunctionDecl`. It is also worth exploring to coalesce the implementation of `getPatternFunctionDecl` with `FunctionDecl::getTemplateInstantiationPattern`. But I’m leaving that for the future, as I’d like to backport this fix (ecc7e6ce4 made the issue more visible in clang 20, sorry!), and changing Sema’s ABI would not be suitable in that regards. Hence, no release note. Fixes https://github.com/llvm/llvm-project/issues/133719
2025-03-13[C++20] [Modules] Add mangling number for lambda in non-internal module unit ↵Chuanqi Xu1-13/+36
context Close https://github.com/llvm/llvm-project/issues/59513 Close https://github.com/llvm/llvm-project/issues/110146 As we discussed, this is related to ABI: https://github.com/itanium-cxx-abi/cxx-abi/issues/186 I was intending to fix this after it gets merged into the ItaniumC++ABI formally. But it looks like ItaniumC++ABI doesn't update it yet and there are more issue reports for it. Luckily Richard had a clear direction guide here though. So I think it should be good to do this without a formal ItaniumC++ABI wording. The diff of the patch is slightly larger than it was by a simple refacoration to simple the control flow a little bit.
2025-03-10Revert "[clang] Implement instantiation context note for checking template ↵Nikita Popov1-3/+4
parameters (#126088)" This reverts commit a24523ac8dc07f3478311a5969184b922b520395. This is causing significant compile-time regressions for C++ code, see: https://github.com/llvm/llvm-project/pull/126088#issuecomment-2704874202
2025-03-06[clang] Implement instantiation context note for checking template ↵Matheus Izvekov1-4/+3
parameters (#126088) Instead of manually adding a note pointing to the relevant template parameter to every relevant error, which is very easy to miss, this patch adds a new instantiation context note, so that this can work using RAII magic. This fixes a bunch of places where these notes were missing, and is more future-proof. Some diagnostics are reworked to make better use of this note: - Errors about missing template arguments now refer to the parameter which is missing an argument. - Template Template parameter mismatches now refer to template parameters as parameters instead of arguments. It's likely this will add the note to some diagnostics where the parameter is not super relevant, but this can be reworked with time and the decrease in maintenance burden makes up for it. This bypasses the templight dumper for the new context entry, as the tests are very hard to update. This depends on #125453, which is needed to avoid losing the context note for errors occuring during template argument deduction.
2025-01-26[Clang] Correctly determine constexprness of dependent lambdas. (#124468)cor3ntin1-7/+7
We skipped checking if a lambda is constexpr if the parent context was dependent, even if the lambda itself wasn't (and there is no other opportunity to establish constexprness) Fixes #114234 Fixes #97958
2025-01-21[Clang] Delegate part of SetupConstraintScope's job to ↵Younan Zhang1-16/+12
LambdaScopeForCallOperatorInstantiationRAII (#123687) Now that the RAII object has a dedicate logic for handling nested lambdas, where the inner lambda could reference any captures/variables/parameters from the outer lambda, we can shift the responsibility for managing lambdas away from SetupConstraintScope(). I think this also makes the structure clearer. Fixes https://github.com/llvm/llvm-project/issues/123441
2025-01-10[AArch64][SME] Add diagnostics for SME attributes on lambda functions (#121777)Kerry McLaughlin1-0/+4
CheckFunctionDeclaration emits diagnostics if any SME attributes are used by a function definition without the required +sme or +sme2 target features. This patch moves these diagnostics to a new function in SemaARM and also adds a call to this from ActOnStartOfLambdaDefinition.
2025-01-09[SYCL] Basic diagnostics for the sycl_kernel_entry_point attribute. (#120327)Tom Honermann1-0/+5
The `sycl_kernel_entry_point` attribute is used to declare a function that defines a pattern for an offload kernel entry point. The attribute requires a single type argument that specifies a class type that meets the requirements for a SYCL kernel name as described in section 5.2, "Naming of kernels", of the SYCL 2020 specification. A unique kernel name type is required for each function declared with the attribute. The attribute may not first appear on a declaration that follows a definition of the function. The function is required to have a non-deduced `void` return type. The function must not be a non-static member function, be deleted or defaulted, be declared with the `constexpr` or `consteval` specifiers, be declared with the `[[noreturn]]` attribute, be a coroutine, or accept variadic arguments. Diagnostics are not yet provided for the following: - Use of a type as a kernel name that does not satisfy the forward declarability requirements specified in section 5.2, "Naming of kernels", of the SYCL 2020 specification. - Use of a type as a parameter of the attributed function that does not satisfy the kernel parameter requirements specified in section 4.12.4, "Rules for parameter passing to kernels", of the SYCL 2020 specification (each such function parameter constitutes a kernel parameter). - Use of language features that are not permitted in device functions as specified in section 5.4, "Language restrictions for device functions", of the SYCL 2020 specification. There are several issues noted by various FIXME comments. - The diagnostic generated for kernel name conflicts needs additional work to better detail the relevant source locations; such as the location of each declaration as well as the original source of each kernel name. - A number of the tests illustrate spurious errors being produced due to attributes that appertain to function templates being instantiated too early (during overload resolution as opposed to after an overload is selected). Included changes allow the `SYCLKernelEntryPointAttr` attribute to be marked as invalid if a `sycl_kernel_entry_point` attribute is used incorrectly. This is intended to prevent trying to emit an offload kernel entry point without having to mark the associated function as invalid since doing so would affect overload resolution; which this attribute should not do. Unfortunately, Clang eagerly instantiates attributes that appertain to functions with the result that errors might be issued for function declarations that are never selected by overload resolution. Tests have been added to demonstrate this. Further work will be needed to address these issues (for this and other attributes).
2024-11-18[Clang] SemaFunctionEffects: Fix bug where lambdas produced by template ↵Doug Wyatt1-2/+1
expansion weren't verified. (#116505) --------- Co-authored-by: Doug Wyatt <dwyatt@apple.com>
2024-10-24[clang] Use {} instead of std::nullopt to initialize empty ArrayRef (#109399)Jay Foad1-6/+4
Follow up to #109133.
2024-10-11[Clang] [Sema] Don't crash on unexpanded pack in invalid block literal (#110762)Sirraide1-1/+4
Consider #109148: ```c++ template <typename ...Ts> void f() { [] { (^Ts); }; } ``` When we encounter `^Ts`, we try to parse a block and subsequently call `DiagnoseUnexpandedParameterPack()` (in `ActOnBlockArguments()`), which sees `Ts` and sets `ContainsUnexpandedParameterPack` to `true` in the `LambdaScopeInfo` of the enclosing lambda. However, the entire block is subsequently discarded entirely because it isn’t even syntactically well-formed. As a result, `ContainsUnexpandedParameterPack` is `true` despite the lambda’s body no longer containing any unexpanded packs, which causes an assertion the next time `DiagnoseUnexpandedParameterPack()` is called. This pr moves handling of unexpanded parameter packs into `CapturingScopeInfo` instead so that the same logic is used for both blocks and lambdas. This fixes this issue since the `ContainsUnexpandedParameterPack` flag is now part of the block (and before that, its `CapturingScopeInfo`) and no longer affects the surrounding lambda directly when the block is parsed. Moreover, this change makes blocks actually usable with pack expansion. This fixes #109148.
2024-10-04[Sema] Avoid repeated hash lookups (NFC) (#111090)Kazu Hirata1-3/+3
2024-10-03[Clang] nonblocking/nonallocating attributes: 2nd pass caller/callee ↵Doug Wyatt1-0/+3
analysis (#99656) - In Sema, when encountering Decls with function effects needing verification, add them to a vector, DeclsWithEffectsToVerify. - Update AST serialization to include DeclsWithEffectsToVerify. - In AnalysisBasedWarnings, use DeclsWithEffectsToVerify as a work queue, verifying functions with declared effects, and inferring (when permitted and necessary) whether their callees have effects. --------- Co-authored-by: Doug Wyatt <dwyatt@apple.com> Co-authored-by: Sirraide <aeternalmail@gmail.com> Co-authored-by: Erich Keane <ekeane@nvidia.com>
2024-09-03[Clang] Fix handling of placeholder variables name in init captures (#107055)cor3ntin1-1/+0
We were incorrectly not deduplicating results when looking up `_` which, for a lambda init capture, would result in an ambiguous lookup. The same bug caused some diagnostic notes to be emitted twice. Fixes #107024
2024-08-17[clang][NFC] Clean up `Sema` headersVlad Serebrennikov1-0/+1
When various `Sema*.h` and `Sema*.cpp` files were created, cleanup of `Sema.h` includes and forward declarations was left for the later. Now's the time. This commit touches `Sema.h` and Sema components: 1. Unused includes are removed. 2. Unused forward declarations are removed. 3. Missing includes are added (those files are largely IWYU-clean now). 4. Includes were converted into forward declarations where possible. As this commit focuses on headers, all changes to `.cpp` files were minimal, and were aiming at keeping everything buildable.
2024-08-09[Clang] Fix Handling of Init Capture with Parameter Packs in ↵Yupei Liu1-2/+7
LambdaScopeForCallOperatorInstantiationRAII (#100766) This PR addresses issues related to the handling of `init capture` with parameter packs in Clang's `LambdaScopeForCallOperatorInstantiationRAII`. Previously, `addInstantiatedCapturesToScope` would add `init capture` containing packs to the scope using the type of the `init capture` to determine the expanded pack size. However, this approach resulted in a pack size of 0 because `getType()->containsUnexpandedParameterPack()` returns `false`. After extensive testing, it appears that the correct pack size can only be inferred from `getInit`. But `getInit` may reference parameters and `init capture` from an outer lambda, as shown in the following example: ```cpp auto L = [](auto... z) { return [... w = z](auto... y) { // ... }; }; ``` To address this, `addInstantiatedCapturesToScope` in `LambdaScopeForCallOperatorInstantiationRAII` should be called last. Additionally, `addInstantiatedCapturesToScope` has been modified to only add `init capture` to the scope. The previous implementation incorrectly called `MakeInstantiatedLocalArgPack` for other non-init captures containing packs, resulting in a pack size of 0. ### Impact This patch affects scenarios where `LambdaScopeForCallOperatorInstantiationRAII` is passed with `ShouldAddDeclsFromParentScope = false`, preventing the correct addition of the current lambda's `init capture` to the scope. There are two main scenarios for `ShouldAddDeclsFromParentScope = false`: 1. **Constraints**: Sometimes constraints are instantiated in place rather than delayed. In this case, `LambdaScopeForCallOperatorInstantiationRAII` does not need to add `init capture` to the scope. 2. **`noexcept` Expressions**: The expressions inside `noexcept` have already been transformed, and the packs referenced within have been expanded. Only `RebuildLambdaInfo` needs to add the expanded captures to the scope, without requiring `addInstantiatedCapturesToScope` from `LambdaScopeForCallOperatorInstantiationRAII`. ### Considerations An alternative approach could involve adding a data structure within the lambda to record the expanded size of the `init capture` pack. However, this would increase the lambda's size and require extensive modifications. This PR is a prerequisite for implmenting https://github.com/llvm/llvm-project/issues/61426
2024-08-06[Sema] Preserve ContainsUnexpandedParameterPack in TransformLambdaExpr (#86265)Younan Zhang1-0/+4
The lambda `ContainsUnexpandedParameterPack` flag is used for the expressions' dependency computing and is therefore essential for pack expansion. We previously lost the flag's preservation during the lambda's transform, which caused some issues, e.g. a fold expression couldn't properly expand inside a template. This patch alleviates the issue by retaining the flag in more scenarios. Note that we still have problems with constraints involving packs regarding lambdas, and dealing with that would take more effort, and we'd like to fix them in the future. Fixes https://github.com/llvm/llvm-project/issues/56852 Fixes https://github.com/llvm/llvm-project/issues/85667 Mitigates https://github.com/llvm/llvm-project/issues/99877 because the attributes were not handled in this patch. --------- Co-authored-by: Ilya Biryukov <809452+ilya-biryukov@users.noreply.github.com> Co-authored-by: cor3ntin <corentinjabot@gmail.com>
2024-07-11[Clang] Correctly recognize unexpanded packs in lambda template params (#98496)cor3ntin1-0/+2
Fixes #48937 Fixes #49099
2024-07-09[Clang] Fix the order of addInstantiatedParameters in ↵Yupei Liu1-14/+28
LambdaScopeForCallOperatorInstantiationRAII (#97215) Currently, `addInstantiatedParameters` is called from the innermost lambda outward. However, when the function parameters of an inner lambda depend on the function parameters of an outer lambda, it can lead to a crash due to the inability to find a mapping for the instantiated decl. This PR corrects this behavior by calling `addInstantiatedParameters` from the outside in. repro code: https://godbolt.org/z/KbsxWesW6 ```cpp namespace dependent_param_concept { template <typename... Ts> void sink(Ts...) {} void dependent_param() { auto L = [](auto... x) { return [](decltype(x)... y) { // `y` depends on `x` return [](int z) requires requires { sink(y..., z); } {}; }; }; L(0, 1)(1, 2)(1); } } // namespace dependent_param_concept ``` This PR is a prerequisite for implmenting #61426
2024-07-01[Sema] Fix -Wunused-but-set-variable after #94865Fangrui Song1-1/+1
2024-07-01[Clang] Improve error message for lambda captures that name a class member ↵CedricSWA1-1/+5
(#94865) This introduces are more helpful error message when trying to explicitly capture a class member in a lambda. Fixes #94764.
2024-06-28[Sema] LambdaScopeForCallOperatorInstantiationRAII - fix typo in early out ↵Simon Pilgrim1-1/+1
logic (#96888) We should be checking for a failed dyn_cast on the ParentFD result - not the loop invariant FD root value. Seems to have been introduced in #65193 Noticed by static analyser (I have no specific test case).
2024-06-04[Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (#93206)Younan Zhang1-9/+20
This patch picks up #78598 with the hope that we can address such crashes in `tryCaptureVariable()` for unevaluated lambdas. In addition to `tryCaptureVariable()`, this also contains several other fixes on e.g. lambda parsing/dependencies. Fixes #63845 Fixes #67260 Fixes #69307 Fixes #88081 Fixes #89496 Fixes #90669 Fixes #91633
2024-05-22[Clang] Perform derived-to-base conversion on explicit object parameter in ↵Sirraide1-14/+54
lambda (#89828) Consider this code: ```c++ template <typename... Ts> struct Overloaded : Ts... { using Ts::operator()...; }; template <typename... Ts> Overloaded(Ts...) -> Overloaded<Ts...>; void f() { int x; Overloaded o { [&](this auto& self) { return &x; } }; o(); } ``` To access `x` in the lambda, we need to perform derived-to-base conversion on `self` (since the type of `self` is not the lambda type, but rather `Overloaded<(lambda type)>`). We were previously missing this step, causing us to attempt to load the entire lambda (as the base class, it would end up being the ‘field’ with index `0` here), which would then assert later on in codegen. Moreover, this is only valid in the first place if there is a unique and publicly accessible cast path from the derived class to the lambda’s type, so this also adds a check in Sema to diagnose problematic cases. This fixes #87210 and fixes #89541.
2024-04-16[clang] Introduce `SemaOpenMP` (#88642)Vlad Serebrennikov1-1/+2
This patch moves OpenMP-related entities out of `Sema` to a newly created `SemaOpenMP` class. This is a part of the effort to split `Sema` up, and follows the recent example of CUDA, OpenACC, SYCL, HLSL. Additional context can be found in https://github.com/llvm/llvm-project/pull/82217, https://github.com/llvm/llvm-project/pull/84184, https://github.com/llvm/llvm-project/pull/87634.
2024-04-13[clang] Introduce `SemaCUDA` (#88559)Vlad Serebrennikov1-4/+5
This patch moves CUDA-related `Sema` function into new `SemaCUDA` class, following the recent example of SYCL, OpenACC, and HLSL. This is a part of the effort to split Sema. Additional context can be found in https://github.com/llvm/llvm-project/pull/82217, https://github.com/llvm/llvm-project/pull/84184, https://github.com/llvm/llvm-project/pull/87634.
2024-01-17[Clang][Sema][NFC] Remove unused Scope* parameter from ↵Krystian Stasiowski1-1/+1
Sema::GetTypeForDeclarator and Sema::ActOnTypeName (#78325) Split from #78274
2023-12-12[clang][NFC] Remove unused parameterTimm Bäder1-2/+1
2023-12-06[Clang][Sema] Don't say "is declared here" for invalid template locationsJustin Bogner1-1/+1
If a template is defined via an external AST source, it won't have a location. When we emit warnings about misusing such templates we shouldn't emit a "template is declared here" warning with no location, as that's just confusing. Reviewers: llvm-beanz, erichkeane, AaronBallman Reviewed By: erichkeane, AaronBallman Pull Request: https://github.com/llvm/llvm-project/pull/71264
2023-10-11[clang] __is_trivially_equality_comparable for types containing lambdas (#68506)Amirreza Ashouri1-2/+1
Lambdas (closure types) are trivially equality-comparable iff they are non-capturing, because non-capturing lambdas are convertible to function pointers: if (lam1 == lam2) compiles, then lam1 and lam2 must have the same type, and be always-equal, and be empty.
2023-10-04[clang][Sema] Fix a bug when instantiating a lambda with requires clause ↵Sheng1-20/+42
(#65193) Instantiating a lambda at a scope different from where it is defined will paralyze clang if the trailing require clause refers to local variables. This patch fixes this by re-adding the local variables to `LocalInstantiationScope`. Fixes #64462
2023-10-02[C++] Implement "Deducing this" (P0847R7)Corentin Jabot1-2/+42
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-3/+2
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[clang][SemaCXX] Diagnose tautological uses of consteval if and ↵Takuya Shimizu1-2/+3
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-08[Clang] Add captures to the instantiation scope of lambda call operatorsCorentin Jabot1-0/+32
Like concepts checking, a trailing return type of a lambda in a dependent context may refer to captures in which case they may need to be rebuilt, so the map of local decl should include captures. This patch reveal a pre-existing issue. `this` is always recomputed by TreeTransform. `*this` (like all captures) only become `const` after the parameter list. However, if try to recompute the value of `this` (in a parameter) during template instantiation while determining the type of the call operator, we will determine it to be const (unless the lambda is mutable). There is no good way to know at that point that we are in a parameter or not, the easiest/best solution is to transform the type of this. Note that doing so break a handful of HLSL tests. So this is a prototype at this point. Fixes #65067 Fixes #63675 Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D159126
2023-09-07Revert "[Clang] Add captures to the instantiation scope of lambda call ↵Corentin Jabot1-32/+0
operators" The change causes some libcxx regressions This reverts commit eaf725bc9371a6699902d67d97662caaa3332799.