aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/ASTMatchers/Dynamic
AgeCommit message (Collapse)AuthorFilesLines
2025-09-12[clang] AST: remove DependentTemplateSpecializationType (#158109)Matheus Izvekov1-1/+0
A DependentTemplateSpecializationType (DTST) is basically just a TemplateSpecializationType (TST) with a hardcoded DependentTemplateName (DTN) as its TemplateName. This removes the DTST and replaces all uses of it with a TST, removing a lot of duplication in the implementation. Technically the hardcoded DTN is an optimization for a most common case, but the TST implementation is in better shape overall and with other optimizations, so this patch ends up being an overall performance positive: <img width="1465" height="38" alt="image" src="https://github.com/user-attachments/assets/084b0694-2839-427a-b664-eff400f780b5" /> A DTST also didn't allow a template name representing a DTN that was substituted, such as from an alias template, while the TST does allow it by the simple fact it can hold an arbitrary TemplateName, so this patch also increases the amount of sugar retained, while still being faster overall. Example (from included test case): ```C++ template<template<class> class TT> using T1 = TT<int>; template<class T> using T2 = T1<T::template X>; ``` Here we can now represent in the AST that `TT` was substituted for the dependent template name `T::template X`.
2025-08-19[clang-tidy] fix misc-unconventional-assign-operator entity match (#154430)Matheus Izvekov1-0/+1
Makes sure UnconventionalAssignOperatorCheck checks if the types reference the same entity, not the exact declaration. This adds a new matcher to support this check. This fixes a regression introduced by #147835. Since this regression was never released, there are no release notes. Fixes #153770
2025-08-09[clang] Improve nested name specifier AST representation (#147835)Matheus Izvekov1-4/+1
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-15[clang-query] Allow for trailing comma in matchers (#148018)Remy Farley1-0/+10
Allow AST matches in clang-query to have a trailing comma at the end of matcher arguments. Makes it nicer to work with queries that span multiple lines. So, for example, the following is possible: ```clang-query match namedDecl( isExpansionInMainFile(), anyOf( varDecl().bind("var"), functionDecl().bind("func"), # enumDecl().bind("enum"), ), ) ```
2025-06-26[ASTMatchers] Migrate away from ArrayRef(std::nullopt) (NFC) (#145840)Kazu Hirata1-1/+1
ArrayRef has a constructor that accepts std::nullopt. This constructor dates back to the days when we still had llvm::Optional. Since the use of std::nullopt outside the context of std::optional is kind of abuse and not intuitive to new comers, I would like to move away from the constructor and eventually remove it. This patch migrates away from std::nullopt in favor of ArrayRef<T>(). Note that {} would be ambiguous for perfect forwarding to work here.
2025-06-04[ASTMatchers] Remove unused includes (NFC) (#142407)Kazu Hirata3-4/+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-01-05[Clang][ASTMatcher] Add a matcher for the name of a ↵Amr Hesham1-0/+1
DependentScopeDeclRefExpr (#121656) Add the `hasDependentName` matcher to match the name of `DependentScopeDeclRefExpr` Fixes https://github.com/llvm/llvm-project/issues/121610
2025-01-03[Clang][ASTMatcher] Add `dependentTemplateSpecializationType` matcher (#121435)kefan cao1-0/+1
Fixes https://github.com/llvm/llvm-project/issues/121307
2024-12-29[Clang][ASTMatcher] Add `dependentNameType` AST matcher (#121263)Amr Hesham1-0/+1
Fixes: https://github.com/llvm/llvm-project/issues/121240
2024-12-27[Clang][ASTMatcher] Add `dependentScopeDeclRefExpr` matcher (#120996)Amr Hesham1-0/+1
Fixes https://github.com/llvm/llvm-project/issues/120937
2024-12-04[ast matcher] add `ExportDecl` in dynamically matchers (#118258)Congcong Cai1-0/+1
2024-09-14[clang] Nits on uses of raw_string_ostream (NFC)JOE19941-1/+1
* Don't call raw_string_ostream::flush(), which is essentially a no-op. * Strip unneeded calls to raw_string_ostream::str(), to avoid extra indirection.
2024-05-11[clang] Use StringRef::operator== instead of StringRef::equals (NFC) (#91844)Kazu Hirata1-2/+2
I'm planning to remove StringRef::equals in favor of StringRef::operator==. - StringRef::operator==/!= outnumber StringRef::equals by a factor of 24 under clang/ in terms of their usage. - The elimination of StringRef::equals brings StringRef closer to std::string_view, which has operator== but not equals. - S == "foo" is more readable than S.equals("foo"), especially for !Long.Expression.equals("str") vs Long.Expression != "str".
2024-04-20[clang] Marshallers.h - use move semantics for 'NodeKinds' and update ↵Amila Senadheera1-2/+2
possible callers to use it (#87273) Fixes: https://github.com/llvm/llvm-project/issues/87248 Signed-off-by: amila <amila.15@cse.mrt.ac.lk>
2024-03-08[clang][ASTMatcher] Add matchers for isExplicitObjectMemberFunction() (#84446)Balazs Benics1-0/+1
Note that this patch will be necessary to fix `forEachArgumentWithParam()` and `forEachArgumentWithParamType()` matchers for deducing "this"; which is my true motivation. There the bug is that with explicit obj params, one should not adjust the number of arguments in presence of `CXXMethodDecls`, and this causes a mismatch there mapping the argument to the wrong param. But, I'll come back there once we have this matcher.
2024-01-16[clang][ASTMatcher] Add matchers for CXXFoldExpr (#71245)Julian Schmidt1-0/+7
Adds support for the following matchers related to `CXXFoldExpr`: `cxxFoldExpr`, `callee`, `hasInit`, `hasPattern`, `isRightFold`, `isLeftFold`, `isUnaryFold`, `isBinaryFold`, `hasOperator`, `hasLHS`, `hasRHS`.
2023-12-27[clang] Use StringRef::ltrim (NFC)Kazu Hirata1-4/+2
2023-12-13[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)Kazu Hirata1-3/+3
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-08-16[clang][ASTMatcher] Add matcher for 'MacroQualifiedType'dingfei1-0/+1
Add matcher for 'MacroQualifiedType' Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D157777
2023-08-07[clang][ASTMatcher] Add Matcher 'convertVectorExpr'dingfei1-0/+1
Add Matcher convertVectorExpr. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D157248
2023-08-07[clang][ASTMatcher] Add Matcher 'dependentSizedExtVectorType'dingfei1-0/+1
Add Matcher dependentSizedExtVectorType for DependentSizedExtVectorType. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D157237
2023-08-04cmake: add missing dependencies on ClangDriverOptions tablegenJon Roelofs1-0/+1
The modules build trips over this frequently because there is no textual include of the tablegen output, but the module includes it. Differential revision: https://reviews.llvm.org/D157119
2023-07-20[clang] adds `conceptDecl` as an ASTMatcherChristopher Di Bella1-0/+1
Closes #63934 Differential Revision: https://reviews.llvm.org/D155549
2023-07-20[WIP][-Wunsafe-buffer-usage] Handle lambda expressions within a method.Rashmi Mudduluru1-0/+2
Differential Revision: https://reviews.llvm.org/D150386
2023-06-25[ASTMatchers] Add argumentCountAtLeast narrowing matcherMike Crowe1-0/+1
This will be used by the modernize-use-std-print clang-tidy check and related checks later. Reviewed By: PiotrZSL Differential Revision: https://reviews.llvm.org/D153716
2023-04-23[NFC][clang] Fix static analyzer concernsManna, Soumi1-1/+1
Reported by Coverity: AUTO_CAUSES_COPY Unnecessary object copies can affect performance. 1. Inside "SemaDeclCXX.cpp" file, in <unnamed>::DiagnoseUninitializedFields(clang::Sema &, clang::CXXConstructorDecl const *): Using the auto keyword without an & causes the copy of an object of type CXXBaseSpecifier. 2. Inside "ClangAttrEmitter.cpp" file, in clang::EmitClangAttrParsedAttrImpl(llvm::RecordKeeper &, llvm::raw_ostream &): Using the auto keyword without an & causes the copy of an object of type pair. 3. Inside "Marshallers.h" file, in clang::ast_matchers::dynamic::internal::MapAnyOfBuilderDescriptor::buildMatcherCtor(clang::ast_matchers::dynamic::SourceRange, llvm::ArrayRef<clang::ast_matchers::dynamic::ParserValue>, clang::ast_matchers::dynamic::Diagnostics *): Using the auto keyword without an & causes the copy of an object of type ParserValue. 4. Inside "CGVTables.cpp" file, in clang::CodeGen::CodeGenModule::GetVCallVisibilityLevel(clang::CXXRecordDecl const *, llvm::DenseSet<clang::CXXRecordDecl const *, llvm::DenseMapInfo<clang::CXXRecordDecl const *, void>> &): Using the auto keyword without an & causes the copy of an object of type CXXBaseSpecifier. 5. Inside "ASTContext.cpp" file, in hasTemplateSpecializationInEncodedString(clang::Type const *, bool): Using the auto keyword without an & causes the copy of an object of type CXXBaseSpecifier. 6. Inside "ComputeDependence.cpp" file, in clang::computeDependence(clang::DependentScopeDeclRefExpr *): Using the auto keyword without an & causes the copy of an object of type TemplateArgumentLoc. Reviewed By: tahonermann, erichkeane Differential Revision: https://reviews.llvm.org/D148812
2023-03-15[clang] Use *{Map,Set}::contains (NFC)Kazu Hirata1-1/+1
2023-03-01[ASTMatcher] Add coroutineBodyStmt matcherChris Cotter1-0/+1
The coroutineBodyStmt matcher matches CoroutineBodyStmt AST nodes. Differential Revision: https://reviews.llvm.org/D140794
2023-01-14[clang] Remove remaining uses of llvm::Optional (NFC)Kazu Hirata4-4/+0
This patch removes several "using" declarations and #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata5-60/+58
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14[clang] Add #include <optional> (NFC)Kazu Hirata5-0/+5
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-09Move from llvm::makeArrayRef to ArrayRef deduction guides - clang/ partserge-sans-paille1-8/+4
This is a follow-up to https://reviews.llvm.org/D140896, split into several parts as it touches a lot of files. Differential Revision: https://reviews.llvm.org/D141139
2023-01-05Add isInAnonymousNamespace() to the dynamic AST matchersAaron Ballman1-0/+1
This was added to the static matchers in 125ccd3751472a0c709498f83671577ffed394a6, but the dynamic matcher was missed. This adds the dynamic matcher to the list.
2022-12-08[clang] Don't including None.h (NFC)Kazu Hirata1-1/+0
These source files no longer use None, so they do not need to include None.h. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03[clang] Use std::nullopt instead of None (NFC)Kazu Hirata4-32/+32
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-21Return None instead of Optional<T>() (NFC)Kazu Hirata2-4/+4
This patch replaces: return Optional<T>(); with: return None; to make the migration from llvm::Optional to std::optional easier. Specifically, I can deprecate None (in my source tree, that is) to identify all the instances of None that should be replaced with std::nullopt. Note that "return None" far outnumbers "return Optional<T>();". There are more than 2000 instances of "return None" in our source tree. All of the instances in this patch come from functions that return Optional<T> except Archive::findSym and ASTNodeImporter::import, where we return Expected<Optional<T>>. Note that we can construct Expected<Optional<T>> from any parameter convertible to Optional<T>, which None certainly is. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716 Differential Revision: https://reviews.llvm.org/D138464
2022-06-30Adds AST matcher for ObjCStringLiteralRashmi Mudduluru1-0/+1
Differential Revision: https://reviews.llvm.org/D128103
2022-06-25[clang] Don't use Optional::hasValue (NFC)Kazu Hirata2-4/+4
This patch replaces Optional::hasValue with the implicit cast to bool in conditionals only.
2022-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata2-4/+4
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata2-4/+4
2022-06-20Don't use Optional::hasValue (NFC)Kazu Hirata1-5/+5
2022-06-20[clang] Don't use Optional::hasValue (NFC)Kazu Hirata1-1/+1
2022-06-18[clang] Use value_or instead of getValueOr (NFC)Kazu Hirata2-2/+2
2022-05-19[Clang][[OpenMP5.1] Initial parser/sema for default(private) clauseJennifer Yu1-0/+1
This implements the default(private) clause as defined in OMP5.1 Differential Revision: https://reviews.llvm.org/D125912
2022-05-13[ASTMatchers][clang-tidy][NFC] Hoist `forEachTemplateArgument` matcher into ↵Whisperity1-0/+1
the core library Fixes the `FIXME:` related to adding `forEachTemplateArgument` to the core AST Matchers library. Reviewed By: aaron.ballman Differential Revision: http://reviews.llvm.org/D125383
2022-01-24Add `isConstinit` matcherEvgeny Shulgin1-0/+1
Support C++20 constinit variables for AST Matchers.
2022-01-20Add `isConsteval` matcherEvgeny Shulgin1-0/+1
Support C++20 consteval functions and C++2b if consteval for AST Matchers.
2022-01-11ASTMatchers: Avoid using SmallVector::set_size()Duncan P. N. Exon Smith1-2/+3
Update `variadicMatcherDescriptor` to assert on reserved capacity and to call `emplace_back()` instead of calling `set_size()` and constructing the element in-place. Differential Revision: https://reviews.llvm.org/D115379
2022-01-07[NFC] Fix endif comments to match with include guardQiu Chaofan1-1/+1
2021-12-24Remove redundant return and continue statements (NFC)Kazu Hirata1-1/+0
Identified with readability-redundant-control-flow.