aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaLookup.cpp
AgeCommit message (Collapse)AuthorFilesLines
6 days[Clang][AST][NFC] Introduce `NamespaceBaseDecl` (#149123)Yanzuo Liu1-7/+6
Add `NamespaceBaseDecl` as common base class of `NamespaceDecl` and `NamespaceAliasDecl`. This simplifies `NestedNameSpecifier` a bit. Co-authored-by: Matheus Izvekov <mizvekov@gmail.com>
8 days[NFC] Remove getDefaultCallingConvention IsBuiltin (#145904)Harald van Dijk1-1/+2
ASTContext::getDefaultCallingConvention() was documented as returning "the default calling convention for the current target", but did not do this, and was never intended to do this, it has always been controlled by command-line options to deviate from the target default. This commit changes ASTContext::getDefaultCallingConvention() to reflect the fact that it returns the context's default calling convention, not the target's default calling convention. The IsBuiltin parameter, which was used to return the target's default calling convention rather than the context's, is removed in favor of getTargetInfo().getDefaultCallingConv() which is more explicit of the intent.
2025-06-23[C++20] [Modules] Don't make enum constant members always visibleChuanqi Xu1-16/+19
Close https://github.com/llvm/llvm-project/issues/131058 See the comments in ASTWriter.cpp:ASTDeclContextNameLookupTrait::getLookupVisibility and SemaLookup.cpp:Sema::makeMergedDefinitionVisible for details.
2025-06-13Remove delayed typo expressions (#143423)Aaron Ballman1-60/+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-12[C++20] [Modules] Treat directly imported internal partition unit as reachableChuanqi Xu1-5/+18
Close https://github.com/llvm/llvm-project/issues/143788 See the discussion for details.
2025-05-27[HLSL] Implement `SpirvType` and `SpirvOpaqueType` (#134034)Cassandra Beckley1-2/+19
This implements the design proposed by [Representing SpirvType in Clang's Type System](https://github.com/llvm/wg-hlsl/pull/181). It creates `HLSLInlineSpirvType` as a new `Type` subclass, and `__hlsl_spirv_type` as a new builtin type template to create such a type. This new type is lowered to the `spirv.Type` target extension type, as described in [Target Extension Types for Inline SPIR-V and Decorated Types](https://github.com/llvm/wg-hlsl/blob/main/proposals/0017-inline-spirv-and-decorated-types.md).
2025-05-20[RISCV] Implement intrinsics for XAndesVPackFPH (#140007)Jim Lin1-1/+2
This patch implements clang intrinsic support for XAndesVPackFPH. The document for the intrinsics can be found at: https://github.com/andestech/andes-vector-intrinsic-doc/blob/ast-v5_4_0-release-v5/auto-generated/andes-v5/intrinsic_funcs.adoc#andes-vector-packed-fp16-extensionxandesvpackfph and with policy variants https://github.com/andestech/andes-vector-intrinsic-doc/blob/ast-v5_4_0-release-v5/auto-generated/andes-v5/policy_funcs/intrinsic_funcs.adoc#andes-vector-packed-fp16-extensionxandesvpackfph Co-authored-by: Tony Chuan-Yue Yuan <yuan593@andestech.com>
2025-05-02[clang][NFC] Convert `Sema::CorrectTypoKind` to scoped enumVlad Serebrennikov1-6/+6
2025-04-28[clang][NFC] Convert LookupResultKind to scoped enumVlad Serebrennikov1-28/+30
2025-04-28[clang][NFC] Convert `LookupResult::AmbiguityKind` to scoped enumVlad Serebrennikov1-14/+16
2025-04-19[clang] llvm::append_range (NFC) (#136440)Kazu Hirata1-1/+1
2025-04-12Reland: [clang] Improved canonicalization for template specialization types ↵Matheus Izvekov1-1/+2
(#135414) This relands https://github.com/llvm/llvm-project/pull/135119, after fixing crashes seen in LLDB CI reported here: https://github.com/llvm/llvm-project/pull/135119#issuecomment-2794910840 Fixes https://github.com/llvm/llvm-project/pull/135119 This changes the TemplateArgument representation to hold a flag indicating whether a tempalte argument of expression type is supposed to be canonical or not. This gets one step closer to solving https://github.com/llvm/llvm-project/issues/92292 This still doesn't try to unique as-written TSTs. While this would increase the amount of memory savings and make code dealing with the AST more well-behaved, profiling template argument lists is still too expensive for this to be worthwhile, at least for now. This also fixes the context creation of TSTs, so that they don't in some cases get incorrectly flagged as sugar over their own canonical form. This is captured in the test expectation change of some AST dumps. This fixes some places which were unnecessarily canonicalizing these TSTs.
2025-04-11Revert "[clang] Improved canonicalization for template specialization types" ↵Dmitry Vasilyev1-2/+1
(#135354) Reverts llvm/llvm-project#135119 because of the assert in ASTContext.cpp, line 5619. See #135352 for details.
2025-04-10[clang] Improved canonicalization for template specialization types (#135119)Matheus Izvekov1-1/+2
This changes the TemplateArgument representation to hold a flag indicating whether a template argument of expression type is supposed to be canonical or not. This gets one step closer to solving https://github.com/llvm/llvm-project/issues/92292 This still doesn't try to unique as-written TSTs. While this would increase the amount of memory savings and make code dealing with the AST more well-behaved, profiling template argument lists is still too expensive for this to be worthwhile, at least for now. Without this uniquing, this patch stands neutral in terms of performance impact. This also fixes the context creation of TSTs, so that they don't in some cases get incorrectly flagged as sugar over their own canonical form. This is captured in the test expectation change of some AST dumps. This fixes some places which were unnecessarily canonicalizing these TSTs.
2025-04-01[clang] improved preservation of template keyword (#133610)Matheus Izvekov1-3/+1
2025-03-25[clang] fix crash with ADL for member pointers with dependent class (#132977)Matheus Izvekov1-2/+2
2025-03-21Reland: [clang] NFC: Clear some uses of MemberPointerType::getClass (#132317)Matheus Izvekov1-5/+2
Relands Original PR: https://github.com/llvm/llvm-project/pull/131965 Addresses https://github.com/llvm/llvm-project/pull/131965#issuecomment-2741619498 * Fixes isIncompleteType for injected classes This clears up some uses of getClass on MemberPointerType when equivalent uses of getMostRecentCXXRecordDecl would be just as simple or simpler. This is split-off from a larger patch which removes getClass, in order to facilitate review.
2025-03-20Revert "[clang] NFC: Clear some uses of MemberPointerType::getClass" (#132281)Matheus Izvekov1-2/+5
Reverts llvm/llvm-project#131965 Reverted due to issue reported here: https://github.com/llvm/llvm-project/pull/131965#issuecomment-2741619498
2025-03-19[clang] NFC: Clear some uses of MemberPointerType::getClass (#131965)Matheus Izvekov1-5/+2
2025-03-10Revert "[clang] Implement instantiation context note for checking template ↵Nikita Popov1-10/+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/+10
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-02-26[Clang] Add BuiltinTemplates.td to generate code for builtin templates (#123736)Nikolas Klauser1-12/+6
This makes it significantly easier to add new builtin templates, since you only have to modify two places instead of a dozen or so. The `BuiltinTemplates.td` could also be extended to generate documentation from it in the future.
2025-01-28[clang] NFC: cleanup check template argument (#124668)Matheus Izvekov1-4/+2
2025-01-28[clang] disallow narrowing when matching template template parameters (#124313)Matheus Izvekov1-1/+1
This fixes the core issue described in P3579, following the design intent of P0522 to not introduce any new cases where a template template parameter match is allowed for a template which is not valid for all possible uses. With this patch, narrowing conversions are disallowed for TTP matching. This reuses the existing machinery for diagnosing narrowing in a converted constant expression. Since P0522 is a DR and we apply it all the way back to C++98, this brings that machinery to use in older standards, in this very narrow scope of TTP matching. This still doesn't solve the ambiguity when partial ordering NTTPs of different integral types, this is blocked by a different bug which will be fixed in a subsequent patch (but the test cases are added).
2025-01-24[C++20] [Modules] Fix may-be incorrect ADL for module local entities (#123931)Chuanqi Xu1-1/+51
Close https://github.com/llvm/llvm-project/issues/123815 See the comments for details. We can't get primary context arbitrarily since the redecl may have different context and information. There is a TODO for modules specific case, I'd like to make it after this PR.
2025-01-23Reland: [clang] unified CWG2398 and P0522 changes; finishes implementation ↵Matheus Izvekov1-1/+3
of P3310 (#124137) This patch relands the following PRs: * #111711 * #107350 * #111457 All of these patches were reverted due to an issue reported in https://github.com/llvm/llvm-project/pull/111711#issuecomment-2406491485, due to interdependencies. --- [clang] Finish implementation of P0522 This finishes the clang implementation of P0522, getting rid of the fallback to the old, pre-P0522 rules. Before this patch, when partial ordering template template parameters, we would perform, in order: * If the old rules would match, we would accept it. Otherwise, don't generate diagnostics yet. * If the new rules would match, just accept it. Otherwise, don't generate any diagnostics yet again. * Apply the old rules again, this time with diagnostics. This situation was far from ideal, as we would sometimes: * Accept some things we shouldn't. * Reject some things we shouldn't. * Only diagnose rejection in terms of the old rules. With this patch, we apply the P0522 rules throughout. This needed to extend template argument deduction in order to accept the historial rule for TTP matching pack parameter to non-pack arguments. This change also makes us accept some combinations of historical and P0522 allowances we wouldn't before. It also fixes a bunch of bugs that were documented in the test suite, which I am not sure there are issues already created for them. This causes a lot of changes to the way these failures are diagnosed, with related test suite churn. The problem here is that the old rules were very simple and non-recursive, making it easy to provide customized diagnostics, and to keep them consistent with each other. The new rules are a lot more complex and rely on template argument deduction, substitutions, and they are recursive. The approach taken here is to mostly rely on existing diagnostics, and create a new instantiation context that keeps track of this context. So for example when a substitution failure occurs, we use the error produced there unmodified, and just attach notes to it explaining that it occurred in the context of partial ordering this template argument against that template parameter. This diverges from the old diagnostics, which would lead with an error pointing to the template argument, explain the problem in subsequent notes, and produce a final note pointing to the parameter. --- [clang] CWG2398: improve overload resolution backwards compat With this change, we discriminate if the primary template and which partial specializations would have participated in overload resolution prior to P0522 changes. We collect those in an initial set. If this set is not empty, or the primary template would have matched, we proceed with this set as the candidates for overload resolution. Otherwise, we build a new overload set with everything else, and proceed as usual. --- [clang] Implement TTP 'reversed' pack matching for deduced function template calls. Clang previously missed implementing P0522 pack matching for deduced function template calls.
2025-01-22[C++20] [Modules] Correct the visibility of decls in implicit global module ↵Chuanqi Xu1-1/+3
of other units in the same TU See the test for the case. It is similar with https://github.com/llvm/llvm-project/commit/baa5b769f2f76baa0ce1ebfe28236dee2c761f0d
2025-01-17[C++20] [Modules] Make module local decls visible to language linkage in the ↵Chuanqi Xu1-0/+5
same module Close https://github.com/llvm/llvm-project/issues/123343 See the issue and the comments in the patch for details.
2024-11-16[Sema] Remove unused includes (NFC) (#116461)Kazu Hirata1-1/+0
Identified with misc-include-cleaner.
2024-10-24[clang] Use {} instead of std::nullopt to initialize empty ArrayRef (#109399)Jay Foad1-1/+1
Follow up to #109133.
2024-10-15[HLSL] Make HLSLAttributedResourceType canonical and add code paths to ↵Helena Kotas1-0/+3
convert HLSL types to DirectX target types (#110327) Translates `RWBuffer` and `StructuredBuffer` resources buffer types to DirectX target types `dx.TypedBuffer` and `dx.RawBuffer`. Includes a change of `HLSLAttributesResourceType` from 'sugar' type to full canonical type. This is required for codegen and other clang infrastructure to work property on HLSL resource types. Fixes #95952 (part 2/2)
2024-10-11Revert "[clang] CWG2398: improve overload resolution backwards compat (#107350)"Mikhail Goncharov1-2/+1
See discussion in https://github.com/llvm/llvm-project/pull/111711 This reverts commit 224519b08945637a85e9798c78286643288f7b77.
2024-10-11Revert "[clang] Implement TTP P0522 pack matching for deduced function ↵Mikhail Goncharov1-1/+0
template calls. (#111457)" See discussion in https://github.com/llvm/llvm-project/pull/111711 This reverts commit 4dadf42c1a74dd4e37db9ffd6fbb3027f59751a7.
2024-10-10[clang] Implement TTP P0522 pack matching for deduced function template ↵Matheus Izvekov1-0/+1
calls. (#111457) Clang previously missed implementing P0522 pack matching for deduced function template calls. Fixes #111363
2024-10-10[clang] CWG2398: improve overload resolution backwards compat (#107350)Matheus Izvekov1-1/+2
With this change, we discriminate if the primary template and which partial specializations would have participated in overload resolution prior to P0522 changes. We collect those in an initial set. If this set is not empty, or the primary template would have matched, we proceed with this set as the candidates for overload resolution. Otherwise, we build a new overload set with everything else, and proceed as usual.
2024-09-24[clang] fix assert in ADL finding entity in the implicit global module (#109882)Matheus Izvekov1-2/+3
This adds to the assert the implicit global module case as in module purview. Fixes #109879
2024-09-22[Clang] Add __builtin_common_type (#99473)Nikolas Klauser1-1/+6
This implements the logic of the `common_type` base template as a builtin alias. If there should be no `type` member, an empty class is returned. Otherwise a specialization of a `type_identity`-like class is returned. The base template (i.e. `std::common_type`) as well as the empty class and `type_identity`-like struct are given as arguments to the builtin.
2024-09-19[clang] Don't call raw_string_ostream::flush() (NFC)Youngsuk Kim1-1/+0
Don't call raw_string_ostream::flush(), which is essentially a no-op. As specified in the docs, raw_string_ostream is always unbuffered
2024-09-03[Clang] Fix handling of placeholder variables name in init captures (#107055)cor3ntin1-1/+1
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-07-15[Clang][AST] Move NamespaceDecl bits to DeclContext (#98567)Krystian Stasiowski1-1/+1
Currently, `NamespaceDecl` has a member `AnonOrFirstNamespaceAndFlags` which stores a few pieces of data: - a bit indicating whether the namespace was declared `inline`, and - a bit indicating whether the namespace was declared as a _nested-namespace-definition_, and - a pointer a `NamespaceDecl` that either stores: - a pointer to the first declaration of that namespace if the declaration is no the first declaration, or - a pointer to the unnamed namespace that inhabits the namespace otherwise. `Redeclarable` already stores a pointer to the first declaration of an entity, so it's unnecessary to store this in `NamespaceDecl`. `DeclContext` has 8 bytes in which various bitfields can be stored for a declaration, so it's not necessary to store these in `NamespaceDecl` either. We only need to store a pointer to the unnamed namespace that inhabits the first declaration of a namespace. This patch moves the two bits currently stored in `NamespaceDecl` to `DeclContext`, and only stores a pointer to the unnamed namespace that inhabits a namespace in the first declaration of that namespace. Since `getOriginalNamespace` always returns the same `NamespaceDecl` as `getFirstDecl`, this function is removed to avoid confusion.
2024-07-08[C2y] Remove support for _Imaginary (#97436)Aaron Ballman1-1/+4
WG14 N3274 removed _Imaginary from Annex G. Clang has never fully supported Annex G or _Imaginary, so removal is pretty trivial for us. Note, we are keeping _Imaginary as a keyword so that we get better diagnostic behavior. This is still conforming because _I makes it a reserved identifier, so it's not available for users to use as an identifier anyway.
2024-07-01[clang][NFC] Move documentation of `Sema` functions into `Sema.h`Vlad Serebrennikov1-210/+0
This patch moves documentation of `Sema` functions from `.cpp` files to `Sema.h` when there was no documentation in the latter, or it can be trivially subsumed. More complicated cases when there's less trivial divergence between documentation attached to declaration and the one attached to implementation are left for a later PR that would require review. It appears that doxygen can find the documentation for a function defined out-of-line even if it's attached to an implementation, and not declaration. But other tools, e.g. clangd, are not as powerful. So this patch significantly improves autocompletion experience for (at least) clangd-based IDEs.
2024-06-28[C++20] [Modules] Don't find module for linkage for decls in globalChuanqi Xu1-1/+1
module Possibly fix https://github.com/llvm/llvm-project/issues/96693 The direct reason is that we are calculating the linkage for the declaration too early so that the linkage got calculated incorrectly. And after I look into the problem, I found it is completely not necessary to calculate the linkage there. It is for ModulesTS. So I simply removes that legacy experimental code and fix the issue.
2024-06-24[NFC] [Modules] Extract the logic to decide whether the module units belongs ↵Chuanqi Xu1-23/+27
to the same module This patch extracts the logci to decide how we decide the module units belongs to the same module into a member function of ASTContext. This is helpful to refactor the implementation in the future.
2024-05-28[clang][Sema] Don't emit 'declared here' note for builtin functions with no ↵Youngsuk Kim1-0/+10
decl in source (#93394) Fixes #93369 --------- Co-authored-by: Timm Baeder <tbaeder@redhat.com> Co-authored-by: S. B. Tam <cpplearner@outlook.com>
2024-05-22[clang] Introduce `SemaRISCV` (#92682)Vlad Serebrennikov1-5/+6
This patch moves `Sema` functions that are specific for RISC-V into the new `SemaRISCV` class. This continues previous efforts to split `Sema` up. Additional context can be found in https://github.com/llvm/llvm-project/pull/84184. This PR is somewhat different from previous PRs on this topic: 1. Splitting out target-specific functions wasn't previously discussed. It felt quite natural to do, though. 2. I had to make some static function in `SemaChecking.cpp` member functions of `Sema` in order to use them in `SemaRISCV`. 3. I dropped "RISCV" from identifiers, but decided to leave "RVV" (RISC-V "V" vector extensions) intact. I think it's an idiomatic abbreviation at this point, but I'm open to input from contributors in that area. 4. I repurposed `SemaRISCVVectorLookup.cpp` for `SemaRISCV`. I think this was a successful experiment, which both helps the goal of splitting `Sema` up, and shows a way to approach `SemaChecking.cpp`, which I wasn't sure how to approach before. As we move more target-specific function out of there, we'll gradually make the checking "framework" inside `SemaChecking.cpp` public, which is currently a whole bunch of static functions. This would enable us to move more functions outside of `SemaChecking.cpp`.
2024-05-20[Clang][Sema] Don't build CXXDependentScopeMemberExprs for potentially ↵Krystian Stasiowski1-3/+6
implicit class member access expressions (#92318) According to [expr.prim.id.general] p2: > If an _id-expression_ `E` denotes a non-static non-type member of some class `C` at a point where the current class is `X` and > - `E` is potentially evaluated or `C` is `X` or a base class of `X`, and > - `E` is not the _id-expression_ of a class member access expression, and > - if `E` is a _qualified-id_, `E` is not the un-parenthesized operand of the unary `&` operator, > > the _id-expression_ is transformed into a class member access expression using `(*this)` as the object expression. Consider the following: ``` struct A { void f0(); template<typename T> void f1(); }; template<typename T> struct B : T { auto g0() -> decltype(T::f0()); // ok auto g1() -> decltype(T::template f1<int>()); // error: call to non-static member function without an object argument }; template struct B<A>; ``` Clang incorrectly rejects the call to `f1` in the _trailing-return-type_ of `g1`. Furthermore, the following snippet results in a crash during codegen: ``` struct A { void f(); }; template<typename T> struct B : T { template<typename U> static void g(); template<> void g<int>() { return T::f(); // crash here } }; template struct B<A>; ``` This happens because we unconditionally build a `CXXDependentScopeMemberExpr` (with an implicit object expression) for `T::f` when parsing the template definition, even though we don't know whether `g` is an implicit object member function yet. This patch fixes these issues by instead building `DependentScopeDeclRefExpr`s for such expressions, and only transforming them into implicit class member access expressions during instantiation. Since we implemented the MS "unqualified lookup into dependent bases" extension by building an implicit class member access (and relying on the first component name of the _nested-name-specifier_ to be looked up in the context of the object expression during instantiation), we instead pre-append a fake _nested-name-specifier_ that refers to the injected-class-name of the enclosing class. This patch also refactors `Sema::BuildQualifiedDeclarationNameExpr` and `Sema::BuildQualifiedTemplateIdExpr`, streamlining their implementation and removing any redundant checks.
2024-05-13[clang] Introduce `SemaObjC` (#89086)Vlad Serebrennikov1-9/+0
This is continuation of efforts to split `Sema` up, following the example of OpenMP, OpenACC, etc. Context can be found in https://github.com/llvm/llvm-project/pull/82217 and https://github.com/llvm/llvm-project/pull/84184. I split formatting changes into a separate commit to help reviewing the actual changes.
2024-05-09[Clang][Sema] Revert changes to operator= lookup in templated classes from ↵Krystian Stasiowski1-34/+17
#91498, #90999, and #90152 (#91620) This reverts changes in #91498, #90999, and #90152 which make `operator=` dependent whenever the current class is templated.
2024-05-08[Clang][Sema] Fix lookup of dependent operator= outside of complete-class ↵Krystian Stasiowski1-15/+20
contexts (#91498) Fixes a crash caused by #90152.