aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/CXXInheritance.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-27[clang] NFC: reintroduce clang/include/clang/AST/Type.h (#155050)Matheus Izvekov1-1/+1
This reintroduces `Type.h`, having earlier been renamed to `TypeBase.h`, as a redirection to `TypeBase.h`, and redirects most users to include the former instead. This is a preparatory patch for being able to provide inline definitions for `Type` methods which would otherwise cause a circular dependency with `Decl{,CXX}.h`. Doing these operations into their own NFC patch helps the git rename detection logic work, preserving the history. This patch makes clang just a little slower to build (~0.17%), just because it makes more code indirectly include `DeclCXX.h`.
2025-08-27[clang] NFC: rename clang/include/clang/AST/Type.h to TypeBase.h (#155049)Matheus Izvekov1-1/+1
This is a preparatory patch, to be able to provide inline definitions for `Type` functions which depend on `Decl{,CXX}.h`. As the latter also depends on `Type.h`, this would not be possible without some reorganizing. Splitting this rename into its own patch allows git to track this as a rename, and preserve all git history, and not force any code reformatting. A later NFC patch will reintroduce `Type.h` as redirection to `TypeBase.h`, rewriting most places back to directly including `Type.h` instead of `TypeBase.h`, leaving only a handful of places where this is necessary. Then yet a later patch will exploit this by making more stuff inline.
2025-08-27[clang] AST: fix getAs canonicalization of leaf types (#155028)Matheus Izvekov1-1/+1
2025-08-26[clang] NFC: introduce Type::getAsEnumDecl, and cast variants for all ↵Matheus Izvekov1-6/+3
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-25[clang] NFC: change more places to use Type::getAsTagDecl and friends (#155313)Matheus Izvekov1-20/+7
This changes a bunch of places which use getAs<TagType>, including derived types, just to obtain the tag definition. This is preparation for #155028, offloading all the changes that PR used to introduce which don't depend on any new helpers.
2025-08-09[clang] Improve nested name specifier AST representation (#147835)Matheus Izvekov1-6/+10
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-05-25[AST] Remove unused includes (NFC) (#141417)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-02-24[clang][NFC] Remove CXXRecordDecl::lookupDependentName() and its helpers ↵Nathan Ridge1-53/+0
(#128392) This function has been superseded by HeuristicResolver::lookupDependentName(), which implements the same heuristics and more. Porting note for any out-of-tree callers: ``` RD->lookupDependentName(Name, Filter); ``` can be replaced with: ``` HeuristicResolver(RD->getASTContext())->lookupDependentName(Name, Filter); ```
2024-12-09[clang] Fix cast for injected types in case name lookup for dependent bases ↵Vladislav Belov1-6/+6
(#119024) An assertion failure occurs in Clang when attempting to compile such an example: ```c++ template <typename, typename, bool> struct MozPromise { class Private; private: int mMagic4 = 42; }; template <typename ResolveValueT, typename RejectValueT, bool IsExclusive> struct MozPromise<ResolveValueT, RejectValueT, IsExclusive>::Private : MozPromise { void SetTaskPriority() { mMagic4 ; } }; ``` Output: ``` clang: llvm-project/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From&) [with To = clang::RecordType; From = clang::QualType]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed. ``` The reason is in the incorrect way of casting types when searching for names in base classes ```c++ return Specifier->getType()->castAs<RecordType>()->getDecl()->getCanonicalDecl() == BaseRecord; ``` It loses injected types for template class names. This patch provides fix for such cases
2024-12-03Reapply "[clang] Fix name lookup for dependent bases" (#118003)Vladislav Belov1-6/+12
Unlike the previous version (https://github.com/llvm/llvm-project/pull/114978), this patch also removes an unnecessary assert that causes Clang to crash when compiling such tests. (clang/lib/AST/DeclCXX.cpp) https://lab.llvm.org/buildbot/#/builders/52/builds/4021 ```c++ template <class T> class X { public: X() = default; virtual ~X() = default; virtual int foo(int x, int y, T &entry) = 0; void bar() { struct Y : public X<T> { Y() : X() {} int foo(int, int, T &) override { return 42; } }; } }; ``` the assertions: ```c++ llvm-project/clang/lib/AST/DeclCXX.cpp:2508: void clang::CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *): Assertion `!MD->getParent()->isDependentContext() && "Can't add an overridden method to a class template!"' failed. ``` I believe that this assert is unnecessary and contradicts the logic of this patch. After its removal, Clang was successfully built using itself, and all tests passed.
2024-11-26Revert "[Clang] Fix name lookup for dependent bases (#114978)" (#117727)Anton Sidorenko1-12/+6
This reverts commit 486644723038555a224fd09d462bb5099e64809e as requested by the commit author. Buildbots fail: * https://lab.llvm.org/buildbot/#/builders/164/builds/4945 * https://lab.llvm.org/buildbot/#/builders/52/builds/4021
2024-11-26[Clang] Fix name lookup for dependent bases (#114978)Vladislav Belov1-6/+12
Currently the following example is a compilation failure: ```cpp template<typename T> struct A { typedef int M; struct B { typedef void M; struct C; }; }; template<typename T> struct A<T>::B::C : A<T> { M m; // void or int ? }; ``` According to the point 13.8.3.2 ``` A dependent base class is a base class that is a dependent type and is not the current instantiation. Note 2 : A base class can be the current instantiation in the case of a nested class naming an enclosing class as a base. ``` The base class `A` is the current instantiation, because `C` is a nested class for an enclosing class `A<T>`, it's is the not-dependent base class and we need to search the names through its scope. This patch makes this example compile
2024-11-17[AST] Remove unused includes (NFC) (#116549)Kazu Hirata1-2/+1
Identified with misc-include-cleaner.
2024-10-07[AST] Avoid repeated hash lookups (NFC) (#111327)Kazu Hirata1-5/+3
Here I'm splitting up the existing "if" statement into two. Mixing hasDefinition() and insert() in one "if" condition would be extremely confusing as hasDefinition() doesn't change anything while insert() does.
2023-02-23Revert "[clang] Add the check of membership for the issue #58674 and improve ↵Alexander Kornienko1-16/+15
the lookup process" The commit causes clang to crash. See https://reviews.llvm.org/D143840#4147234 This reverts commit 8498ba6c2860c838183f9951b63df26ab5f02265.
2023-02-22[clang] Add the check of membership for the issue #58674 and improve the ↵Liming Liu1-15/+16
lookup process This patch includes the commit 01adf96ebc86 and a fix of unhandled declaration references. When looking up base classes, Clang first checks whether a base class is a template and takes the specialized template based on it. However, the base class might be instantiated, and the above behavior can lose information. This patch fixes the problem by first checking whether a base class is a record declaration, so the instantiated one will be taken. Differential Revision: https://reviews.llvm.org/D143840
2023-01-29Revert commit 01adf96ebc86 because it caused "Unhandled DeclRefExpr" errors.Liming Liu1-6/+4
2023-01-29[clang] Add the check of membership in decltype for the issue #58674Liming Liu1-5/+8
D137531 had once fixed the issue. However, it caused a crash during compiling llvm/unittests/IR/PatternMatch.cpp in stage-2. The reason is the predicator isDerivedFrom does not consider independent types if the derived type is dependent. This patch improves D137531 by adding an option to make isDerivedFrom consider independent types. Differential Revision: https://reviews.llvm.org/D142437
2022-09-17[clang] Don't include SetVector.h (NFC)Kazu Hirata1-1/+0
2021-10-17[clang] Use llvm::erase_if (NFC)Kazu Hirata1-3/+1
2021-10-12[AST, CodeGen, Driver] Use llvm::is_contained (NFC)Kazu Hirata1-1/+1
2021-03-17Make iteration over the DeclContext::lookup_result safe.Vassil Vassilev1-6/+7
The idiom: ``` DeclContext::lookup_result R = DeclContext::lookup(Name); for (auto *D : R) {...} ``` is not safe when in the loop body we trigger deserialization from an AST file. The deserialization can insert new declarations in the StoredDeclsList whose underlying type is a vector. When the vector decides to reallocate its storage the pointer we hold becomes invalid. This patch replaces a SmallVector with an singly-linked list. The current approach stores a SmallVector<NamedDecl*, 4> which is around 8 pointers. The linked list is 3, 5, or 7. We do better in terms of memory usage for small cases (and worse in terms of locality -- the linked list entries won't be near each other, but will be near their corresponding declarations, and we were going to fetch those memory pages anyway). For larger cases: the vector uses a doubling strategy for reallocation, so will generally be between half-full and full. Let's say it's 75% full on average, so there's N * 4/3 + 4 pointers' worth of space allocated currently and will be 2N pointers with the linked list. So we break even when there are N=6 entries and slightly lose in terms of memory usage after that. We suspect that's still a win on average. Thanks to @rsmith! Differential revision: https://reviews.llvm.org/D91524
2020-12-01Remove CXXBasePaths::found_decls and simplify and modernize its onlyRichard Smith1-23/+0
caller. This function did not satisfy its documented contract: it only considered the first lookup result on each base path, not all lookup results. It also performed unnecessary memory allocations. This change results in a minor change to our representation: we now include overridden methods that are found by any derived-to-base path (not involving another override) in the list of overridden methods for a function, rather than filtering out functions from bases that are both direct virtual bases and indirect virtual bases for which the indirect virtual base path contains another override for the function. (That filtering rule is part of the class-scope name lookup rules, and doesn't really have much to do with enumerating overridden methods.) The users of the list of overridden methods do not appear to rely on this filtering having happened, and it's simpler to not do it.
2020-11-25Refactor and simplify class scope name lookup.Richard Smith1-92/+35
This is partly in preparation for an upcoming change that can change the order in which DeclContext lookup results are presented. In passing, fix some obvious errors where name lookup's notion of a "static member function" missed static member function templates, and where its notion of "same set of declarations" was confused by the same declarations appearing in a different order.
2020-02-29Remove unused parameter from CXXRecordDecl::forallBases [NFC]Aaron Puchert1-17/+7
Summary: Apparently all users of the function were fine with short-circuiting and none cared to override the default argument. Reviewers: aaron.ballman, rsmith Reviewed By: aaron.ballman Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D75319
2020-01-31Fix wrong devirtualization when the final overrider in one base classRichard Smith1-0/+2
overrides the final overrider in a different base class.
2019-08-14[Clang] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere1-1/+1
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368942
2019-03-31Range-style std::find{,_if} -> llvm::find{,_if}. NFCFangrui Song1-2/+1
llvm-svn: 357359
2019-02-01[OpenMP 5.0] Parsing/sema support for "omp declare mapper" directive.Michael Kruse1-0/+15
This patch implements parsing and sema for "omp declare mapper" directive. User defined mapper, i.e., declare mapper directive, is a new feature in OpenMP 5.0. It is introduced to extend existing map clauses for the purpose of simplifying the copy of complex data structures between host and device (i.e., deep copy). An example is shown below: struct S { int len; int *d; }; #pragma omp declare mapper(struct S s) map(s, s.d[0:s.len]) // Memory region that d points to is also mapped using this mapper. Contributed-by: Lingda Li <lildmh@gmail.com> Differential Revision: https://reviews.llvm.org/D56326 llvm-svn: 352906
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-12-21[AST][NFC] Remove stale comment in CXXRecordDecl::is(Virtually)DerivedFrom.Bruno Ricci1-2/+0
The "this" capture was removed in r291939. llvm-svn: 349948
2018-07-30Remove trailing spaceFangrui Song1-32/+32
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
2018-07-20[AST] Various micro-optimizations in CXXInheritanceBenjamin Kramer1-10/+10
1. Pack std::pair<bool, unsigned> in CXXBasePaths::ClassSubobjects. 2. Use a SmallPtrSet instead of a SmallDenseSet for CXXBasePaths::VisitedDependentRecords. 3. Reorder some members of CXXBasePaths to save 8 bytes. 4. Use a SmallSetVector instead of a SetVector in CXXBasePaths::ComputeDeclsFound to avoid some allocations. This speeds up an -fsyntax-only on all of Boost by approx 0.15%, mainly by speeding up CXXBasePaths::lookupInBases by approx 10%. No functional changes. Patch by Bruno Ricci! Differential Revision: https://reviews.llvm.org/D49302 llvm-svn: 337607
2018-05-09Remove \brief commands from doxygen comments.Adrian Prantl1-4/+4
This is similar to the LLVM change https://reviews.llvm.org/D46290. We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46320 llvm-svn: 331834
2018-03-01Remove redundant casts. NFCGeorge Burgess IV1-3/+2
So I wrote a clang-tidy check to lint out redundant `isa`, `cast`, and `dyn_cast`s for fun. This is a portion of what it found for clang; I plan to do similar cleanups in LLVM and other subprojects when I find time. Because of the volume of changes, I explicitly avoided making any change that wasn't highly local and obviously correct to me (e.g. we still have a number of foo(cast<Bar>(baz)) that I didn't touch, since overloading is a thing and the cast<Bar> did actually change the type -- just up the class hierarchy). I also tried to leave the types we were cast<>ing to somewhere nearby, in cases where it wasn't locally obvious what we were dealing with before. llvm-svn: 326416
2017-12-17Refactor overridden methods iteration to avoid double lookups.Benjamin Kramer1-11/+8
Convert most uses to range-for loops. No functionality change intended. llvm-svn: 320954
2017-11-30[AST] Fix some Clang-tidy modernize and Include What You Use warnings; other ↵Eugene Zelenko1-21/+36
minor fixes (NFC). llvm-svn: 319487
2017-05-18[index] Avoid one more crash caused by infinite recursion that happens whenAlex Lorenz1-2/+10
looking up a dependent name in a record that derives from itself rdar://32273000 Differential Revision: https://reviews.llvm.org/D33324 llvm-svn: 303366
2017-05-16[index] Avoid another crash that happens when looking up a dependent nameAlex Lorenz1-0/+2
in a record that has a base without a definition rdar://32224197 llvm-svn: 303192
2017-05-10[index] Index simple dependent declaration referencesAlex Lorenz1-18/+94
This commit implements basic support for indexing of dependent declaration references. Now the indexer tries to find a suitable match in the base template for a dependent member ref/decl ref/dependent type. rdar://29158210 Differential Revision: https://reviews.llvm.org/D32972 llvm-svn: 302632
2017-01-13Remove unused lambda captures. NFCMalcolm Parsons1-2/+2
llvm-svn: 291939
2016-07-18[NFC] Header cleanupMehdi Amini1-1/+0
Summary: Removed unused headers, replaced some headers with forward class declarations Patch by: Eugene <claprix@yandex.ru> Differential Revision: https://reviews.llvm.org/D20100 llvm-svn: 275882
2016-05-19Fix PR27601 by reverting [r267453] - Refactor traversal of bases in ↵Faisal Vali1-9/+6
deduction of template parameters from base This reversal is being done with r267453's author's (i.e. Richard Smith's) permission. This fixes https://llvm.org/bugs/show_bug.cgi?id=27601 Also, per Richard's request the examples from the bug report have been added to our test suite. llvm-svn: 270016
2016-04-25Refactor traversal of bases in deduction of template parameters from baseRichard Smith1-6/+9
classes of an argument to use CXXRecordDecl::forallBases. Fix forallBases to only visit each base class once. llvm-svn: 267453
2016-03-03[OPENMP 4.0] Initial support for 'omp declare reduction' construct.Alexey Bataev1-0/+15
Add parsing, sema analysis and serialization/deserialization for 'declare reduction' construct. User-defined reductions are defined as #pragma omp declare reduction( reduction-identifier : typename-list : combiner ) [initializer ( initializer-expr )] These custom reductions may be used in 'reduction' clauses of OpenMP constructs. The combiner specifies how partial results can be combined into a single value. The combiner can use the special variable identifiers omp_in and omp_out that are of the type of the variables being reduced with this reduction-identifier. Each of them will denote one of the values to be combined before executing the combiner. It is assumed that the special omp_out identifier will refer to the storage that holds the resulting combined value after executing the combiner. As the initializer-expr value of a user-defined reduction is not known a priori the initializer-clause can be used to specify one. Then the contents of the initializer-clause will be used as the initializer for private copies of reduction list items where the omp_priv identifier will refer to the storage to be initialized. The special identifier omp_orig can also appear in the initializer-clause and it will refer to the storage of the original variable to be reduced. Differential Revision: http://reviews.llvm.org/D11182 llvm-svn: 262582
2015-08-18unique_ptrify CXXBasePaths::DeclsFound & remove the then-unnecessary ↵David Blaikie1-4/+4
user-defined dtor Maybe this and the NumDeclsFound member should just be a std::vector instead. (it could be a std::dynarray, but that missed standardization) llvm-svn: 245392
2015-07-25Capture 'this' so GCC 4.7 can find a static members.Benjamin Kramer1-4/+6
llvm-svn: 243218
2015-07-25[AST] Turn the callbacks of lookupInBases and forallBases into a function_refBenjamin Kramer1-37/+34
This lets us pass functors (and lambdas) without void * tricks. On the downside we can't pass CXXRecordDecl's Find* members (which are now type safe) to lookupInBases directly, but a lambda trampoline is a small price to pay. No functionality change intended. llvm-svn: 243217
2015-06-22Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko1-1/+1
llvm-svn: 240353
2015-06-22Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko1-1/+1
The patch is generated using this command: $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \ -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \ work/llvm/tools/clang To reduce churn, not touching namespaces spanning less than 10 lines. llvm-svn: 240270