aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaDecl.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-01-11[Sema] Avoid repeated hash lookups (NFC) (#122588)Kazu Hirata1-2/+2
2025-01-11Reapply "[clang] Avoid re-evaluating field bitwidth" (#122289)Timm Baeder1-10/+11
2025-01-10[AArch64][SME] Add diagnostics for SME attributes on lambda functions (#121777)Kerry McLaughlin1-52/+3
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-3/+33
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).
2025-01-08Revert "[clang] Avoid re-evaluating field bitwidth (#117732)"Timm Bäder1-11/+10
This reverts commit 81fc3add1e627c23b7270fe2739cdacc09063e54. This breaks some LLDB tests, e.g. SymbolFile/DWARF/x86/no_unique_address-with-bitfields.cpp: lldb: ../llvm-project/clang/lib/AST/Decl.cpp:4604: unsigned int clang::FieldDecl::getBitWidthValue() const: Assertion `isa<ConstantExpr>(getBitWidth())' failed.
2025-01-08[clang] Avoid re-evaluating field bitwidth (#117732)Timm Baeder1-10/+11
Save the bitwidth value as a `ConstantExpr` with the value set. Remove the `ASTContext` parameter from `getBitWidthValue()`, so the latter simply returns the value from the `ConstantExpr` instead of constant-evaluating the bitwidth expression every time it is called.
2024-12-19[FMV][AArch64] Emit mangled default version if explicitly specified. (#120022)Alexandros Lamprineas1-25/+22
Currently we need at least one more version other than the default to trigger FMV. However we would like a header file declaration __attribute__((target_version("default"))) void f(void); to guarantee that there will be f.default
2024-12-06[AST] Include clang/Basic/DiagnosticComment.h instead of ↵Kazu Hirata1-1/+1
clang/AST/CommentDiagnostic.h (#117499) Since: commit d076608d58d1ec55016eb747a995511e3a3f72aa Author: Richard Trieu <rtrieu@google.com> Date: Sat Dec 8 05:05:03 2018 +0000 clang/AST/CommentDiagnostic.h has been forwarding to clang/Basic/DiagnosticComment.h. This patch includes clang/Basic/DiagnosticComment.h instead of clang/AST/CommentDiagnostic.h.
2024-12-03[Clang] Recover GLTemplateParameterList for generic lambdas in ↵Younan Zhang1-3/+18
RebuildLambdaScopeInfo (#118176) The NTTP argument appearing inside a trailing return type of a generic lambda would have us check for potential lambda captures, where the function needs GLTemplateParameterList of the current LSI to tell whether the lambda is generic. The lambda scope in this context is rebuilt by the LambdaScopeForCallOperatorInstantiationRAII when substituting the lambda operator during template argument deduction. Thus, I think the template parameter list should be preserved in the rebuilding process, as it seems otherwise innocuous to me. Fixes #115931
2024-11-27[Clang/AMDGPU] Zero sized arrays not allowed in HIP device code. (#113470)Vigneshwar Jayakumar1-0/+13
Added diagnosis to throw error when zero sized arrays are used in the HIP device code. SWDEV-449592 --------- Co-authored-by: vigneshwar jayakumar <vigneshwar.jayakumar@amd.com>
2024-11-27[Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref ↵Bill Wendling1-0/+2
(#116719) Implement the sema checks with a placeholder. We then check for that placeholder in all of the places we care to emit a diagnostic. Fixes: #115520
2024-11-27[Sema] Migrate away from PointerUnion::{is,get} (NFC) (#117498)Kazu Hirata1-3/+3
Note that PointerUnion::{is,get} have been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa<T>, cast<T> and the llvm::dyn_cast<T> I'm not touching PointerUnion::dyn_cast for now because it's a bit complicated; we could blindly migrate it to dyn_cast_if_present, but we should probably use dyn_cast when the operand is known to be non-null.
2024-11-22[clang] Infer lifetime_capture_by for STL containers (#117122)Utkarsh Saxena1-0/+2
This is behind `-Wdangling-capture` warning which is disabled by default.
2024-11-21[Clang] Eliminate shadowing warnings for parameters of explicit object ↵Oleksandr T.1-2/+5
member functions (#114813) Fixes #95707.
2024-11-19[Clang] Skip shadow warnings for enum constants in distinct class scopes ↵Oleksandr T.1-3/+8
(#115656) Fixes #62588
2024-11-16[Sema] Remove unused includes (NFC) (#116461)Kazu Hirata1-3/+1
Identified with misc-include-cleaner.
2024-11-13Reapply "[clang] Introduce [[clang::lifetime_capture_by(X)]] (#115823)Utkarsh Saxena1-0/+1
Fix compile time regression and memory leak In the previous change, we saw: - Memory leak: https://lab.llvm.org/buildbot/#/builders/169/builds/5193 - 0.5% Compile time regression [link](https://llvm-compile-time-tracker.com/compare.php?from=4a68e4cbd2423dcacada8162ab7c4bb8d7f7e2cf&to=8c4331c1abeb33eabf3cdbefa7f2b6e0540e7f4f&stat=instructions:u) For compile time regression, we make the Param->Idx `StringMap` for **all** functions. This `StringMap` is expensive and should not be computed when none of the params are annotated with `[[clang::lifetime_capture_by(X)]]`. For the memory leak, the small vectors used in Attribute are not destroyed because the attributes are allocated through ASTContext's allocator. We therefore need a raw array in this case.
2024-11-13[clang] [NFC] Split checkAttributesAfterMerging() to multiple functions ↵Boaz Brickner1-5/+29
(#115464)
2024-11-11Revert "[clang] Introduce [[clang::lifetime_capture_by(X)]] (#111499)"Nikita Popov1-1/+0
This reverts commit 8c4331c1abeb33eabf3cdbefa7f2b6e0540e7f4f. Causes a large compile-time regression, see: https://llvm-compile-time-tracker.com/compare.php?from=4a68e4cbd2423dcacada8162ab7c4bb8d7f7e2cf&to=8c4331c1abeb33eabf3cdbefa7f2b6e0540e7f4f&stat=instructions:u
2024-11-11[clang] Introduce [[clang::lifetime_capture_by(X)]] (#111499)Utkarsh Saxena1-0/+1
This implements the RFC https://discourse.llvm.org/t/rfc-introduce-clang-lifetime-capture-by-x/81371 In this PR, we introduce `[[clang::lifetime_capture_by(X)]]` attribute as discussed in the RFC. As an implementation detail of this attribute, we store and use param indices instead of raw param expressions. The parameter indices are computed lazily at the end of function declaration since the function decl (and therefore the subsequent parameters) are not visible yet while parsing a parameter annotation. In subsequent PR, we will infer this attribute for STL containers and perform lifetime analysis to detect dangling cases.
2024-11-08[C2y] Add test coverage and documentation for WG14 N3341 (#115478)Aaron Ballman1-5/+6
This paper made empty structures and unions implementation-defined. We have always supported this as a GNU extension, so now we're documenting our behavior and removing the extension warning in C2y mode.
2024-11-08Fix issues with WG14 N3344 changesAaron Ballman1-1/+2
This amends 24e2e259a06d9aa67dc278ac24dcb98da9dd63f6 with a fix for 'register void *', which is still okay as a function parameter.
2024-11-07[C2y] Implement WG14 N3344 (#115313)Aaron Ballman1-3/+15
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3344.pdf This paper disallows a single `void` parameter from having qualifiers or storage class specifiers. Clang has diagnosed most of these as an error for a long time, but `register void` was previously accepted in all C language modes and is now being rejected in all C language modes.
2024-11-07[clang] Output an error when [[lifetimebound]] attribute is applied on a ↵Boaz Brickner1-1/+7
function implicit object parameter while the function returns void (#114203) Fixes: https://github.com/llvm/llvm-project/issues/107556
2024-11-06Revert "Reapply "[Clang][Sema] Refactor collection of multi-level template ↵Krystian Stasiowski1-14/+17
argument lists (#106585, #111173)" (#111852)" (#115159) This reverts commit 2bb3d3a3f32ffaef3d9b6a27db7f1941f0cb1136.
2024-11-06Revert "Reapply "[Clang][Sema] Always use latest redeclaration of primary ↵Krystian Stasiowski1-3/+1
template" (#114569)" (#115156) This reverts commit b24650e814e55d90acfc40acf045456c98f32b9c.
2024-11-05[CUDA] Add support for __grid_constant__ attribute (#114589)Artem Belevich1-1/+10
LLVM support for the attribute has been implemented already, so it just plumbs it through to the CUDA front-end. One notable difference from NVCC is that the attribute can be used regardless of the targeted GPU. On the older GPUs it will just be ignored. The attribute is a performance hint, and does not warrant a hard error if compiler can't benefit from it on a particular GPU variant.
2024-11-05[SYCL] The sycl_kernel_entry_point attribute. (#111389)Tom Honermann1-0/+3
The `sycl_kernel_entry_point` attribute is used to declare a function that defines a pattern for an offload kernel to be emitted. The attribute requires a single type argument that specifies the type used as a SYCL kernel name as described in section 5.2, "Naming of kernels", of the SYCL 2020 specification. Properties of the offload kernel are collected when a function declared with the `sycl_kernel_entry_point` attribute is parsed or instantiated. These properties, such as the kernel name type, are stored in the AST context where they are (or will be) used for diagnostic purposes and to facilitate reflection to a SYCL run-time library. These properties are not serialized with the AST but are recreated upon deserialization. The `sycl_kernel_entry_point` attribute is intended to replace the existing `sycl_kernel` attribute which is intended to be deprecated in a future change and removed following an appropriate deprecation period. The new attribute differs in that it is enabled for both SYCL host and device compilation, may be used with non-template functions, explicitly indicates the type used as the kernel name type, and will impact AST generation. This change adds the basic infrastructure for the new attribute. Future changes will add diagnostics and new AST support that will be used to drive generation of the corresponding offload kernel.
2024-11-01Reapply "[Clang][Sema] Always use latest redeclaration of primary template" ↵Krystian Stasiowski1-1/+3
(#114569) This patch reapplies #114258, fixing an infinite recursion bug in `ASTImporter` that occurs when importing the primary template of a class template specialization when the latest redeclaration of that template is a friend declaration in the primary template.
2024-11-01[Clang] prevent setting default lexical access specifier for missing primary ↵Oleksandr T.1-0/+2
declarations (#112424) This PR resolves a crash triggered by a forward reference to an enum type in a function parameter list. The fix includes setting `Invalid` when `TagUseKind` is `Declaration` to ensure correct error handling. Fixes #112208
2024-10-31[clang/AST] Make it possible to use SwiftAttr in type context (#108631)Pavel Yaskevich1-3/+1
Swift ClangImporter now supports concurrency annotations on imported declarations and their parameters/results, to make it possible to use imported APIs in Swift safely there has to be a way to annotate individual parameters and result types with relevant attributes that indicate that e.g. a block is called on a particular actor or it accepts a `Sendable` parameter. To faciliate that `SwiftAttr` is switched from `InheritableAttr` which is a declaration attribute to `DeclOrTypeAttr`. To support this attribute in type context we need access to its "Attribute" argument which requires `AttributedType` to be extended to include `Attr *` when available instead of just `attr::Kind` otherwise it won't be possible to determine what attribute should be imported.
2024-10-30Revert "[Clang][Sema] Always use latest redeclaration of primary template" ↵Felipe de Azevedo Piovezan1-3/+1
(#114304) Clang importer doesn't seem to work well with this change, see discussion in the original PR. Reverts llvm/llvm-project#114258
2024-10-30[Clang][Sema] Always use latest redeclaration of primary template (#114258)Krystian Stasiowski1-1/+3
This patch fixes a couple of regressions introduced in #111852. Consider: ``` template<typename T> struct A { template<bool U> static constexpr bool f() requires U { return true; } }; template<> template<bool U> constexpr bool A<short>::f() requires U { return A<long>::f<U>(); } template<> template<bool U> constexpr bool A<long>::f() requires U { return true; } static_assert(A<short>::f<true>()); // crash here ``` This crashes because when collecting template arguments from the _first_ declaration of `A<long>::f<true>` for constraint checking, we don't add the template arguments from the enclosing class template specialization because there exists another redeclaration that is a member specialization. This also fixes the following example, which happens for a similar reason: ``` // input.cppm export module input; export template<int N> constexpr int f(); template<int N> struct A { template<int J> friend constexpr int f(); }; template struct A<0>; template<int N> constexpr int f() { return N; } ``` ``` // input.cpp import input; static_assert(f<1>() == 1); // error: static assertion failed ```
2024-10-25[clang] Output an error when [[lifetimebound]] attribute is applied on a ↵Boaz Brickner1-1/+13
function parameter while the function returns void (#113460) Fixes: https://github.com/llvm/llvm-project/issues/107556
2024-10-24[clang] Use {} instead of std::nullopt to initialize empty ArrayRef (#109399)Jay Foad1-4/+4
Follow up to #109133.
2024-10-16[HLSL] Collect explicit resource binding information (#111203)Helena Kotas1-0/+3
Scans each global variable declaration and its members and collects all required resource bindings in a new `SemaHLSL` data member `Bindings`. New fields are added `HLSLResourceBindingAttr` for storing processed binding information so that it can be used by CodeGen (`Bindings` or any other Sema information is not accessible from CodeGen.) Adjusts the existing register binding attribute handling and diagnostics to: - do not create HLSLResourceBindingAttribute if it is not valid - diagnose only the simple/local errors when a register binding attribute is parsed - additional diagnostic of binding type mismatches is done later and uses the new `Bindings` data Fixes #110719
2024-10-15[Sema]Use tag name lookup for class names (#112166)Gábor Spaits1-4/+7
This PR would fix #16855 . The correct lookup to use for class names is Tag name lookup, because it does not take namespaces into account. The lookup before does and because of this some valid programs are not accepted. An example scenario of a valid program being declined is when you have a struct (let's call it `y`) inheriting from another struct with a name `x` but the struct `y` is in a namespace that is also called `x`: ``` struct x {}; namespace { namespace x { struct y : x {}; } } ``` This shall be accepted because: ``` C++ [class.derived]p2 (wrt lookup in a base-specifier): The lookup for // the component name of the type-name or simple-template-id is type-only. ```
2024-10-11Reapply "[Clang][Sema] Refactor collection of multi-level template argument ↵Krystian Stasiowski1-17/+14
lists (#106585, #111173)" (#111852) This patch reapplies #111173, fixing a bug when instantiating dependent expressions that name a member template that is later explicitly specialized for a class specialization that is implicitly instantiated. The bug is addressed by adding the `hasMemberSpecialization` function, which return `true` if _any_ redeclaration is a member specialization. This is then used when determining the instantiation pattern for a specialization of a template, and when collecting template arguments for a specialization of a template.
2024-10-11[Clang] [Sema] Don't crash on unexpanded pack in invalid block literal (#110762)Sirraide1-2/+2
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-09Revert "Reapply "[Clang][Sema] Refactor collection of multi-level template ↵Krystian Stasiowski1-14/+17
argument lists (#106585)" (#111173)" (#111766) This reverts commit 4da8ac34f76e707ab94380b94f616457cfd2cb83.
2024-10-09[clang] Change "bad" to "unsupported" in register type error (#111550)David Spickett1-1/+2
This is maybe a personal take but I expect "bad" to either mean: * Allowed but not ideal, like a "bad" memory alignment might work but it is slow. * The tool won't allow it but is going to tell me why it didn't. The current error doesn't elaborate so I think it's best we just say "unsupported" instead. This is clear that the type used is not allowed at all.
2024-10-08Reapply "[Clang][Sema] Refactor collection of multi-level template argument ↵Krystian Stasiowski1-17/+14
lists (#106585)" (#111173) Reapplies #106585, fixing an issue where non-dependent names of member templates appearing prior to that member template being explicitly specialized for an implicitly instantiated class template specialization would incorrectly use the definition of the explicitly specialized member template.
2024-10-08[clang][Sema] Bad register variable type error should point to the type ↵David Spickett1-1/+2
(#110239) ...not the register keyword. Fixes #109776. Until now the error was only tested in clang/test/Sema/asm.c, where you can't check for the "^" character. I've added a new caret test file as I see has been done for other error types.
2024-10-08Recommit "[RISCV][FMV] Support target_version" (#111096)" (#111333)Piyou Chen1-4/+16
Fix the buildbot failure caused by heap use-after-free error. Origin message: This patch enable `target_version` attribute for RISC-V target. The proposal of `target_version` syntax can be found at the https://github.com/riscv-non-isa/riscv-c-api-doc/pull/48 (which has landed), as modified by the proposed https://github.com/riscv-non-isa/riscv-c-api-doc/pull/85 (which adds the priority syntax). `target_version` attribute will trigger the function multi-versioning feature and act like `target_clones` attribute. See https://github.com/llvm/llvm-project/pull/85786 for the implementation of `target_clones`.
2024-10-04Revert "[RISCV][FMV] Support target_version" (#111096)Piyou Chen1-15/+4
Reverts llvm/llvm-project#99040 due to https://lab.llvm.org/buildbot/#/builders/190/builds/7052
2024-10-04[RISCV][FMV] Support target_version (#99040)Piyou Chen1-4/+15
This patch enable `target_version` attribute for RISC-V target. The proposal of `target_version` syntax can be found at the https://github.com/riscv-non-isa/riscv-c-api-doc/pull/48 (which has landed), as modified by the proposed https://github.com/riscv-non-isa/riscv-c-api-doc/pull/85 (which adds the priority syntax). `target_version` attribute will trigger the function multi-versioning feature and act like `target_clones` attribute. See https://github.com/llvm/llvm-project/pull/85786 for the implementation of `target_clones`.
2024-10-03[Clang] nonblocking/nonallocating attributes: 2nd pass caller/callee ↵Doug Wyatt1-57/+8
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-10-02Allow tag-based API notes on anonymous tag decls with typedef namesDoug Gregor1-0/+3
It is common practice in C to declare anonymous tags that are immediately given a typedef name, e.g., typedef enum { ... } MyType; At present, one can only express API notes on the typedef. However, that excludes the possibility of tag-specific notes like EnumExtensibility. For these anonymous declarations, process API notes using the typedef name as the tag name, so that one can add API notes to `MyType` via the `Tags` section.
2024-10-02[Clang] Emit a diagnostic note at the class declaration when the method ↵c8ef1-3/+8
definition does not match any declaration. (#110638) Fixes #110558. In this patch, we will emit a diagnostic note pointing to the class declaration when a method definition does not match any declaration. This approach, similar to what GCC does, makes the diagnostic more user-friendly. --------- Co-authored-by: Vlad Serebrennikov <serebrennikov.vladislav@gmail.com>
2024-10-01[Clang] Implement CWG 2707 "Deduction guides cannot have a trailing ↵Younan Zhang1-7/+4
requires-clause" (#110473) Closes https://github.com/llvm/llvm-project/issues/98595