summaryrefslogtreecommitdiff
path: root/clang/lib/AST/NestedNameSpecifier.cpp
AgeCommit message (Collapse)Author
2025-08-27[clang] NFC: reintroduce clang/include/clang/AST/Type.h (#155050)Matheus Izvekov
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 Izvekov
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-09[clang] Improve nested name specifier AST representation (#147835)Matheus Izvekov
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-18[Clang][AST][NFC] Introduce `NamespaceBaseDecl` (#149123)Yanzuo Liu
Add `NamespaceBaseDecl` as common base class of `NamespaceDecl` and `NamespaceAliasDecl`. This simplifies `NestedNameSpecifier` a bit. Co-authored-by: Matheus Izvekov <mizvekov@gmail.com>
2025-05-29[Clang] Optimize some `getBeginLoc` implementations (#141058)cor3ntin
The bulk of the changes are in `CallExpr` We cache Begin/End source locs in the trailing objects, in the space left by making the offset to the trailing objects static. We also set a flag to indicate that we are calling an explicit object member function, further reducing the cost of getBeginLoc. Fixes #140876
2025-04-09[clang] fix NestedNameSpecifier dependency calculation (#135067)Matheus Izvekov
A NestedNameSpecifier of TypeSpec kind can be non-dependent even if its prefix is dependent, when for example the prefix is an injected class type but the type itself is a simple alias to a non-dependent type. This issue was a bit hard to observe because if it is an alias to a class type, then we (for some unknown reason) ignored that the NNS was dependent in the first place, which wouldn't happen with an enum type. This could have been a workaround for previous dependency bugs, and is not relevant anymore for any of the test cases in the tree, so this patch also removes that. The other kinds of dependencies are still relevant. If the prefix contains an unexpanded pack, then this NNS is still unexpanded, and likewise for errors. This fixes a regression reported here: https://github.com/llvm/llvm-project/pull/133610#issuecomment-2787909829 which was introduced by https://github.com/llvm/llvm-project/pull/133610 There are no release notes since the regression was never released.
2025-04-01[clang] improved preservation of template keyword (#133610)Matheus Izvekov
2025-03-27Fix MSVC "not all control paths return a value" warning. NFC.Simon Pilgrim
2025-03-26[clang] fix deduction of member pointers with dependent named classes (#133113)Matheus Izvekov
This fixes a regression when interpreting a nested name specifier for deduction purposes in member pointers. This introduces a helper for fully translating a nested name specifier into a type. This regression was introduced here: https://github.com/llvm/llvm-project/pull/130537 and was reported here: https://github.com/llvm/llvm-project/pull/132401#issuecomment-2751489581 No release notes, since this regression was never released.
2025-03-21Reland: [clang] preserve class type sugar when taking pointer to member ↵Matheus Izvekov
(#132401) Original PR: #130537 Originally reverted due to revert of dependent commit. Relanding with no changes. This changes the MemberPointerType representation to use a NestedNameSpecifier instead of a Type to represent the base class. Since the qualifiers are always parsed as nested names, there was an impedance mismatch when converting these back and forth into types, and this led to issues in preserving sugar. The nested names are indeed a better match for these, as the differences which a QualType can represent cannot be expressed syntatically, and they represent the use case more exactly, being either dependent or referring to a CXXRecord, unqualified. This patch also makes the MemberPointerType able to represent sugar for a {up/downcast}cast conversion of the base class, although for now the underlying type is canonical, as preserving the sugar up to that point requires further work. As usual, includes a few drive-by fixes in order to make use of the improvements.
2025-03-20Revert "Reland: [clang] preserve class type sugar when taking pointer to ↵Matheus Izvekov
member" (#132280) Reverts llvm/llvm-project#132234 Needs to be reverted due to dependency. This blocks reverting another PR, see here: https://github.com/llvm/llvm-project/pull/131965#issuecomment-2741619498
2025-03-20Reland: [clang] preserve class type sugar when taking pointer to member ↵Matheus Izvekov
(#132234) Original PR: #130537 Reland after updating lldb too. This changes the MemberPointerType representation to use a NestedNameSpecifier instead of a Type to represent the base class. Since the qualifiers are always parsed as nested names, there was an impedance mismatch when converting these back and forth into types, and this led to issues in preserving sugar. The nested names are indeed a better match for these, as the differences which a QualType can represent cannot be expressed syntatically, and they represent the use case more exactly, being either dependent or referring to a CXXRecord, unqualified. This patch also makes the MemberPointerType able to represent sugar for a {up/downcast}cast conversion of the base class, although for now the underlying type is canonical, as preserving the sugar up to that point requires further work. As usual, includes a few drive-by fixes in order to make use of the improvements.
2025-03-20Revert "[clang] improve class type sugar preservation in pointers to ↵Matheus Izvekov
members" (#132215) Reverts llvm/llvm-project#130537 This missed updating lldb, which we didn't notice due to lack of pre-commit CI.
2025-03-20[clang] improve class type sugar preservation in pointers to members (#130537)Matheus Izvekov
This changes the MemberPointerType representation to use a NestedNameSpecifier instead of a Type to represent the class. Since the qualifiers are always parsed as nested names, there was an impedance mismatch when converting these back and forth into types, and this led to issues in preserving sugar. The nested names are indeed a better match for these, as the differences which a QualType can represent cannot be expressed syntactically, and it also represents the use case more exactly, being either dependent or referring to a CXXRecord, unqualified. This patch also makes the MemberPointerType able to represent sugar for a {up/downcast}cast conversion of the base class, although for now the underlying type is canonical, as preserving the sugar up to that point requires further work. As usual, includes a few drive-by fixes in order to make use of the improvements, and removing some duplications, for example CheckBaseClassAccess is deduplicated from across SemaAccess and SemaCast.
2025-03-10[clang] NNS: don't print trailing scope resolution operator in diagnostics ↵Matheus Izvekov
(#130529) This clears up the printing of a NestedNameSpecifier so a trailing '::' is not printed, unless it refers into the global scope. This fixes a bunch of diagnostics where the trailing :: was awkward. This also prints the NNS quoted consistenty. There is a drive-by improvement to error recovery, where now we print the actual type instead of `<dependent type>`. This will clear up further uses of NNS printing in further patches.
2024-11-17[AST] Remove unused includes (NFC) (#116549)Kazu Hirata
Identified with misc-include-cleaner.
2024-04-11[NFC][Clang] Improve const correctness for IdentifierInfo (#79365)Bill Wendling
The IdentifierInfo isn't typically modified. Use 'const' wherever possible.
2022-10-14Properly print unnamed TagDecl objects in diagnosticsAaron Ballman
The diagnostics engine is very smart about being passed a NamedDecl to print as part of a diagnostic; it gets the "right" form of the name, quotes it properly, etc. However, the result of using an unnamed tag declaration was to print '' instead of anything useful. This patch causes us to print the same information we'd have gotten if we had printed the type of the declaration rather than the name of it, as that's the most relevant information we can display. Differential Revision: https://reviews.llvm.org/D134813
2022-08-08[clang] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song
With C++17 there is no Clang pedantic warning or MSVC C5051. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D131346
2021-09-02Fully qualify template template parameters when printingDavid Blaikie
I discovered this quirk when working on some DWARF - AST printing prints type template parameters fully qualified, but printed template template parameters the way they were written syntactically, or wholely unqualified - instead, we should print them consistently with the way we print type template parameters: fully qualified. The one place this got weird was for partial specializations like in ast-print-temp-class.cpp - hence the need for checking for TemplateNameDependenceScope::DependentInstantiation template template parameters. (not 100% sure that's the right solution to that, though - open to ideas) Differential Revision: https://reviews.llvm.org/D108794
2021-07-21[clang] Introduce SourceLocation::[U]IntTy typedefs.Simon Tatham
This is part of a patch series working towards the ability to make SourceLocation into a 64-bit type to handle larger translation units. NFC: this patch introduces typedefs for the integer type used by SourceLocation and makes all the boring changes to use the typedefs everywhere, but for the moment, they are unconditionally defined to uint32_t. Patch originally by Mikhail Maltsev. Reviewed By: tmatheson Differential Revision: https://reviews.llvm.org/D105492
2021-05-12Add type information to integral template argument if required.Pratyush Das
Non-comprehensive list of cases: * Dumping template arguments; * Corresponding parameter contains a deduced type; * Template arguments are for a DeclRefExpr that hadMultipleCandidates() Type information is added in the form of prefixes (u8, u, U, L), suffixes (U, L, UL, LL, ULL) or explicit casts to printed integral template argument, if MSVC codeview mode is disabled. Differential revision: https://reviews.llvm.org/D77598
2020-06-30[AST][RecoveryExpr] Avoid spurious 'missing typename' diagnostic when the ↵Haojian Wu
NNS contains errors. Differential Revision: https://reviews.llvm.org/D82631
2020-05-02Use realloc for NestedNameSpecifierLocBuilderBenjamin Kramer
These allocations are so tiny that the buffer can be grown in-place most of the time.
2020-04-17[clang-tidy] modernize-use-using: Fix broken fixit with 'template' keywordMatthias Gehre
Summary: Before this PR, `modernize-use-using` would transform the typedef in ``` template <typename a> class TemplateKeyword { typedef typename a::template f<> e; typedef typename a::template f<>::d e2; }; ``` into ``` template <typename a> class TemplateKeyword { using d = typename a::b<>; using d2 = typename a::template a::b<>::c; }; ``` The first one is missing the `template` keyword, the second one has an extra `a::` scope. Both result in compilation errors. Reviewers: aaron.ballman, alexfh, hokein, njames93 Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D78139
2020-03-16[AST] rename DependencyFlags.h => DependenceFlags.h, NFCHaojian Wu
We forgot to fix in the previous patch.
2020-03-04[AST] Refactor propagation of dependency bits. NFCIlya Biryukov
Summary: This changes introduces an enum to represent dependencies as a bitmask and extract common patterns from code that computes dependency bits into helper functions. Reviewers: rsmith, martong, shafik, ilya-biryukov, hokein Subscribers: hokein, sammccall, Mordante, riccibruno, merge_guards_bot, rnkovacs, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71920
2020-02-13Don't call memcpy(p, 0, 0).Richard Smith
Found by UBSan, reported by Kostya. Thanks!
2020-02-07PR12350: Handle remaining cases permitted by CWG DR 244.Richard Smith
Also add extension warnings for the cases that are disallowed by the current rules for destructor name lookup, refactor and simplify the lookup code, and improve the diagnostic quality when lookup fails. The special case we previously supported for converting p->N::S<int>::~S() from naming a class template into naming a specialization thereof is subsumed by a more general rule here (which is also consistent with Clang's historical behavior and that of other compilers): if we can't find a suitable S in N, also look in N::S<int>. The extension warnings are off by default, except for a warning when lookup for p->N::S::~T() looks for T in scope instead of in N (or N::S). That seems sufficiently heinous to warn on by default, especially since we can't support it for a dependent nested-name-specifier.
2020-01-14Fix "null pointer passed to nonnull argument" clang static analyzer ↵Simon Pilgrim
warnings. NFCI. Assert that the memcpy arguments are valid.
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
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
2019-01-07NFC: Replace asserts with if() in SourceLocation accessorsStephen Kelly
Summary: Nowhere else in the AST classes assert on these kinds of accessors. This way, we can call the accessors and check the validity of the result instead of externally duplicating the conditions. This generality will make it possible to introspect instances for source locations: http://ec2-18-191-7-3.us-east-2.compute.amazonaws.com:10240/z/iiaWhw Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D56354 llvm-svn: 350573
2018-12-04[WIP][Sema] Improve static_assert diagnostics for type traits.Clement Courbet
Summary: In our codebase, `static_assert(std::some_type_trait<Ts...>::value, "msg")` (where `some_type_trait` is an std type_trait and `Ts...` is the appropriate template parameters) account for 11.2% of the `static_assert`s. In these cases, the `Ts` are typically not spelled out explicitly, e.g. `static_assert(std::is_same<SomeT::TypeT, typename SomeDependentT::value_type>::value, "message");` The diagnostic when the assert fails is typically not very useful, e.g. `static_assert failed due to requirement 'std::is_same<SomeT::TypeT, typename SomeDependentT::value_type>::value' "message"` This change makes the diagnostic spell out the types explicitly , e.g. `static_assert failed due to requirement 'std::is_same<int, float>::value' "message"` See tests for more examples. After this is submitted, I intend to handle `static_assert(!std::some_type_trait<Ts...>::value, "msg")`, which is another 6.6% of static_asserts. Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D54903 llvm-svn: 348239
2018-10-04[NestedNameSpecifier] Add missing stream-specific dump methodsStephen Kelly
Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52870 llvm-svn: 343807
2018-09-10[AST] Fix a crash on invalid.Erik Pilkington
Problem was that we were appending to the source location info buffer in the copy assignment operator (instead of overwriting). rdar://42746401 llvm-svn: 341869
2018-07-30Remove trailing spaceFangrui Song
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
2018-05-09Remove \brief commands from doxygen comments.Adrian Prantl
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-02-21Clean up use of C allocation functionsSerge Pavlov
If the value returned by `malloc`, `calloc` or `realloc` is not checked for null pointer, this change replaces them for `safe_malloc`, `safe_calloc` or `safe_realloc`, which are defined in the namespace `llvm`. These function report fatal error on out of memory. In the plain C files, assertion statements are added to ensure that memory is successfully allocated. The aim of this change is to get better diagnostics of OOM on Windows. Differential Revision: https://reviews.llvm.org/D43017 llvm-svn: 325661
2017-11-28Refactor functions PrintTemplateArgumentListSerge Pavlov
These functions were defined as static members of TemplateSpecializationType. Now they are moved to namespace level. Previously there were different implementations for lists containing TemplateArgument and TemplateArgumentLoc, now these implementations share the same code. This change is a result of refactoring patch D40508. NFC. llvm-svn: 319178
2017-11-21[AST] Fix some Clang-tidy modernize and Include What You Use warnings; other ↵Eugene Zelenko
minor fixes (NFC). llvm-svn: 318813
2017-06-03Added LLVM_FALLTHROUGH to address warning: this statement may fall through. NFC.Galina Kistanova
llvm-svn: 304650
2016-10-20Retire llvm::alignOf in favor of C++11 alignof.Benjamin Kramer
No functionality change intended. llvm-svn: 284730
2016-10-08Un-tabify source files, NFC.Yaron Keren
llvm-svn: 283657
2016-07-07[AST] Use ArrayRef in more interfacesDavid Majnemer
ArrayRef is a little better than passing around a pointer/length pair. No functional change is intended. llvm-svn: 274732
2016-06-28P0136R1, DR1573, DR1645, DR1715, DR1736, DR1903, DR1941, DR1959, DR1991:Richard Smith
Replace inheriting constructors implementation with new approach, voted into C++ last year as a DR against C++11. Instead of synthesizing a set of derived class constructors for each inherited base class constructor, we make the constructors of the base class visible to constructor lookup in the derived class, using the normal rules for using-declarations. For constructors, UsingShadowDecl now has a ConstructorUsingShadowDecl derived class that tracks the requisite additional information. We create shadow constructors (not found by name lookup) in the derived class to model the actual initialization, and have a new expression node, CXXInheritedCtorInitExpr, to model the initialization of a base class from such a constructor. (This initialization is special because it performs real perfect forwarding of arguments.) In cases where argument forwarding is not possible (for inalloca calls, variadic calls, and calls with callee parameter cleanup), the shadow inheriting constructor is not emitted and instead we directly emit the initialization code into the caller of the inherited constructor. Note that this new model is not perfectly compatible with the old model in some corner cases. In particular: * if B inherits a private constructor from A, and C uses that constructor to construct a B, then we previously required that A befriends B and B befriends C, but the new rules require A to befriend C directly, and * if a derived class has its own constructors (and so its implicit default constructor is suppressed), it may still inherit a default constructor from a base class llvm-svn: 274049
2016-01-29Annotate dump() methods with LLVM_DUMP_METHOD, addressing Richard Smith ↵Yaron Keren
r259192 post commit comment. llvm-svn: 259232
2015-12-27Constify NestedNameSpecifier::dump and add a no-argument dump function ↵Yaron Keren
suitable for calling from a debugger. llvm-svn: 256472
2015-08-04[UB] Fix the two ways that we would try to memcpy from a null buffer inChandler Carruth
the nested name specifier code. First, skip the entire thing when the input is empty. Next, handle the case where we started off with a null buffer and a zero capacity to skip copying and freeing. This was found with UBSan. llvm-svn: 243946
2015-06-22Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko
llvm-svn: 240353
2015-06-22Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko
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