aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/CommentSema.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-09[clang] Improve nested name specifier AST representation (#147835)Matheus Izvekov1-11/+3
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-08-08[clangd] introduce doxygen parser (#150790)tcottin1-3/+4
Followup work of #140498 to continue the work on clangd/clangd#529 Introduce the use of the Clang doxygen parser to parse the documentation of hovered code. - ASTContext independent doxygen parsing - Parsing doxygen commands to markdown for hover information Note: after this PR I have planned another patch to rearrange the information shown in the hover info. This PR is just for the basic introduction of doxygen parsing for hover information. --------- Co-authored-by: Maksim Ivanov <emaxx@google.com>
2025-07-09[clang][diagnostics] Refactor "warn_doc_api_container_decl_mismatch" to use ↵Ayokunle Amodu1-13/+16
enum_select (#146433) Related: https://github.com/llvm/llvm-project/issues/123121 This patch refactors the `warn_doc_api_container_decl_mismatch` diagnostic to use enum_select instead of select. This gets rid of magic numbers and improves readability in the caller site.
2025-07-08[clang][diagnostics] Refactor "warn_doc_container_decl_mismatch" to use ↵Ayokunle Amodu1-16/+15
enum_select (#147120) Related: https://github.com/llvm/llvm-project/issues/123121 This patch refactors the `warn_doc_container_decl_mismatch` diagnostic to use `enum_select` instead of `select`. This gets rid of magic numbers and improves readability in the caller site. @cor3ntin @erichkeane
2025-06-23[NFC][Clang][AST] Drop `llvm::` in front of `ArrayRef`/`MutableArrayRef` ↵Rahul Joshi1-3/+3
(#145207)
2025-05-22[Clang] add typo correction for unknown attribute names (#140629)Oleksandr T.1-71/+26
This patch enhances Clang's diagnosis for unknown attributes by providing typo correction suggestions for known attributes. ```cpp [[gmu::deprected]] // expected-warning {{unknown attribute 'gmu::deprected' ignored; did you mean 'gnu::deprecated'?}} int f1(void) { return 0; } [[deprected]] // expected-warning {{unknown attribute 'deprected' ignored; did you mean 'deprecated'?}} int f2(void) { return 0; } ```
2024-12-06[AST] Include clang/Basic/DiagnosticComment.h instead of ↵Kazu Hirata1-1/+1
clang/AST/CommentDiagnostic.h (#117499) Since: commit d076608d58d1ec55016eb747a995511e3a3f72aa Author: Richard Trieu <rtrieu@google.com> Date: Sat Dec 8 05:05:03 2018 +0000 clang/AST/CommentDiagnostic.h has been forwarding to clang/Basic/DiagnosticComment.h. This patch includes clang/Basic/DiagnosticComment.h instead of clang/AST/CommentDiagnostic.h.
2024-11-17[AST] Remove unused includes (NFC) (#116549)Kazu Hirata1-1/+0
Identified with misc-include-cleaner.
2023-11-06[clang][NFC] Refactor `ParamCommandComment::PassDirection`Vlad Serebrennikov1-14/+15
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 `InlineCommandComment::RenderKind`Vlad Serebrennikov1-11/+8
This patch converts `InlineCommandComment::RenderKind` 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-08-11[C23] Rename C2x -> C23; NFCAaron Ballman1-2/+2
This does the rename for most internal uses of C2x, but does not rename or reword diagnostics (those will be done in a follow-up). I also updated standards references and citations to the final wording in the standard.
2023-01-09Move from llvm::makeArrayRef to ArrayRef deduction guides - clang/ partserge-sans-paille1-3/+3
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
2022-05-13Comment parsing: Allow inline commands to have 0 or more than 1 argumentAaron Puchert1-37/+11
That's required to support `\n`, but can also be used for other commands. We already had the infrastructure in place to parse a varying number of arguments, we simply needed to generalize it so that it would work not only for block commands. This should fix #55319. Reviewed By: gribozavr2 Differential Revision: https://reviews.llvm.org/D125429
2021-11-12Comment AST: Recognize function-like objects via return type (NFC)Aaron Puchert1-3/+11
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-19/+4
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: Declare function pointer variables as functionsAaron Puchert1-32/+2
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-10-17[clang] Use llvm::erase_if (NFC)Kazu Hirata1-3/+1
2020-04-06[AST] Remove DeclCXX.h dep on ASTContext.hReid Kleckner1-1/+1
Saves only 36 includes of ASTContext.h and related headers. There are two deps on ASTContext.h: - C++ method overrides iterator types (TinyPtrVector) - getting LangOptions For #1, duplicate the iterator type, which is TinyPtrVector<>::const_iterator. For #2, add an out-of-line accessor to get the language options. Getting the ASTContext from a Decl is already an out of line method that loops over the parent DeclContexts, so if it is ever performance critical, the proper fix is to pass the context (or LangOpts) into the predicate in question. Other changes are just header fixups.
2020-02-20[clang][doxygen] Fix false -Wdocumentation warning for tag typedefsJan Korous1-5/+43
For tag typedefs like this one: /*! @class Foo */ typedef class { } Foo; clang -Wdocumentation gives: warning: '@class' command should not be used in a comment attached to a non-struct declaration [-Wdocumentation] ... while doxygen seems fine with it. Differential Revision: https://reviews.llvm.org/D74746
2019-12-21[Wdocumentation] Implement \anchorMark de Wever1-0/+1
Differential revision: https://reviews.llvm.org/D69223
2019-12-10[Wdocumentation] Use C2x/C++14 deprecated attributeMark de Wever1-10/+27
This replaces the non-standard __attribute__((deprecated)) with the standard [[deprecated]] when compiling in C2x/C++14 mode. Discovered while looking at https://bugs.llvm.org/show_bug.cgi?id=43753 Differential Revision: https://reviews.llvm.org/D71141
2019-12-10[Wdocumentation] Properly place deprecated attributeMark de Wever1-5/+5
It is now placed before the function: - allows to replace __attribute__((deprecated)) with [[deprecated]]. - required for trailing returns. Fixes bug: https://bugs.llvm.org/show_bug.cgi?id=43753 Differential Revision: https://reviews.llvm.org/D71140
2019-12-10[Wdocumentation] Use the command marker.Mark de Wever1-3/+2
Use the proper marker for -Wdocumentation-deprecated-sync instead of hard-coded the backslash. Discovered while looking at https://bugs.llvm.org/show_bug.cgi?id=43753 Differential Revision: https://reviews.llvm.org/D71139
2019-09-02[Wdocumentation] fixes an assertion failure with typedefed function and ↵Dmitri Gribenko1-0/+8
block pointer Summary: The assertion happens when compiling with -Wdocumentation with variable declaration to a typedefed function pointer. I not too familiar with the ObjC syntax but first two tests assert without this patch. Fixes https://bugs.llvm.org/show_bug.cgi?id=42844 Reviewers: gribozavr Reviewed By: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66706 llvm-svn: 370677
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-08-09Port getLocEnd -> getEndLocStephen Kelly1-4/+3
Reviewers: teemperor! Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D50351 llvm-svn: 339386
2018-05-09Remove \brief commands from doxygen comments.Adrian Prantl1-1/+1
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
2017-10-06-Wdocumentation should allow '...' params in variadic function type aliasesAlex Lorenz1-1/+9
rdar://34811344 llvm-svn: 315103
2017-04-26-Wdocumentation should not check the @returns command for Objective-CAlex Lorenz1-2/+4
function/block pointer properties The commit r300981 allowed @param/@return commands for function/block pointer property declarations. This meant that -Wdocumentation started warning about @return that was used to document properties whose function/block type returned void. However, prior to that commit, we allowed @return for all property declarations, because it can be used to document the value that's returned by the property getter. This commit restores the previous behaviour: now the @return command can be used to document all properties without warnings. rdar://24978538 llvm-svn: 301402
2017-04-21[PR32667] -Wdocumentation should allow @param/@returns for fields/variablesAlex Lorenz1-2/+26
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-28AST: improve layout of SimpleTypoCorrectorSaleem Abdulrasool1-6/+5
Add the "explicit" specifier to the single-argument constructor of SimpleTypoCorrector. Reorder the fields to remove excessive padding (8 bytes). Patch by Alexander Shaposhnikov! llvm-svn: 279946
2016-02-10Fix some Clang-tidy readability-redundant-control-flow warnings; other minor ↵Eugene Zelenko1-7/+4
fixes. Differential revision: http://reviews.llvm.org/D17060 llvm-svn: 260414
2014-05-12[C++11] Use 'nullptr'. AST edition.Craig Topper1-5/+6
llvm-svn: 208517
2014-04-30Comment parsing: remove HTML attribute validationDmitri Gribenko1-13/+8
Since the community says that a blacklist is not good enough, and I don't have enough time now to implement a proper whitelist, let's just remove the attribute validation. But, nevertheless, we can still communicate in the generated XML if our parser found an issue with the HTML. But this bit is best-effort and is specifically called out in the schema as such. llvm-svn: 207712
2014-04-22Comment parsing: in the generated XML file, mark HTML that is safe to passDmitri Gribenko1-4/+29
through to the output even if the input comment comes from an untrusted source Attribute filtering is currently based on a blacklist, which right now includes all event handler attributes (they contain JavaScipt code). It should be switched to a whitelist, but going over all of the HTML5 spec requires a significant amount of time. llvm-svn: 206882
2014-03-19Comment parsing: recognize \param ... on function templates with variadicDmitri Gribenko1-1/+4
parameters Patch by Joe Ranieri. llvm-svn: 204235
2014-01-27Comment parsing: don't crash while parsing \deprecated in a standalone commentDmitri Gribenko1-2/+11
(comment without a decl). I think this can not happen during normal compilation with -Wdocumentation, only while using Clang APIs to parse comments outside of a source file. Based on a patch by Olivier Goffart. llvm-svn: 200230
2014-01-25Rename getResultType() on function and method declarations to getReturnType()Alp Toker1-1/+1
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-17Fix strange indentation and remove trailing whitespace on empty linesDmitri Gribenko1-10/+10
llvm-svn: 197513
2013-11-10Avoid double StringMap lookups. No functionality change.Benjamin Kramer1-5/+3
llvm-svn: 194355
2013-11-10CommentSema: Factor code better. No functionality change.Benjamin Kramer1-44/+28
llvm-svn: 194354
2013-08-23Use pop_back_val() instead of both back() and pop_back().Robert Wilhelm1-2/+1
No functionality change intended. llvm-svn: 189112
2013-06-24Comment parsing: allow "\param ..." to describe variadic argumentsDmitri Gribenko1-1/+19
Original patch by Fariborz Jahanian; extended by me. Fixes rdar://14124644 llvm-svn: 184688
2013-06-24Move comment on Sema::isFunctionPointerVarDecl() to the header fileDmitri Gribenko1-3/+1
llvm-svn: 184677
2013-06-22Comment parsing: followup to r184610: allow multiple \returnsDmitri Gribenko1-7/+1
Remove unneeded member in CommentSema, add a test for the XML schema (the schema already allowed multiple paragraphs in <ResultDiscussion>, but there were no tests for that), fix HTML generation (it is not allowed to have <p> inside <dl>). llvm-svn: 184652
2013-06-21[document parsing]: Allow multiple adjacent \return and the likeFariborz Jahanian1-3/+2
commands. Render them properly in XML output. // rdar://14207725 llvm-svn: 184610
2013-06-19documentation parsing: patch to make @class work forFariborz Jahanian1-3/+21
class templates; and similarly, @function works for function templates. // rdar://14124702 llvm-svn: 184329
2013-06-19Revert r184249, "doc. parsing: Allow parameter name "..." for variadic ↵NAKAMURA Takumi1-15/+1
functions/methods." It crashes in the case; /// Without any "param"s in the description. int printf(const char *format, ...); llvm-svn: 184283
2013-06-18doc. parsing: Allow parameter name "..." for variadic functions/methods.Fariborz Jahanian1-1/+15
// rdar://14124644 llvm-svn: 184249
2013-05-20doc. parsing. HeaderDoc documentaton allows use ofFariborz Jahanian1-0/+5
@class command on an @interface declaration. Turn off the warning for this case. // rdar://13927330 llvm-svn: 182334