aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/Comment.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-09[clang] Improve nested name specifier AST representation (#147835)Matheus Izvekov1-2/+0
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-07[Clang] accept @tparam on variable template partial specializations (#147219)Oleksandr T.1-0/+7
Fixes #144775 --- This patch addresses a false-positive `-Wdocumentation` warning on `@tparam` comments attached to _variable template partial specializations_
2024-10-24[clang] Use {} instead of std::nullopt to initialize empty ArrayRef (#109399)Jay Foad1-1/+1
Follow up to #109133.
2023-11-06[clang][NFC] Refactor `ParamCommandComment::PassDirection`Vlad Serebrennikov1-4/+5
This patch converts `ParamCommandComment::PassDirection` to a scoped enum at namespace scope, making it eligible for forward declaring. This is useful for e.g. annotating bit-fields with `preferred_type`.
2023-11-06[clang][NFC] Refactor `Comment::CommentKind`Vlad Serebrennikov1-9/+12
This patch converts `Comment::CommentKind` into a scoped enum at namespace scope, making it eligible for forward declaring. This is useful for e.g. annotating bit-fields with `preferred_type`.
2022-12-03[AST] Use std::nullopt instead of None (NFC)Kazu Hirata1-1/+1
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-07[clang][NFC] Use c++17 style variable type traitsNathan James1-1/+1
This was done as a test for D137302 and it makes sense to push these changes Reviewed By: shafik Differential Revision: https://reviews.llvm.org/D137491
2022-08-08[clang] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song1-1/+1
With C++17 there is no Clang pedantic warning or MSVC C5051. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D131346
2021-12-11Use llvm::any_of and llvm::all_of (NFC)Kazu Hirata1-6/+1
2021-11-12Comment AST: Recognize function-like objects via return type (NFC)Aaron Puchert1-1/+4
Instead of pretending that function pointer type aliases or variables are functions, and thereby losing the information that they are type aliases or variables, respectively, we use the existence of a return type in the DeclInfo to signify a "function-like" object. That seems pretty natural, since it's also the return type (or parameter list) from the DeclInfo that we compare the documentation with. Addresses a concern voiced in D111264#3115104. Reviewed By: gribozavr2 Differential Revision: https://reviews.llvm.org/D113691
2021-11-12Comment AST: Find out if function is variadic in DeclInfo::fillAaron Puchert1-0/+6
Then we don't have to look into the declaration again. Also it's only natural to collect this information alongside parameters and return type, as it's also just a parameter in some sense. Reviewed By: gribozavr2 Differential Revision: https://reviews.llvm.org/D113690
2021-11-09Comment AST: Add support for variable templatesAaron Puchert1-0/+15
We treat them as variables of course, though if they have function pointer type we treat them as functions, i.e. allow parameter and return value specifications. Just like VarDecls. Reviewed By: gribozavr2 Differential Revision: https://reviews.llvm.org/D111266
2021-11-09Comment AST: Declare function pointer variables as functionsAaron Puchert1-2/+1
We were doing this already for type aliases, and it deduplicates the code looking through aliases and pointers to find a function type. As a side effect, this finds two warnings that we apparently missed before. Reviewed By: gribozavr2 Differential Revision: https://reviews.llvm.org/D111264
2021-11-09Comment AST: Factor out function type extraction in DeclInfo::fill (NFC)Aaron Puchert1-42/+17
Reviewed By: gribozavr2 Differential Revision: https://reviews.llvm.org/D111262
2020-01-07Fix "pointer is null" static analyzer warning. NFCI.Simon Pilgrim1-3/+3
2019-08-27[clang] Ensure that comment classes are trivially destructibleBruno Ricci1-0/+15
As in D66646, these classes are also allocated with a BumpPtrAllocator, and therefore should be trivially destructible. Differential Revision: https://reviews.llvm.org/D66722 Reviewed By: Mordante, gribozavr llvm-svn: 370041
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-07-30Remove trailing spaceFangrui Song1-1/+1
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
2017-04-26[AST] Look through attribute type locs when searching for function typeAlex Lorenz1-0/+3
loc Prior to this commit -Wdocumentation crashed when checking the @returns command for declarations whose function/block pointer type included an attribute like _Nullable. rdar://31818195 llvm-svn: 301400
2017-04-21[PR32667] -Wdocumentation should allow @param/@returns for fields/variablesAlex Lorenz1-0/+17
that have a function/block pointer type This commit improves the -Wdocumentation warning by making sure that @param and @returns commands won't trigger warnings when used for fields, variables, or properties whose type is a function/block pointer type. The function/block pointer type must be specified directly with the declaration, and when a typedef is used the warning is still emitted. In the future we might also want to handle the std::function type as well. rdar://24978538 llvm-svn: 300981
2016-08-25[Sema][Comments] Add support for TypeAliasTemplateBruno Cardoso Lopes1-0/+14
Emit proper diagnostics when -Wdocumentation is used with constructs such as: template<typename T> using fn = int(T aaa, int ccc); Previously clang wouldn't recognize the function and complain with 'comment that is not attached to a function declaration'. Differential Revision: https://reviews.llvm.org/D23860 rdar://problem/27300695 llvm-svn: 279754
2016-08-25[Sema][Comments] Factor out function type loc logic. NFCIBruno Cardoso Lopes1-64/+64
This is in prepatation for @param TypeAliasTemplate support. llvm-svn: 279691
2016-08-24[Sema][Comments] Support @param with c++ 'using' keywordBruno Cardoso Lopes1-6/+6
Give appropriate warnings with -Wdocumentation for @param comments that refer to function aliases defined with 'using'. Very similar to typedef's behavior. This does not add support for TypeAliasTemplateDecl yet. Differential Revision: https://reviews.llvm.org/D23783 rdar://problem/27300695 llvm-svn: 279662
2016-07-18[NFC] Header cleanupMehdi Amini1-2/+1
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-06-24Use more ArrayRefsDavid Majnemer1-3/+3
No functional change is intended, just a small refactoring. llvm-svn: 273647
2014-08-30Use llvm::makeArrayRef instead of explicitly calling ArrayRef constructor ↵Craig Topper1-12/+5
and mentioning the type. This works now that we have a conversion from ArrayRef<T*> to ArrayRef<const T*>. llvm-svn: 216824
2014-05-12[C++11] Use 'nullptr'. AST edition.Craig Topper1-1/+1
llvm-svn: 208517
2014-01-25Rename getResultLoc() tooAlp Toker1-2/+2
Follow up to r200082. Spotted by Dmitri llvm-svn: 200105
2014-01-25Rename getResultType() on function and method declarations to getReturnType()Alp Toker1-5/+5
A return type is the declared or deduced part of the function type specified in the declaration. A result type is the (potentially adjusted) type of the value of an expression that calls the function. Rule of thumb: * Declarations have return types and parameters. * Expressions have result types and arguments. llvm-svn: 200082
2013-12-17Documentation comment parsing: when checking if we have typedef to somethingDmitri Gribenko1-0/+5
that we consider a function for the purposes of checking \param and \returns, look through reference types. llvm-svn: 197530
2013-12-17Documentation comment parsing: allow \param and \returns on std::function,Dmitri Gribenko1-0/+26
boost::function and similar function-like objects llvm-svn: 197528
2013-12-05Add an AdjustedType sugar node for adjusting calling conventionsReid Kleckner1-0/+5
Summary: In general, this type node can be used to represent any type adjustment that occurs implicitly without losing type sugar. The immediate use of this is to adjust the calling conventions of member function pointer types without breaking template instantiation. Fixes PR17996. Reviewers: rsmith Differential Revision: http://llvm-reviews.chandlerc.com/D2332 llvm-svn: 196451
2013-09-10Add unused markings to suppress warnings.Eli Friedman1-1/+3
trunk clang is a bit more aggressive about emitting unused-declaration warnings, so adjust some AST code to match. Specifically, use LLVM_ATTRIBUTE_UNUSED for declarations which are never supposed to be referenced, and turn references to declarations which are supposed to be referenced into odr-uses. llvm-svn: 190443
2013-08-23Use CharInfo.h routines in TextComment::isWhitespaceNoCacheDmitri Gribenko1-3/+2
llvm-svn: 189115
2013-07-05[comment parsing]: Removes an unsafe API whoseFariborz Jahanian1-2/+2
use can cause crash. No test is available. It is uncovered by code browsing. // rdar://14348205 llvm-svn: 185732
2013-06-24Comment parsing: allow "\param ..." to describe variadic argumentsDmitri Gribenko1-0/+2
Original patch by Fariborz Jahanian; extended by me. Fixes rdar://14124644 llvm-svn: 184688
2013-05-05Replace ArrayRef<T>() with None, now that we have an implicit ArrayRef ↵Dmitri Gribenko1-1/+1
constructor from None Patch by Robert Wilhelm. llvm-svn: 181139
2013-02-18Replace TypeLoc llvm::cast support to be well-defined.David Blaikie1-13/+13
The TypeLoc hierarchy used the llvm::cast machinery to perform undefined behavior by casting pointers/references to TypeLoc objects to derived types and then using the derived copy constructors (or even returning pointers to derived types that actually point to the original TypeLoc object). Some context is in this thread: http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-December/056804.html Though it's spread over a few months which can be hard to read in the mail archive. llvm-svn: 175462
2013-01-14Dump comments in -ast-dump.Alexander Kornienko1-14/+0
http://llvm-reviews.chandlerc.com/D269 "Added dumping of declaration comments in ASTDumper. This required moving the comment dumping code from CommentDumper so that the indentation is correct." Patch by Philip Craig! llvm-svn: 172409
2012-10-19Remove const_casts by propagating constness down to called functions.Dmitri Gribenko1-3/+3
llvm-svn: 166287
2012-10-18[doc parsing] use getParamName to access parameter Fariborz Jahanian1-13/+11
for current(rewritten) comment and getParamNameAsWritten to access param name coming with \param marker. llvm-svn: 166231
2012-10-17[Doc parsing]: This patch adds <Declaration> tag to Fariborz Jahanian1-1/+1
XML comment for declarations which pretty-prints declaration. I had to XFAIL one test annotate-comments.cpp. This test is currently unmaintainable as written. Dmitri G., can you see what we can do about this test. We should change this test such that adding a new tag does not wreck havoc to the test. llvm-svn: 166130
2012-10-15Fixes location of overriding declaration with no commentFariborz Jahanian1-1/+2
of their own. llvm-svn: 165972
2012-10-15structured document comment: patch to provide comment for overriding functionFariborz Jahanian1-0/+15
template when comment is comming from overridden declaration. // rdar://12378793 llvm-svn: 165953
2012-10-11search for overridden methods with comment when overriding methodFariborz Jahanian1-0/+6
has none of its own. Factor in Doug's comments. // rdar://12378793 llvm-svn: 165771
2012-10-10[Doc parsing] This patch searches overridden objc/c++Fariborz Jahanian1-10/+10
methods looking for documentation on a particular base class inherited by any method that overrides the base class. In case of redeclaration, as when objc method is defined in the implementation, it also looks up for documentation in class/class extension being redeclared. llvm-svn: 165643
2012-09-15Comment parsing: don't treat typedef to a typedef to a function as aDmitri Gribenko1-8/+0
'function-like' type that can be annotated with \param. Thanks to Eli Friedman for noticing! llvm-svn: 163985
2012-09-10Comment AST: TableGen'ize all command lists in CommentCommandTraits.cpp.Dmitri Gribenko1-3/+5
Now we have a list of all commands. This is a good thing in itself, but it also enables us to easily implement typo correction for command names. With this change we have objects that contain information about each command, so it makes sense to resolve command name just once during lexing (currently we store command names as strings and do a linear search every time some property value is needed). Thus comment token and AST nodes were changed to contain a command ID -- index into a tables of builtin and registered commands. Unknown commands are registered during parsing and thus are also uniformly assigned an ID. Using an ID instead of a StringRef is also a nice memory optimization since ID is a small integer that fits into a common bitfield in Comment class. This change implies that to get any information about a command (even a command name) we need a CommandTraits object to resolve the command ID to CommandInfo*. Currently a fresh temporary CommandTraits object is created whenever it is needed since it does not have any state. But with this change it has state -- new commands can be registered, so a CommandTraits object was added to ASTContext. Also, in libclang CXComment has to be expanded to include a CXTranslationUnit so that all functions working on comment AST nodes can get a CommandTraits object. This breaks binary compatibility of CXComment APIs. Now clang_FullComment_getAsXML(CXTranslationUnit TU, CXComment CXC) doesn't need TU parameter anymore, so it was removed. This is a source-incompatible change for this C API. llvm-svn: 163540
2012-08-24Comment semantic analysis: treat function typedefs as functions so that one canDmitri Gribenko1-1/+52
use \param and \returns in documentation. Fixes PR13533. llvm-svn: 162507
2012-08-07Comment AST: DeclInfo: add a special kind for enums.Dmitri Gribenko1-0/+3
Comment XML: add a root node kind for enums. llvm-svn: 161442