[llvm-branch-commits] [clang-tools-extra] [clangd] Add clangd 18 release notes (PR #84436)

2024-03-07 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/84436

None

>From 41cdc4a095d3082a3d6764c8950e626156c7bb07 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Fri, 8 Mar 2024 02:00:08 -0500
Subject: [PATCH] [clangd] Add clangd 18 release notes

---
 clang-tools-extra/docs/ReleaseNotes.rst | 33 +++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 5758b5acbc0b56..d963642b812fbf 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -51,21 +51,40 @@ Improvements to clangd
 Inlay hints
 ^^^
 
+- Type hints
+* Improved heuristics for showing sugared vs. desguared types
+* Some hints which provide no information (e.g. ) are 
now omitted
+- Parameter hints
+* Parameter hints are now shown for calls through function pointers
+* Parameter hints are now shown for calls to a class's ``operator()``
+* No longer show bogus parameter hints for some builtins like 
``__builtin_dump_struct``
+
 Diagnostics
 ^^^
 
-Semantic Highlighting
-^
+- Improved quality of include-cleaner diagnostics (missing and unused includes)
 
 Compile flags
 ^
 
+- System include extractor (``--query-driver``) improvements
+* The directory containing builtin headers is now excluded from extracted 
system includes
+* Various flags which can affect the system includes (``--target``, 
``--stdlib``, ``-specs``) are now forwarded to the driver
+* Fixed a bug where clangd would sometimes try to call a driver that 
didn't have obj-c support with ``-x objective-c++-header``
+* The driver path is now dot-normalized before being compared to the 
``--query-driver`` pattern
+* ``--query-driver`` is now supported by ``clangd-indexer``
+- Fixed a regression in clangd 17 where response files would not be expanded
+
 Hover
 ^
 
+- Hover now shows alignment info for fields and records
+
 Code completion
 ^^^
 
+- Refined heuristics for determining whether the use of a function can be a 
call or not
+
 Code actions
 
 
@@ -75,15 +94,25 @@ Code actions
 Signature help
 ^^
 
+- Improved support for calls through function pointer types
+
 Cross-references
 
 
+- Improved support for C++20 concepts
+- Find-references now works for labels
+- Improvements to template heuristics
+
 Objective-C
 ^^^
 
 Miscellaneous
 ^
 
+- Various stability improvements, e.g. crash fixes
+- Improved error recovery on invalid code
+- Clangd now bails gracefully on assembly and IR source files
+
 Improvements to clang-doc
 -
 

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] [clangd] Add clangd 18 release notes (PR #84436)

2024-03-07 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

To prepare these, I went through the clangd commits in clangd 18 and made note 
of what seemed notable to me.

In some areas of the code that I'm less familiar with, I was somewhat vague 
(e.g. under "Diagnostics" I added "Improved quality of include-cleaner 
diagnostics (missing and unused includes)"; if someone more familiar with 
include-cleaner would like to expand on that with more specific improvements, 
that would be welcome).

https://github.com/llvm/llvm-project/pull/84436
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] [clangd] Add clangd 18 release notes (PR #84436)

2024-03-09 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/84436

>From f3c3e2d29abaf07ec2d84092c29bc01cc7201fda Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Fri, 8 Mar 2024 02:00:08 -0500
Subject: [PATCH] [clangd] [include-cleaner] Add release notes for LLVM 18

---
 clang-tools-extra/docs/ReleaseNotes.rst | 43 +
 1 file changed, 36 insertions(+), 7 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 5758b5acbc0b56..8621444364fb20 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -51,21 +51,35 @@ Improvements to clangd
 Inlay hints
 ^^^
 
-Diagnostics
-^^^
-
-Semantic Highlighting
-^
+- Type hints
+* Improved heuristics for showing sugared vs. desguared types
+* Some hints which provide no information (e.g. ) are 
now omitted
+- Parameter hints
+* Parameter hints are now shown for calls through function pointers
+* Parameter hints are now shown for calls to a class's ``operator()``
+* No longer show bogus parameter hints for some builtins like 
``__builtin_dump_struct``
 
 Compile flags
 ^
 
+- System include extractor (``--query-driver``) improvements
+* The directory containing builtin headers is now excluded from extracted 
system includes
+* Various flags which can affect the system includes (``--target``, 
``--stdlib``, ``-specs``) are now forwarded to the driver
+* Fixed a bug where clangd would sometimes try to call a driver that 
didn't have obj-c support with ``-x objective-c++-header``
+* The driver path is now dot-normalized before being compared to the 
``--query-driver`` pattern
+* ``--query-driver`` is now supported by ``clangd-indexer``
+- Fixed a regression in clangd 17 where response files would not be expanded
+
 Hover
 ^
 
+- Hover now shows alignment info for fields and records
+
 Code completion
 ^^^
 
+- Refined heuristics for determining whether the use of a function can be a 
call or not
+
 Code actions
 
 
@@ -75,15 +89,25 @@ Code actions
 Signature help
 ^^
 
+- Improved support for calls through function pointer types
+
 Cross-references
 
 
+- Improved support for C++20 concepts
+- Find-references now works for labels
+- Improvements to template heuristics
+
 Objective-C
 ^^^
 
 Miscellaneous
 ^
 
+- Various stability improvements, e.g. crash fixes
+- Improved error recovery on invalid code
+- Clangd now bails gracefully on assembly and IR source files
+
 Improvements to clang-doc
 -
 
@@ -564,10 +588,15 @@ Changes in existing checks
 Removed checks
 ^^
 
-Improvements to include-fixer
+Improvements to include-cleaner
 -
 
-The improvements are...
+- Support for ``--only-headers`` flag to limit analysis to headers matching a 
regex
+- Recognizes references through ``concept``s
+- Builtin headers are not analyzed
+- Handling of references through ``friend`` declarations
+- Fixes around handling of IWYU pragmas on stdlib headers
+- Improved handling around references to/from template specializations
 
 Improvements to clang-include-fixer
 ---

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] [clangd] Add clangd 18 release notes (PR #84436)

2024-03-09 Thread Nathan Ridge via llvm-branch-commits


@@ -51,21 +51,40 @@ Improvements to clangd
 Inlay hints
 ^^^
 
+- Type hints
+* Improved heuristics for showing sugared vs. desguared types
+* Some hints which provide no information (e.g. ) are 
now omitted
+- Parameter hints
+* Parameter hints are now shown for calls through function pointers
+* Parameter hints are now shown for calls to a class's ``operator()``
+* No longer show bogus parameter hints for some builtins like 
``__builtin_dump_struct``
+
 Diagnostics
 ^^^
 
-Semantic Highlighting
-^
+- Improved quality of include-cleaner diagnostics (missing and unused includes)

HighCommander4 wrote:

Thanks, I added these in an include-cleaner section

https://github.com/llvm/llvm-project/pull/84436
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] [clangd] Add clangd 18 release notes (PR #84436)

2024-03-09 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

@kadircet do you know what is the process for getting this approved and merged? 
As this is targeting the `release/18.x` branch, I do not have permissions to 
merge it myself like a regular PR.

https://github.com/llvm/llvm-project/pull/84436
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] release/18.x: [clangd] [HeuristicResolver] Protect against infinite recursion on DependentNameTypes (#83542) (PR #84117)

2024-03-15 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

(Does the backport need to be reviewed separately? Not sure what is the process 
these days.)

https://github.com/llvm/llvm-project/pull/84117
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] release/18.x: [clangd] [HeuristicResolver] Protect against infinite recursion on DependentNameTypes (#83542) (PR #84117)

2024-03-15 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

> Do you think this needs a release note?

There is an umbrella entry in the release notes for "Various stability 
improvements, e.g. crash fixes". I don't think it adds much value to list the 
crash fixes individually (unless maybe it's a particularly widely reported one 
like https://github.com/clangd/clangd/issues/1384).

https://github.com/llvm/llvm-project/pull/84117
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] release/18.x: [clangd] [HeuristicResolver] Protect against infinite recursion on DependentNameTypes (#83542) (PR #84117)

2024-03-15 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

> that sounds a bit unclear. :)

I'm happy to take suggestions for better wording!

https://github.com/llvm/llvm-project/pull/84117
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] [clangd] Add clangd 19 release notes (PR #105975)

2024-08-24 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/105975

None

>From 210ac24c486f144967598a6abcb7fdc829113ffe Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Sun, 25 Aug 2024 02:10:45 -0400
Subject: [PATCH] [clangd] Add clangd 19 release notes

---
 clang-tools-extra/docs/ReleaseNotes.rst | 35 +
 1 file changed, 35 insertions(+)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 71461968629868..ebcdeca8c2ee50 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -61,6 +61,8 @@ Diagnostics
 Semantic Highlighting
 ^
 
+- Improved semantic token coverage in some edge cases, e.g. IndirectFieldDecl
+
 Compile flags
 ^
 
@@ -70,24 +72,57 @@ Hover
 Code completion
 ^^^
 
+- ``--function-arg-placeholders=0`` is now respected for variable template 
argument lists
+   as well
+- Macro proposals now use the completion item kind ``Constant`` (for 
object-like macros)
+  or ``Function`` (for function-style macros) even for proposals coming from 
the index
+
 Code actions
 
 
+- The "extract variable" tweak is no longer offered for the initializer 
expression of a
+  declaration
 - The tweak for turning unscoped into scoped enums now removes redundant 
prefixes
   from the enum values.
+- Support "move function body out-of-line" in non-header files as well
 
 Signature help
 ^^
 
+- Signature help now shows function argument names for calls through pointers 
to
+  functions in struct fields
+
 Cross-references
 
 
+- Improve go-to-definition for some concept references
+
+Document outline
+
+
+- Improved precision of document outline information for symbols whose 
definitions
+  involve macro expansions
+
+Clang-tidy integration
+^^
+
+- The quick fix for clang-tidy's ``readability-identifier-naming`` diagnostic 
is now
+  hooked to invoke ``textDocument/rename``, renaming the identifier across the 
whole
+  project rather than just the translation unit of the diagnostic
+- ``misc-const-correctness`` can now be enabled with ``FastCheckFilter: None``
+  (previously clangd would force it off unconditionally due to its run time)
+
 Objective-C
 ^^^
 
+- Added support for renaming Objective-C methods
+
 Miscellaneous
 ^
 
+- Worked around a clang-format bug that caused memory exhaustion when opening 
some large
+  ``.h`` files due to the formatter's language guessing heuristic (#GH85703)
+- Various other stability improvements, e.g. crash fixes
 - Added a boolean option `AnalyzeAngledIncludes` to `Includes` config section,
   which allows to enable unused includes detection for all angled ("system") 
headers.
   At this moment umbrella headers are not supported, so enabling this option

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] [clangd] Add clangd 19 release notes (PR #105975)

2024-08-26 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

> Should we mention the module support, even though it’s still in the initial 
> stages?

It is [already 
mentioned](https://github.com/llvm/llvm-project/blob/5f744ee5c770d7332740bb6247f961e7d99ee359/clang-tools-extra/docs/ReleaseNotes.rst#L51-L53).
 (It was added to the release notes as part of the same commit as the 
implementation.)

https://github.com/llvm/llvm-project/pull/105975
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] [clangd] Add clangd 19 release notes (PR #105975)

2024-08-28 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 milestoned 
https://github.com/llvm/llvm-project/pull/105975
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] [clangd] Add clangd 19 release notes (PR #105975)

2024-08-28 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

Thanks for the review.

@tstellar could you merge these release notes for us please?

https://github.com/llvm/llvm-project/pull/105975
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] release/19.x: [clangd] Update TidyFastChecks for release/19.x (#106354) (PR #106989)

2024-09-02 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 approved this pull request.

+1 from me

https://github.com/llvm/llvm-project/pull/106989
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] 4718ec0 - [clangd] Avoid recursion in TargetFinder::add()

2021-01-12 Thread Nathan Ridge via llvm-branch-commits

Author: Nathan Ridge
Date: 2021-01-12T13:57:54-05:00
New Revision: 4718ec01669b01373180f4cd1256c6e2dd6f3999

URL: 
https://github.com/llvm/llvm-project/commit/4718ec01669b01373180f4cd1256c6e2dd6f3999
DIFF: 
https://github.com/llvm/llvm-project/commit/4718ec01669b01373180f4cd1256c6e2dd6f3999.diff

LOG: [clangd] Avoid recursion in TargetFinder::add()

Fixes https://github.com/clangd/clangd/issues/633

Differential Revision: https://reviews.llvm.org/D94382

Added: 


Modified: 
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/FindTarget.h
clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/FindTarget.cpp 
b/clang-tools-extra/clangd/FindTarget.cpp
index 9a502a84e36f..84316659daad 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -330,6 +330,7 @@ struct TargetFinder {
   llvm::SmallDenseMap>
   Decls;
+  llvm::SmallDenseMap Seen;
   RelSet Flags;
 
   template  void debug(T &Node, RelSet Flags) {
@@ -359,6 +360,15 @@ struct TargetFinder {
 if (!D)
   return;
 debug(*D, Flags);
+
+// Avoid recursion (which can arise in the presence of heuristic
+// resolution of dependent names) by exiting early if we have
+// already seen this decl with all flags in Flags.
+auto Res = Seen.try_emplace(D);
+if (!Res.second && Res.first->second.contains(Flags))
+  return;
+Res.first->second |= Flags;
+
 if (const UsingDirectiveDecl *UDD = llvm::dyn_cast(D))
   D = UDD->getNominatedNamespaceAsWritten();
 

diff  --git a/clang-tools-extra/clangd/FindTarget.h 
b/clang-tools-extra/clangd/FindTarget.h
index 435e4f4ac038..92e4354d1eaa 100644
--- a/clang-tools-extra/clangd/FindTarget.h
+++ b/clang-tools-extra/clangd/FindTarget.h
@@ -194,6 +194,9 @@ class DeclRelationSet {
 S &= Other.S;
 return *this;
   }
+  bool contains(DeclRelationSet Other) const {
+return (S & Other.S) == Other.S;
+  }
   friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, DeclRelationSet);
 };
 // The above operators can't be looked up if both sides are enums.

diff  --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index dd7e9878a6d5..46e17dc053c0 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -787,6 +787,47 @@ TEST_F(TargetDeclTest, DependentTypes) {
"template  struct B");
 }
 
+TEST_F(TargetDeclTest, TypedefCascade) {
+  Code = R"cpp(
+struct C {
+  using type = int;
+};
+struct B {
+  using type = C::type;
+};
+struct A {
+  using type = B::type;
+};
+A::[[type]] waldo;
+  )cpp";
+  EXPECT_DECLS("TypedefTypeLoc",
+   {"using type = int", Rel::Alias | Rel::Underlying},
+   {"using type = C::type", Rel::Alias | Rel::Underlying},
+   {"using type = B::type", Rel::Alias});
+}
+
+TEST_F(TargetDeclTest, RecursiveTemplate) {
+  Flags.push_back("-std=c++20"); // the test case uses concepts
+
+  Code = R"cpp(
+template 
+concept Leaf = false;
+
+template 
+struct descend_left {
+  using type = typename descend_left::[[type]];
+};
+
+template 
+struct descend_left {
+  using type = typename Tree::value;
+};
+  )cpp";
+  EXPECT_DECLS("DependentNameTypeLoc",
+   {"using type = typename descend_left::type",
+Rel::Alias | Rel::Underlying});
+}
+
 TEST_F(TargetDeclTest, ObjC) {
   Flags = {"-xobjective-c"};
   Code = R"cpp(



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] 3e6e6a2 - [clangd] Call hierarchy (XRefs layer, incoming calls)

2020-11-24 Thread Nathan Ridge via llvm-branch-commits

Author: Nathan Ridge
Date: 2020-11-23T20:43:38-05:00
New Revision: 3e6e6a2db674cd85b33c06b75685c6bce5acb154

URL: 
https://github.com/llvm/llvm-project/commit/3e6e6a2db674cd85b33c06b75685c6bce5acb154
DIFF: 
https://github.com/llvm/llvm-project/commit/3e6e6a2db674cd85b33c06b75685c6bce5acb154.diff

LOG: [clangd] Call hierarchy (XRefs layer, incoming calls)

Support for outgoing calls is left for a future change.

Differential Revision: https://reviews.llvm.org/D91122

Added: 
clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp

Modified: 
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/XRefs.h
clang-tools-extra/clangd/unittests/CMakeLists.txt
clang-tools-extra/clangd/unittests/TestTU.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index 0cd8695da92d..e319636f9076 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -47,6 +47,7 @@
 #include "clang/Index/USRGeneration.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
@@ -1339,9 +1340,9 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, 
const LocatedSymbol &S) {
   return OS;
 }
 
-// FIXME(nridge): Reduce duplication between this function and declToSym().
-static llvm::Optional
-declToTypeHierarchyItem(ASTContext &Ctx, const NamedDecl &ND) {
+template 
+static llvm::Optional declToHierarchyItem(const NamedDecl &ND) {
+  ASTContext &Ctx = ND.getASTContext();
   auto &SM = Ctx.getSourceManager();
   SourceLocation NameLoc = nameLocation(ND, Ctx.getSourceManager());
   SourceLocation BeginLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getBeginLoc()));
@@ -1365,54 +1366,84 @@ declToTypeHierarchyItem(ASTContext &Ctx, const 
NamedDecl &ND) {
   // correctly.
   SymbolKind SK = indexSymbolKindToSymbolKind(SymInfo.Kind);
 
-  TypeHierarchyItem THI;
-  THI.name = printName(Ctx, ND);
-  THI.kind = SK;
-  THI.deprecated = ND.isDeprecated();
-  THI.range = Range{sourceLocToPosition(SM, DeclRange->getBegin()),
-sourceLocToPosition(SM, DeclRange->getEnd())};
-  THI.selectionRange = Range{NameBegin, NameEnd};
-  if (!THI.range.contains(THI.selectionRange)) {
+  HierarchyItem HI;
+  HI.name = printName(Ctx, ND);
+  HI.kind = SK;
+  HI.range = Range{sourceLocToPosition(SM, DeclRange->getBegin()),
+   sourceLocToPosition(SM, DeclRange->getEnd())};
+  HI.selectionRange = Range{NameBegin, NameEnd};
+  if (!HI.range.contains(HI.selectionRange)) {
 // 'selectionRange' must be contained in 'range', so in cases where clang
 // reports unrelated ranges we need to reconcile somehow.
-THI.range = THI.selectionRange;
+HI.range = HI.selectionRange;
   }
 
-  THI.uri = URIForFile::canonicalize(*FilePath, *TUPath);
+  HI.uri = URIForFile::canonicalize(*FilePath, *TUPath);
 
   // Compute the SymbolID and store it in the 'data' field.
   // This allows typeHierarchy/resolve to be used to
   // resolve children of items returned in a previous request
   // for parents.
   if (auto ID = getSymbolID(&ND))
-THI.data = ID.str();
+HI.data = ID.str();
+
+  return HI;
+}
 
-  return THI;
+static llvm::Optional
+declToTypeHierarchyItem(const NamedDecl &ND) {
+  auto Result = declToHierarchyItem(ND);
+  if (Result)
+Result->deprecated = ND.isDeprecated();
+  return Result;
 }
 
-static Optional
-symbolToTypeHierarchyItem(const Symbol &S, const SymbolIndex *Index,
-  PathRef TUPath) {
+static llvm::Optional
+declToCallHierarchyItem(const NamedDecl &ND) {
+  auto Result = declToHierarchyItem(ND);
+  if (Result && ND.isDeprecated())
+Result->tags.push_back(SymbolTag::Deprecated);
+  return Result;
+}
+
+template 
+static llvm::Optional symbolToHierarchyItem(const Symbol &S,
+   PathRef TUPath) {
   auto Loc = symbolToLocation(S, TUPath);
   if (!Loc) {
-log("Type hierarchy: {0}", Loc.takeError());
+elog("Failed to convert symbol to hierarchy item: {0}", Loc.takeError());
 return llvm::None;
   }
-  TypeHierarchyItem THI;
-  THI.name = std::string(S.Name);
-  THI.kind = indexSymbolKindToSymbolKind(S.SymInfo.Kind);
-  THI.deprecated = (S.Flags & Symbol::Deprecated);
-  THI.selectionRange = Loc->range;
+  HierarchyItem HI;
+  HI.name = std::string(S.Name);
+  HI.kind = indexSymbolKindToSymbolKind(S.SymInfo.Kind);
+  HI.selectionRange = Loc->range;
   // FIXME: Populate 'range' correctly
   // (https://github.com/clangd/clangd/issues/59).
-  THI.range = THI.selectionRange;
-  THI.uri = Loc->uri;
+  HI.range = HI.selectionRange;
+  HI.uri = Loc->uri;
   // Store the SymbolID in the 'data' field. The client will
-  // send this back in typeHierarchy/resolve, allowing us to
-  // continu

[llvm-branch-commits] [clang-tools-extra] 4cb976e - [clangd] Call hierarchy (ClangdServer layer)

2020-11-24 Thread Nathan Ridge via llvm-branch-commits

Author: Nathan Ridge
Date: 2020-11-23T20:43:41-05:00
New Revision: 4cb976e014db80efd20dfca45ba218c3a69aac42

URL: 
https://github.com/llvm/llvm-project/commit/4cb976e014db80efd20dfca45ba218c3a69aac42
DIFF: 
https://github.com/llvm/llvm-project/commit/4cb976e014db80efd20dfca45ba218c3a69aac42.diff

LOG: [clangd] Call hierarchy (ClangdServer layer)

Differential Revision: https://reviews.llvm.org/D91123

Added: 


Modified: 
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index 889d2cbcf280..523931d9cc7b 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -678,6 +678,26 @@ void ClangdServer::resolveTypeHierarchy(
   CB(Item);
 }
 
+void ClangdServer::prepareCallHierarchy(
+PathRef File, Position Pos, Callback> CB) {
+  auto Action = [File = File.str(), Pos,
+ CB = std::move(CB)](Expected InpAST) mutable {
+if (!InpAST)
+  return CB(InpAST.takeError());
+CB(clangd::prepareCallHierarchy(InpAST->AST, Pos, File));
+  };
+  WorkScheduler.runWithAST("Call Hierarchy", File, std::move(Action));
+}
+
+void ClangdServer::incomingCalls(
+const CallHierarchyItem &Item,
+Callback> CB) {
+  WorkScheduler.run("Incoming Calls", "",
+[CB = std::move(CB), Item, this]() mutable {
+  CB(clangd::incomingCalls(Item, Index));
+});
+}
+
 void ClangdServer::onFileEvent(const DidChangeWatchedFilesParams &Params) {
   // FIXME: Do nothing for now. This will be used for indexing and potentially
   // invalidating other caches.

diff  --git a/clang-tools-extra/clangd/ClangdServer.h 
b/clang-tools-extra/clangd/ClangdServer.h
index 1ccb4c5899f8..18c35e701e5b 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -242,6 +242,14 @@ class ClangdServer {
 TypeHierarchyDirection Direction,
 Callback> CB);
 
+  /// Get information about call hierarchy for a given position.
+  void prepareCallHierarchy(PathRef File, Position Pos,
+Callback> CB);
+
+  /// Resolve incoming calls for a given call hierarchy item.
+  void incomingCalls(const CallHierarchyItem &Item,
+ Callback>);
+
   /// Retrieve the top symbols from the workspace matching a query.
   void workspaceSymbols(StringRef Query, int Limit,
 Callback> CB);



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] 0a4f99c - [clangd] Call hierarchy (ClangdLSPServer layer)

2020-11-24 Thread Nathan Ridge via llvm-branch-commits

Author: Nathan Ridge
Date: 2020-11-23T20:44:07-05:00
New Revision: 0a4f99c494d007a21652b1b3939bde4753042c33

URL: 
https://github.com/llvm/llvm-project/commit/0a4f99c494d007a21652b1b3939bde4753042c33
DIFF: 
https://github.com/llvm/llvm-project/commit/0a4f99c494d007a21652b1b3939bde4753042c33.diff

LOG: [clangd] Call hierarchy (ClangdLSPServer layer)

Differential Revision: https://reviews.llvm.org/D91124

Added: 
clang-tools-extra/clangd/test/call-hierarchy.test

Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/test/initialize-params.test
clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 335a6fc9ad94..66dee68ec474 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -625,6 +625,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams 
&Params,
  }},
 {"typeHierarchyProvider", true},
 {"memoryUsageProvider", true}, // clangd extension.
+{"callHierarchyProvider", true},
 ;
   if (Opts.Encoding)
 Result["offsetEncoding"] = *Opts.Encoding;
@@ -1224,6 +1225,26 @@ void ClangdLSPServer::onResolveTypeHierarchy(
std::move(Reply));
 }
 
+void ClangdLSPServer::onPrepareCallHierarchy(
+const CallHierarchyPrepareParams &Params,
+Callback> Reply) {
+  Server->prepareCallHierarchy(Params.textDocument.uri.file(), Params.position,
+   std::move(Reply));
+}
+
+void ClangdLSPServer::onCallHierarchyIncomingCalls(
+const CallHierarchyIncomingCallsParams &Params,
+Callback> Reply) {
+  Server->incomingCalls(Params.item, std::move(Reply));
+}
+
+void ClangdLSPServer::onCallHierarchyOutgoingCalls(
+const CallHierarchyOutgoingCallsParams &Params,
+Callback> Reply) {
+  // FIXME: To be implemented.
+  Reply(std::vector{});
+}
+
 void ClangdLSPServer::applyConfiguration(
 const ConfigurationSettings &Settings) {
   // Per-file update to the compilation database.
@@ -1468,6 +1489,9 @@ ClangdLSPServer::ClangdLSPServer(class Transport &Transp,
   MsgHandler->bind("textDocument/symbolInfo", &ClangdLSPServer::onSymbolInfo);
   MsgHandler->bind("textDocument/typeHierarchy", 
&ClangdLSPServer::onTypeHierarchy);
   MsgHandler->bind("typeHierarchy/resolve", 
&ClangdLSPServer::onResolveTypeHierarchy);
+  MsgHandler->bind("textDocument/prepareCallHierarchy", 
&ClangdLSPServer::onPrepareCallHierarchy);
+  MsgHandler->bind("callHierarchy/incomingCalls", 
&ClangdLSPServer::onCallHierarchyIncomingCalls);
+  MsgHandler->bind("callHierarchy/outgoingCalls", 
&ClangdLSPServer::onCallHierarchyOutgoingCalls);
   MsgHandler->bind("textDocument/selectionRange", 
&ClangdLSPServer::onSelectionRange);
   MsgHandler->bind("textDocument/documentLink", 
&ClangdLSPServer::onDocumentLink);
   MsgHandler->bind("textDocument/semanticTokens/full", 
&ClangdLSPServer::onSemanticTokens);

diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.h 
b/clang-tools-extra/clangd/ClangdLSPServer.h
index 4d568bc13d8b..e65fc0e8a006 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -135,6 +135,14 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
Callback>);
   void onResolveTypeHierarchy(const ResolveTypeHierarchyItemParams &,
   Callback>);
+  void onPrepareCallHierarchy(const CallHierarchyPrepareParams &,
+  Callback>);
+  void onCallHierarchyIncomingCalls(
+  const CallHierarchyIncomingCallsParams &,
+  Callback>);
+  void onCallHierarchyOutgoingCalls(
+  const CallHierarchyOutgoingCallsParams &,
+  Callback>);
   void onChangeConfiguration(const DidChangeConfigurationParams &);
   void onSymbolInfo(const TextDocumentPositionParams &,
 Callback>);

diff  --git a/clang-tools-extra/clangd/test/call-hierarchy.test 
b/clang-tools-extra/clangd/test/call-hierarchy.test
new file mode 100644
index ..6548ea0068a8
--- /dev/null
+++ b/clang-tools-extra/clangd/test/call-hierarchy.test
@@ -0,0 +1,39 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"cpp","text":"void
 callee(int);\nvoid caller1() {\n  callee(42);\n}\nvoid caller2() {\n  
caller1();\n  caller1();\n}\nvoid caller3() {\n  caller1();\n  
caller2();\n}\n","uri":"test:///main.cpp","version":1}}}
+---
+{"jsonrpc":"2.0","id":1,"method":"textDocument/prepareCallHierarchy","params":

[llvm-branch-commits] [clang-tools-extra] dced150 - [clangd] Use WorkScheduler.run() in ClangdServer::resolveTypeHierarchy()

2020-11-24 Thread Nathan Ridge via llvm-branch-commits

Author: Nathan Ridge
Date: 2020-11-23T20:44:14-05:00
New Revision: dced150375d09df6266448342fbb066d638b59ef

URL: 
https://github.com/llvm/llvm-project/commit/dced150375d09df6266448342fbb066d638b59ef
DIFF: 
https://github.com/llvm/llvm-project/commit/dced150375d09df6266448342fbb066d638b59ef.diff

LOG: [clangd] Use WorkScheduler.run() in ClangdServer::resolveTypeHierarchy()

Differential Revision: https://reviews.llvm.org/D91941

Added: 


Modified: 
clang-tools-extra/clangd/ClangdServer.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index 523931d9cc7bf..502078c776db9 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -674,8 +674,11 @@ void ClangdServer::typeHierarchy(PathRef File, Position 
Pos, int Resolve,
 void ClangdServer::resolveTypeHierarchy(
 TypeHierarchyItem Item, int Resolve, TypeHierarchyDirection Direction,
 Callback> CB) {
-  clangd::resolveTypeHierarchy(Item, Resolve, Direction, Index);
-  CB(Item);
+  WorkScheduler.run(
+  "Resolve Type Hierarchy", "", [=, CB = std::move(CB)]() mutable {
+clangd::resolveTypeHierarchy(Item, Resolve, Direction, Index);
+CB(Item);
+  });
 }
 
 void ClangdServer::prepareCallHierarchy(



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] 3d2c681 - [clangd] Avoid type hierarchy crash on incomplete type

2020-11-25 Thread Nathan Ridge via llvm-branch-commits

Author: Nathan Ridge
Date: 2020-11-25T03:45:00-05:00
New Revision: 3d2c681f2835261599654c1b82dacdae05c9b4c4

URL: 
https://github.com/llvm/llvm-project/commit/3d2c681f2835261599654c1b82dacdae05c9b4c4
DIFF: 
https://github.com/llvm/llvm-project/commit/3d2c681f2835261599654c1b82dacdae05c9b4c4.diff

LOG: [clangd] Avoid type hierarchy crash on incomplete type

Fixes https://github.com/clangd/clangd/issues/597

Differential Revision: https://reviews.llvm.org/D92077

Added: 


Modified: 
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index 31e963cb853f..8a85507ff14c 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -1553,6 +1553,10 @@ std::vector typeParents(const 
CXXRecordDecl *CXXRD) {
   CXXRD = CTSD->getSpecializedTemplate()->getTemplatedDecl();
   }
 
+  // Can't query bases without a definition.
+  if (!CXXRD->hasDefinition())
+return Result;
+
   for (auto Base : CXXRD->bases()) {
 const CXXRecordDecl *ParentDecl = nullptr;
 

diff  --git a/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp 
b/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
index 64831724d1be..08f936ce8b55 100644
--- a/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
+++ b/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
@@ -30,6 +30,7 @@ namespace {
 using ::testing::AllOf;
 using ::testing::ElementsAre;
 using ::testing::Field;
+using ::testing::IsEmpty;
 using ::testing::Matcher;
 using ::testing::UnorderedElementsAre;
 
@@ -318,6 +319,18 @@ struct Child3 : T {};
   EXPECT_THAT(typeParents(Child3), ElementsAre());
 }
 
+TEST(TypeParents, IncompleteClass) {
+  Annotations Source(R"cpp(
+class Incomplete;
+  )cpp");
+  TestTU TU = TestTU::withCode(Source.code());
+  auto AST = TU.build();
+
+  const CXXRecordDecl *Incomplete =
+  dyn_cast(&findDecl(AST, "Incomplete"));
+  EXPECT_THAT(typeParents(Incomplete), IsEmpty());
+}
+
 // Parts of getTypeHierarchy() are tested in more detail by the
 // FindRecordTypeAt.* and TypeParents.* tests above. This test exercises the
 // entire operation.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] c6cb47b - [clangd] Collect main file refs by default

2020-11-25 Thread Nathan Ridge via llvm-branch-commits

Author: Nathan Ridge
Date: 2020-11-25T20:33:57-05:00
New Revision: c6cb47b640ffafda113581c488a73fb62b6ea38a

URL: 
https://github.com/llvm/llvm-project/commit/c6cb47b640ffafda113581c488a73fb62b6ea38a
DIFF: 
https://github.com/llvm/llvm-project/commit/c6cb47b640ffafda113581c488a73fb62b6ea38a.diff

LOG: [clangd] Collect main file refs by default

This is needed for call hierarchy to be able to find callers of
main-file-only functions.

Differential Revision: https://reviews.llvm.org/D92000

Added: 


Modified: 
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/tool/ClangdMain.cpp
clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdServer.h 
b/clang-tools-extra/clangd/ClangdServer.h
index b6a1bd757894..35ba4686cc9a 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -106,7 +106,7 @@ class ClangdServer {
 bool BackgroundIndex = false;
 
 /// Store refs to main-file symbols in the index.
-bool CollectMainFileRefs = false;
+bool CollectMainFileRefs = true;
 
 /// If set, use this index to augment code completion results.
 SymbolIndex *StaticIndex = nullptr;

diff  --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp 
b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index 5c89e423cde4..d0eab3650750 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -494,7 +494,7 @@ opt CollectMainFileRefs{
 "collect-main-file-refs",
 cat(Misc),
 desc("Store references to main-file-only symbols in the index"),
-init(false),
+init(ClangdServer::Options().CollectMainFileRefs),
 };
 
 #if CLANGD_ENABLE_REMOTE

diff  --git a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp 
b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
index b25d3fde0002..f4a9b2fa2d13 100644
--- a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -188,8 +188,10 @@ TEST_F(BackgroundIndexTest, IndexTwoFiles) {
   size_t CacheHits = 0;
   MemoryShardStorage MSS(Storage, CacheHits);
   OverlayCDB CDB(/*Base=*/nullptr);
-  BackgroundIndex Idx(FS, CDB, [&](llvm::StringRef) { return &MSS; },
-  /*Opts=*/{});
+  BackgroundIndex::Options Opts;
+  Opts.CollectMainFileRefs = true;
+  BackgroundIndex Idx(
+  FS, CDB, [&](llvm::StringRef) { return &MSS; }, Opts);
 
   tooling::CompileCommand Cmd;
   Cmd.Filename = testPath("root/A.cc");
@@ -201,7 +203,7 @@ TEST_F(BackgroundIndexTest, IndexTwoFiles) {
   EXPECT_THAT(runFuzzyFind(Idx, ""),
   UnorderedElementsAre(AllOf(Named("common"), NumReferences(1U)),
AllOf(Named("A_CC"), NumReferences(0U)),
-   AllOf(Named("g"), NumReferences(0U)),
+   AllOf(Named("g"), NumReferences(1U)),
AllOf(Named("f_b"), Declared(),
  Not(Defined()), NumReferences(0U;
 
@@ -214,7 +216,7 @@ TEST_F(BackgroundIndexTest, IndexTwoFiles) {
   EXPECT_THAT(runFuzzyFind(Idx, ""),
   UnorderedElementsAre(AllOf(Named("common"), NumReferences(5U)),
AllOf(Named("A_CC"), NumReferences(0U)),
-   AllOf(Named("g"), NumReferences(0U)),
+   AllOf(Named("g"), NumReferences(1U)),
AllOf(Named("f_b"), Declared(), Defined(),
  NumReferences(1U;
 
@@ -238,7 +240,8 @@ TEST_F(BackgroundIndexTest, MainFileRefs) {
   FS.Files[testPath("root/A.cc")] =
   "#include \"A.h\"\nstatic void main_sym() { (void)header_sym; }";
 
-  // Check the behaviour with CollectMainFileRefs = false (the default).
+  // Check the behaviour with CollectMainFileRefs = false (the default
+  // at the SymbolCollector level).
   {
 llvm::StringMap Storage;
 size_t CacheHits = 0;



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] d1fd91d - [clangd] Do not treat line as inactive if skipped range ends at character position 0

2020-11-26 Thread Nathan Ridge via llvm-branch-commits

Author: Nathan Ridge
Date: 2020-11-26T03:42:42-05:00
New Revision: d1fd91ddaf9de95428a25d001606c23703e14b31

URL: 
https://github.com/llvm/llvm-project/commit/d1fd91ddaf9de95428a25d001606c23703e14b31
DIFF: 
https://github.com/llvm/llvm-project/commit/d1fd91ddaf9de95428a25d001606c23703e14b31.diff

LOG: [clangd] Do not treat line as inactive if skipped range ends at character 
position 0

Fixes https://github.com/clangd/clangd/issues/602

Differential Revision: https://reviews.llvm.org/D92148

Added: 


Modified: 
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp 
b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index 44d74f387dd1..5397d328b086 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -234,6 +234,10 @@ class HighlightingsBuilder {
   // with line-based 
diff ing.
   assert(R.start.line <= R.end.line);
   for (int Line = R.start.line; Line <= R.end.line; ++Line) {
+// If the end of the inactive range is at the beginning
+// of a line, that line is not inactive.
+if (Line == R.end.line && R.end.character == 0)
+  continue;
 // Copy tokens before the inactive line
 for (; It != NonConflicting.end() && It->R.start.line < Line; ++It)
   WithInactiveLines.push_back(std::move(*It));

diff  --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp 
b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index 232be6a78380..79f3af264c0f 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -623,18 +623,23 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
   // Code after the preamble.
   // Code inside inactive blocks does not get regular highlightings
   // because it's not part of the AST.
-$InactiveCode[[#ifdef test]]
+  #define $Macro[[test2]]
+$InactiveCode[[#if defined(test)]]
 $InactiveCode[[int Inactive2;]]
+$InactiveCode[[#elif defined(test2)]]
+  int $Variable[[Active1]];
+$InactiveCode[[#else]]
+$InactiveCode[[int Inactive3;]]
 $InactiveCode[[#endif]]
 
   #ifndef $Macro[[test]]
-  int $Variable[[Active1]];
+  int $Variable[[Active2]];
   #endif
 
 $InactiveCode[[#ifdef test]]
-$InactiveCode[[int Inactive3;]]
+$InactiveCode[[int Inactive4;]]
 $InactiveCode[[#else]]
-  int $Variable[[Active2]];
+  int $Variable[[Active3]];
   #endif
 )cpp",
   // Argument to 'sizeof...'



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] f15b786 - [clang-tidy] [clangd] Avoid multi-line diagnostic range for else-after-return diagnostic

2020-11-29 Thread Nathan Ridge via llvm-branch-commits

Author: Nathan Ridge
Date: 2020-11-29T18:32:23-05:00
New Revision: f15b7869e5afbd6c24ef440b0b62593e80fbd24f

URL: 
https://github.com/llvm/llvm-project/commit/f15b7869e5afbd6c24ef440b0b62593e80fbd24f
DIFF: 
https://github.com/llvm/llvm-project/commit/f15b7869e5afbd6c24ef440b0b62593e80fbd24f.diff

LOG: [clang-tidy] [clangd] Avoid multi-line diagnostic range for 
else-after-return diagnostic

Fixes https://bugs.llvm.org/show_bug.cgi?id=47809

Differential Revision: https://reviews.llvm.org/D92272

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
index 79e3cded45bc..89bb02e78cc6 100644
--- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
@@ -267,7 +267,8 @@ void ElseAfterReturnCheck::check(const 
MatchFinder::MatchResult &Result) {
   // If the if statement is the last statement its enclosing statements
   // scope, we can pull the decl out of the if statement.
   DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
-   << ControlFlowInterruptor;
+   << ControlFlowInterruptor
+   << SourceRange(ElseLoc);
   if (checkInitDeclUsageInElse(If) != nullptr) {
 Diag << tooling::fixit::createReplacement(
 SourceRange(If->getIfLoc()),
@@ -302,7 +303,8 @@ void ElseAfterReturnCheck::check(const 
MatchFinder::MatchResult &Result) {
   // If the if statement is the last statement its enclosing statements
   // scope, we can pull the decl out of the if statement.
   DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
-   << ControlFlowInterruptor;
+   << ControlFlowInterruptor
+   << SourceRange(ElseLoc);
   Diag << tooling::fixit::createReplacement(
   SourceRange(If->getIfLoc()),
   (tooling::fixit::getText(*If->getInit(), *Result.Context) +
@@ -319,7 +321,7 @@ void ElseAfterReturnCheck::check(const 
MatchFinder::MatchResult &Result) {
   }
 
   DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
-   << ControlFlowInterruptor;
+   << ControlFlowInterruptor << SourceRange(ElseLoc);
   removeElseAndBrackets(Diag, *Result.Context, Else, ElseLoc);
 }
 

diff  --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp 
b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index ba7029e54dbb..c6a14aeeb469 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -474,6 +474,24 @@ TEST(DiagnosticTest, ClangTidyNoLiteralDataInMacroToken) {
   EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre()); // no-crash
 }
 
+TEST(DiagnosticTest, ElseAfterReturnRange) {
+  Annotations Main(R"cpp(
+int foo(int cond) {
+if (cond == 1) {
+  return 42;
+} [[else]] if (cond == 2) {
+  return 43;
+}
+return 44;
+}
+  )cpp");
+  TestTU TU = TestTU::withCode(Main.code());
+  TU.ClangTidyProvider = addTidyChecks("llvm-else-after-return");
+  EXPECT_THAT(
+  TU.build().getDiagnostics(),
+  ElementsAre(Diag(Main.range(), "do not use 'else' after 'return'")));
+}
+
 TEST(DiagnosticsTest, Preprocessor) {
   // This looks like a preamble, but there's an #else in the middle!
   // Check that:



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] fef242c - [clangd] Fix locateMacroAt() for macro definition outside preamble

2020-12-13 Thread Nathan Ridge via llvm-branch-commits

Author: Nathan Ridge
Date: 2020-12-13T18:33:33-05:00
New Revision: fef242c32e833b84e8b46bd56a28c01c5f9aa65d

URL: 
https://github.com/llvm/llvm-project/commit/fef242c32e833b84e8b46bd56a28c01c5f9aa65d
DIFF: 
https://github.com/llvm/llvm-project/commit/fef242c32e833b84e8b46bd56a28c01c5f9aa65d.diff

LOG: [clangd] Fix locateMacroAt() for macro definition outside preamble

Fixes https://github.com/clangd/clangd/issues/577

Differential Revision: https://reviews.llvm.org/D91025

Added: 


Modified: 
clang-tools-extra/clangd/SourceCode.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/SourceCode.cpp 
b/clang-tools-extra/clangd/SourceCode.cpp
index 54248386d7b4..c0ccf2152750 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -975,17 +975,30 @@ llvm::Optional locateMacroAt(const 
syntax::Token &SpelledTok,
   if (!IdentifierInfo || !IdentifierInfo->hadMacroDefinition())
 return None;
 
-  // Get the definition just before the searched location so that a macro
-  // referenced in a '#undef MACRO' can still be found. Note that we only do
-  // that if Loc is not pointing at start of file.
-  if (SM.getLocForStartOfFile(SM.getFileID(Loc)) != Loc)
-Loc = Loc.getLocWithOffset(-1);
-  MacroDefinition MacroDef = PP.getMacroDefinitionAtLoc(IdentifierInfo, Loc);
-  if (auto *MI = MacroDef.getMacroInfo())
-return DefinedMacro{
-IdentifierInfo->getName(), MI,
-translatePreamblePatchLocation(MI->getDefinitionLoc(), SM)};
-  return None;
+  // We need to take special case to handle #define and #undef.
+  // Preprocessor::getMacroDefinitionAtLoc() only considers a macro
+  // definition to be in scope *after* the location of the macro name in a
+  // #define that introduces it, and *before* the location of the macro name
+  // in an #undef that undefines it. To handle these cases, we check for
+  // the macro being in scope either just after or just before the location
+  // of the token. In getting the location before, we also take care to check
+  // for start-of-file.
+  FileID FID = SM.getFileID(Loc);
+  assert(Loc != SM.getLocForEndOfFile(FID));
+  SourceLocation JustAfterToken = Loc.getLocWithOffset(1);
+  auto *MacroInfo =
+  PP.getMacroDefinitionAtLoc(IdentifierInfo, 
JustAfterToken).getMacroInfo();
+  if (!MacroInfo && SM.getLocForStartOfFile(FID) != Loc) {
+SourceLocation JustBeforeToken = Loc.getLocWithOffset(-1);
+MacroInfo = PP.getMacroDefinitionAtLoc(IdentifierInfo, JustBeforeToken)
+.getMacroInfo();
+  }
+  if (!MacroInfo) {
+return None;
+  }
+  return DefinedMacro{
+  IdentifierInfo->getName(), MacroInfo,
+  translatePreamblePatchLocation(MacroInfo->getDefinitionLoc(), SM)};
 }
 
 llvm::Expected Edit::apply() const {

diff  --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp 
b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index c3c87bd628bd..5b0ceb1cc200 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1624,6 +1624,14 @@ TEST(FindReferences, WithinAST) {
 }
   )cpp",
 
+  R"cpp(// Macro outside preamble
+int breakPreamble;
+#define [[MA^CRO]](X) (X+1)
+void test() {
+  int x = [[MACRO]]([[MACRO]](1));
+}
+  )cpp",
+
   R"cpp(
 int [[v^ar]] = 0;
 void foo(int s = [[var]]);



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang-tools-extra] [clang][Sema] Upstream HeuristicResolver from clangd (PR #121314)

2024-12-29 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/121314

Fixes https://github.com/llvm/llvm-project/issues/121310

>From 4a1f5a145dac353f2060e6d1d4b2eb2d231e3a5a Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Thu, 26 Dec 2024 00:40:48 -0500
Subject: [PATCH] [clang][Sema] Upstream HeuristicResolver from clangd

Fixes https://github.com/llvm/llvm-project/issues/121310
---
 clang-tools-extra/clangd/CMakeLists.txt| 1 -
 clang-tools-extra/clangd/FindTarget.cpp| 2 +-
 clang-tools-extra/clangd/FindTarget.h  | 4 +++-
 clang-tools-extra/clangd/InlayHints.cpp| 2 +-
 clang-tools-extra/clangd/ParsedAST.cpp | 2 +-
 clang-tools-extra/clangd/ParsedAST.h   | 2 +-
 clang-tools-extra/clangd/SemanticHighlighting.cpp  | 2 +-
 clang-tools-extra/clangd/XRefs.cpp | 2 +-
 clang-tools-extra/clangd/unittests/CMakeLists.txt  | 1 -
 .../include/clang/Sema}/HeuristicResolver.h| 7 ++-
 clang/lib/Sema/CMakeLists.txt  | 1 +
 .../clangd => clang/lib/Sema}/HeuristicResolver.cpp| 4 +---
 clang/unittests/Sema/CMakeLists.txt| 1 +
 .../unittests/Sema/HeuristicResolverTest.cpp   | 3 +--
 14 files changed, 15 insertions(+), 19 deletions(-)
 rename {clang-tools-extra/clangd => 
clang/include/clang/Sema}/HeuristicResolver.h (95%)
 rename {clang-tools-extra/clangd => clang/lib/Sema}/HeuristicResolver.cpp (99%)
 rename clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp => 
clang/unittests/Sema/HeuristicResolverTest.cpp (99%)

diff --git a/clang-tools-extra/clangd/CMakeLists.txt 
b/clang-tools-extra/clangd/CMakeLists.txt
index d797ddce8c44d1..6f10afe4a5625f 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -91,7 +91,6 @@ add_clang_library(clangDaemon STATIC
   GlobalCompilationDatabase.cpp
   Headers.cpp
   HeaderSourceSwitch.cpp
-  HeuristicResolver.cpp
   Hover.cpp
   IncludeCleaner.cpp
   IncludeFixer.cpp
diff --git a/clang-tools-extra/clangd/FindTarget.cpp 
b/clang-tools-extra/clangd/FindTarget.cpp
index e702c6b3537a09..04fd6d437b7bdd 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -8,7 +8,6 @@
 
 #include "FindTarget.h"
 #include "AST.h"
-#include "HeuristicResolver.h"
 #include "support/Logger.h"
 #include "clang/AST/ASTConcept.h"
 #include "clang/AST/ASTTypeTraits.h"
@@ -35,6 +34,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Specifiers.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
diff --git a/clang-tools-extra/clangd/FindTarget.h 
b/clang-tools-extra/clangd/FindTarget.h
index b41c5470951001..a7706804ce7ece 100644
--- a/clang-tools-extra/clangd/FindTarget.h
+++ b/clang-tools-extra/clangd/FindTarget.h
@@ -33,9 +33,11 @@
 #include 
 
 namespace clang {
-namespace clangd {
+
 class HeuristicResolver;
 
+namespace clangd {
+
 /// Describes the link between an AST node and a Decl it refers to.
 enum class DeclRelation : unsigned;
 /// A bitfield of DeclRelations.
diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index fefffeb4efc1a2..1b1bcf78c9855e 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -9,7 +9,6 @@
 #include "../clang-tidy/utils/DesignatedInitializers.h"
 #include "AST.h"
 #include "Config.h"
-#include "HeuristicResolver.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "SourceCode.h"
@@ -27,6 +26,7 @@
 #include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
diff --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index 725cbeb154cb84..89d6f26d0f150e 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -20,7 +20,6 @@
 #include "Feature.h"
 #include "FeatureModule.h"
 #include "Headers.h"
-#include "HeuristicResolver.h"
 #include "IncludeCleaner.h"
 #include "IncludeFixer.h"
 #include "Preamble.h"
@@ -53,6 +52,7 @@
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "clang/Serialization/ASTWriter.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Core/Diagnostic.h"
diff --git a/clang-tools-extra/clangd/ParsedAST.h 
b/clang-tools-extra/clangd/ParsedAST.h
index 8d9d1e64569267..82fac96360488e 100644
--- a/clang-tools-extra/clangd/ParsedAST.h
+++ b/clang-too

[llvm-branch-commits] [clang] [clang-tools-extra] [clang][Sema] Upstream HeuristicResolver from clangd (PR #121314)

2024-12-29 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

Depends on https://github.com/llvm/llvm-project/pull/121313

https://github.com/llvm/llvm-project/pull/121314
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][CodeComplete] Use HeuristicResolver to resolve pointee types (PR #121315)

2024-12-29 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/121315

Fixes https://github.com/clangd/clangd/issues/810

>From 5165ce906cb5ec9ecd913f69fc376b049ab803d6 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Thu, 26 Dec 2024 20:59:06 -0500
Subject: [PATCH] [clang][CodeComplete] Use HeuristicResolver to resolve
 pointee types

Fixes https://github.com/clangd/clangd/issues/810
---
 clang/include/clang/Sema/SemaCodeCompletion.h |  2 ++
 clang/lib/Sema/SemaCodeComplete.cpp   | 15 ++-
 clang/test/CodeCompletion/member-access.cpp   | 17 +
 3 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Sema/SemaCodeCompletion.h 
b/clang/include/clang/Sema/SemaCodeCompletion.h
index 50409439389b06..e931596c215d31 100644
--- a/clang/include/clang/Sema/SemaCodeCompletion.h
+++ b/clang/include/clang/Sema/SemaCodeCompletion.h
@@ -23,6 +23,7 @@
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/Designator.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "clang/Sema/Ownership.h"
 #include "clang/Sema/SemaBase.h"
 #include "llvm/ADT/StringRef.h"
@@ -43,6 +44,7 @@ class SemaCodeCompletion : public SemaBase {
 
   /// Code-completion consumer.
   CodeCompleteConsumer *CodeCompleter;
+  HeuristicResolver Resolver;
 
   /// Describes the context in which code completion occurs.
   enum ParserCompletionContext {
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 1f398bb004fa30..2b07f20da82683 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -34,6 +34,7 @@
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/Designator.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Overload.h"
 #include "clang/Sema/ParsedAttr.h"
@@ -5862,8 +5863,10 @@ void SemaCodeCompletion::CodeCompleteMemberReferenceExpr(
   enum CodeCompletionContext::Kind contextKind;
 
   if (IsArrow) {
-if (const auto *Ptr = ConvertedBaseType->getAs())
-  ConvertedBaseType = Ptr->getPointeeType();
+if (const auto *PointeeType =
+Resolver.getPointeeType(ConvertedBaseType.getTypePtr())) {
+  ConvertedBaseType = QualType(PointeeType, 0);
+}
   }
 
   if (IsArrow) {
@@ -5900,8 +5903,9 @@ void SemaCodeCompletion::CodeCompleteMemberReferenceExpr(
 ExprValueKind BaseKind = Base->getValueKind();
 
 if (IsArrow) {
-  if (const PointerType *Ptr = BaseType->getAs()) {
-BaseType = Ptr->getPointeeType();
+  if (const auto *PointeeType =
+  Resolver.getPointeeType(BaseType.getTypePtr())) {
+BaseType = QualType(PointeeType, 0);
 BaseKind = VK_LValue;
   } else if (BaseType->isObjCObjectPointerType() ||
  BaseType->isTemplateTypeParmType()) {
@@ -10473,4 +10477,5 @@ void SemaCodeCompletion::GatherGlobalCodeCompletions(
 
 SemaCodeCompletion::SemaCodeCompletion(Sema &S,
CodeCompleteConsumer 
*CompletionConsumer)
-: SemaBase(S), CodeCompleter(CompletionConsumer) {}
+: SemaBase(S), CodeCompleter(CompletionConsumer),
+  Resolver(S.getASTContext()) {}
diff --git a/clang/test/CodeCompletion/member-access.cpp 
b/clang/test/CodeCompletion/member-access.cpp
index 912f269db6c1ac..ab6dc69bf2923d 100644
--- a/clang/test/CodeCompletion/member-access.cpp
+++ b/clang/test/CodeCompletion/member-access.cpp
@@ -384,3 +384,20 @@ void Foo() {
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:382:5 %s -o - | 
FileCheck -check-prefix=CHECK-DEREF-DEPENDENT %s
 // CHECK-DEREF-DEPENDENT: [#void#]Add()
 }
+
+namespace dependent_smart_pointer {
+template 
+struct smart_pointer {
+  T* operator->();
+};
+
+template 
+struct node {
+  smart_pointer> next;
+  void foo() {
+next->next;
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:398:11 %s -o - | 
FileCheck -check-prefix=CHECK-DEPENDENT-SMARTPTR %s
+// CHECK-DEPENDENT-SMARTPTR: [#smart_pointer>#]next
+  }
+};
+}

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][CodeComplete] Use HeuristicResolver to resolve pointee types (PR #121315)

2024-12-29 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

Depends on https://github.com/llvm/llvm-project/pull/121314

https://github.com/llvm/llvm-project/pull/121315
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][HeuristicResolver] Additional hardening against an infinite loop in simplifyType() (PR #126690)

2025-02-10 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

This is not needed to fix https://github.com/llvm/llvm-project/issues/126536 
(https://github.com/llvm/llvm-project/pull/126689 does that), it's a hedge 
against additional bugs that may be lurking that cause infinite loops.

I'm open to suggestions as to whether this is a good idea. It may hide some 
bugs, but the symptoms of those bugs are much less severe (incorrect or failed 
heuristic resolution of a dependent name in a template) than an infinite loop.

https://github.com/llvm/llvm-project/pull/126690
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][HeuristicResolver] Additional hardening against an infinite loop in simplifyType() (PR #126690)

2025-02-10 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/126690

None

>From 28630abecc42c23527687b84be8cb4dbcd2ca5d9 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Tue, 11 Feb 2025 02:06:32 -0500
Subject: [PATCH] [clang][HeuristicResolver] Additional hardening against an
 infinite loop in simplifyType()

---
 clang/lib/Sema/HeuristicResolver.cpp | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/HeuristicResolver.cpp 
b/clang/lib/Sema/HeuristicResolver.cpp
index 3cbf33dcdced38..adce403412f689 100644
--- a/clang/lib/Sema/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -258,7 +258,11 @@ QualType HeuristicResolverImpl::simplifyType(QualType 
Type, const Expr *E,
 }
 return T;
   };
-  while (!Current.Type.isNull()) {
+  // As an additional protection against infinite loops, bound the number of
+  // simplification steps.
+  size_t StepCount = 0;
+  const size_t MaxSteps = 64;
+  while (!Current.Type.isNull() && StepCount++ < MaxSteps) {
 TypeExprPair New = SimplifyOneStep(Current);
 if (New.Type == Current.Type)
   break;

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][HeuristicResolver] Additional hardening against an infinite loop in simplifyType() (PR #126690)

2025-02-11 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

> and cherry picking it into the 20 release

The regressing change, which introduced the `simplifyType()` function, isn't 
present on the llvm 20 branch (it landed a bit after the branch cut). So there 
should not be a need to cherry-pick the fix onto the llvm 20 branch either.



https://github.com/llvm/llvm-project/pull/126690
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][CodeComplete] Use HeuristicResolver to resolve DependentNamTypes (PR #123818)

2025-01-21 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/123818

Fixes https://github.com/clangd/clangd/issues/1249

>From 58029449d63af7f452820dd02aba0d10134f588c Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Tue, 21 Jan 2025 15:56:27 -0500
Subject: [PATCH] [clang][CodeComplete] Use HeuristicResolver to resolve
 DependentNameTypes

Fixes https://github.com/clangd/clangd/issues/1249
---
 clang/lib/Sema/SemaCodeComplete.cpp | 25 +++--
 clang/test/CodeCompletion/member-access.cpp | 16 +
 2 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 69cda6e68bd36b..d349928e1a171b 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -5736,11 +5736,20 @@ class ConceptInfo {
 // In particular, when E->getType() is DependentTy, try to guess a likely type.
 // We accept some lossiness (like dropping parameters).
 // We only try to handle common expressions on the LHS of MemberExpr.
-QualType getApproximateType(const Expr *E) {
+QualType getApproximateType(const Expr *E, HeuristicResolver &Resolver) {
   if (E->getType().isNull())
 return QualType();
   E = E->IgnoreParenImpCasts();
   QualType Unresolved = E->getType();
+  // Resolve DependentNameType
+  if (const auto *DNT = Unresolved->getAs()) {
+auto Decls = Resolver.resolveDependentNameType(DNT);
+if (Decls.size() == 1) {
+  if (const auto *TD = dyn_cast(Decls[0])) {
+return QualType(TD->getTypeForDecl(), 0);
+  }
+}
+  }
   // We only resolve DependentTy, or undeduced autos (including auto* etc).
   if (!Unresolved->isSpecificBuiltinType(BuiltinType::Dependent)) {
 AutoType *Auto = Unresolved->getContainedAutoType();
@@ -5749,7 +5758,7 @@ QualType getApproximateType(const Expr *E) {
   }
   // A call: approximate-resolve callee to a function type, get its return type
   if (const CallExpr *CE = llvm::dyn_cast(E)) {
-QualType Callee = getApproximateType(CE->getCallee());
+QualType Callee = getApproximateType(CE->getCallee(), Resolver);
 if (Callee.isNull() ||
 Callee->isSpecificPlaceholderType(BuiltinType::BoundMember))
   Callee = Expr::findBoundMemberType(CE->getCallee());
@@ -5792,7 +5801,7 @@ QualType getApproximateType(const Expr *E) {
   if (const auto *CDSME = llvm::dyn_cast(E)) {
 QualType Base = CDSME->isImplicitAccess()
 ? CDSME->getBaseType()
-: getApproximateType(CDSME->getBase());
+: getApproximateType(CDSME->getBase(), Resolver);
 if (CDSME->isArrow() && !Base.isNull())
   Base = Base->getPointeeType(); // could handle unique_ptr etc here?
 auto *RD =
@@ -5813,14 +5822,15 @@ QualType getApproximateType(const Expr *E) {
   if (const auto *DRE = llvm::dyn_cast(E)) {
 if (const auto *VD = llvm::dyn_cast(DRE->getDecl())) {
   if (VD->hasInit())
-return getApproximateType(VD->getInit());
+return getApproximateType(VD->getInit(), Resolver);
 }
   }
   if (const auto *UO = llvm::dyn_cast(E)) {
 if (UO->getOpcode() == UnaryOperatorKind::UO_Deref) {
   // We recurse into the subexpression because it could be of dependent
   // type.
-  if (auto Pointee = 
getApproximateType(UO->getSubExpr())->getPointeeType();
+  if (auto Pointee =
+  getApproximateType(UO->getSubExpr(), Resolver)->getPointeeType();
   !Pointee.isNull())
 return Pointee;
   // Our caller expects a non-null result, even though the SubType is
@@ -5857,7 +5867,8 @@ void SemaCodeCompletion::CodeCompleteMemberReferenceExpr(
   SemaRef.PerformMemberExprBaseConversion(Base, IsArrow);
   if (ConvertedBase.isInvalid())
 return;
-  QualType ConvertedBaseType = getApproximateType(ConvertedBase.get());
+  QualType ConvertedBaseType =
+  getApproximateType(ConvertedBase.get(), Resolver);
 
   enum CodeCompletionContext::Kind contextKind;
 
@@ -5896,7 +5907,7 @@ void SemaCodeCompletion::CodeCompleteMemberReferenceExpr(
   return false;
 Base = ConvertedBase.get();
 
-QualType BaseType = getApproximateType(Base);
+QualType BaseType = getApproximateType(Base, Resolver);
 if (BaseType.isNull())
   return false;
 ExprValueKind BaseKind = Base->getValueKind();
diff --git a/clang/test/CodeCompletion/member-access.cpp 
b/clang/test/CodeCompletion/member-access.cpp
index ab6dc69bf2923d..bf35f7ad021f71 100644
--- a/clang/test/CodeCompletion/member-access.cpp
+++ b/clang/test/CodeCompletion/member-access.cpp
@@ -401,3 +401,19 @@ struct node {
   }
 };
 }
+
+namespace dependent_nested_class {
+template 
+struct Foo {
+  struct Bar {
+int field;
+  };
+};
+template 
+void f() {
+  typename Foo::Bar bar;
+  bar.field;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:415:7 %s -o - | 
FileCheck -check-prefix=CHECK-DEPENDENT-NESTEDCLASS %s
+  // CHEC

[llvm-branch-commits] [clang] [clang][CodeComplete] Use HeuristicResolver to resolve DependentNameTypes (PR #123818)

2025-01-21 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 edited 
https://github.com/llvm/llvm-project/pull/123818
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][CodeComplete] Use HeuristicResolver to resolve pointee types (PR #121315)

2024-12-29 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

The buildkite run shows the test `Clang.Index/complete-memfunc-cvquals.cpp` 
failing.

This made me realize that `HeuristicResolver::getPointeeType()` actually has a 
deficiency where it incorrectly discards the cv-qualifiers of the returned 
pointee type. I'll fix that in a dependent patch before proceeding with this.

https://github.com/llvm/llvm-project/pull/121315
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/20.x: [clang][AST] Handle dependent representation of call to function with explicit object parameter in CallExpr::getBeginLoc() (#126868) (PR #127148)

2025-02-14 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

> @HighCommander4 (or anyone else). If you would like to add a note about this 
> fix in the release notes (completely optional). Please reply to this comment 
> with a one or two sentence description of the fix. When you are done, please 
> add the release:note label to this PR.

No release note needed here, as this is a fix for a regression introduced in 
llvm 20. Since it's also being fixed in llvm 20, no user of a release version 
will ever experience this crash.

https://github.com/llvm/llvm-project/pull/127148
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] [clangd] Add clangd 20 release notes (PR #127358)

2025-02-15 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/127358

None

>From 77080f896293c948d9c87c8ce47df38ca81c2090 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Sat, 15 Feb 2025 01:30:48 -0500
Subject: [PATCH] [clangd] Add clangd 20 release notes

---
 clang-tools-extra/docs/ReleaseNotes.rst | 56 +++--
 1 file changed, 53 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index cc5f64a3f9fa3..35de182ceddf4 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -56,7 +56,8 @@ Improvements to clangd
 Inlay hints
 ^^^
 
-- Added `DefaultArguments` Inlay Hints option.
+- Added support for inlay hints for default arguments, enabled using the
+  `DefaultArguments` config option (#GH95712)
 
 Diagnostics
 ^^^
@@ -67,21 +68,45 @@ Semantic Highlighting
 Compile flags
 ^
 
+- Fixed a bug where clangd would unnecessarily reparse open files whose
+  compile command did not change when receiving a new compile command
+  via an LSP `workspace/configuration` request (#GH115438)
+
 Hover
 ^
 
+- Hovering over a function name now shows the function's documentation
+  comment even if the comment is written above the function's out-of-line
+  definition in a different source file (#GH67802)
+
 Code completion
 ^^^
 
+- Added an `ArgumentLists` config option under `Completion`. This is a more
+  flexible version of the `--function-arg-placeholders` command line flag,
+  allowing users more detailed control of what is inserted in argument list
+  position when clangd completes the name of a function in a function call
+  context. (#GH111322)
+- Clangd now supports configuring which headers should be inserted using 
+  `<>` vs. `""` syntax using the `QuotedHeaders` and `AngledHeaders` config
+  options under `Style` (#GH67749)
 - Added completion for C++20 keywords.
+- Clangd's `HeuristicResolver` component was upstreamed to `libSema` where
+  code completion can take advantage of it, resulting in improved code
+  completion in templated code
+- Code completion proposals for symbols defined in included headers now
+  include documentation comments (#GH120099)
 
 Code actions
 
 
 - Added `Swap operands` tweak for certain binary operators.
-
 - Improved the extract-to-function code action to allow extracting statements
   with overloaded operators like ``<<`` of ``std::ostream``.
+- `Define outline` now handles member functions of class templates, and
+  member function templates.
+- `Extract variable` can now operate on the top-level expression in an
+  expression statement (#GH112525)
 
 Signature help
 ^^
@@ -89,13 +114,38 @@ Signature help
 Cross-references
 
 
+- Clangd now supports the "outgoing calls" direction of call hierarchy
+  (#GH77556)
+- Call hierarchy can now be invoked on fields and namespace-scope
+  variables (#GH113900)
+- Improved heuristics for filtering out generated Protobuf symbol names
+  during indexing (#GH110091)
+- Compiler intrinsics defined in `*intrin.h` system headers are now
+  indexed even if they have reserved names (#GH119735)
+- Various improvements to go-to-definition in templated code
+
 Objective-C
 ^^^
 
+Clang-tidy integration
+^^
+
+- Improved robustness in handling clang-tidy check names (#GH109421)
+
+C++20 Modules Support
+^
+
+- Support code completion for symbols defined in modules (#GH110083)
+- Improve performance when opening files that import modules (#GH106683)
+- Compile commands for modules now respect modifications specified in `.clangd`
+  files (#GH122606)
+
 Miscellaneous
 ^
 
-- The DefineOutline tweak now handles member functions of class templates.
+- Fixed an OOM affecting some versions of libcxx headers compiled in C++20
+  mode (#GH108866)
+- Various other stability improvements, e.g. crash fixes
 
 Improvements to clang-doc
 -

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] [clangd] Add clangd 20 release notes (PR #127358)

2025-02-15 Thread Nathan Ridge via llvm-branch-commits


@@ -67,35 +68,84 @@ Semantic Highlighting
 Compile flags
 ^
 
+- Fixed a bug where clangd would unnecessarily reparse open files whose
+  compile command did not change when receiving a new compile command
+  via an LSP `workspace/configuration` request (#GH115438)
+
 Hover
 ^
 
+- Hovering over a function name now shows the function's documentation
+  comment even if the comment is written above the function's out-of-line
+  definition in a different source file (#GH67802)
+
 Code completion
 ^^^
 
+- Added an `ArgumentLists` config option under `Completion`. This is a more
+  flexible version of the `--function-arg-placeholders` command line flag,
+  allowing users more detailed control of what is inserted in argument list
+  position when clangd completes the name of a function in a function call
+  context. (#GH111322)
+- Clangd now supports configuring which headers should be inserted using 
+  `<>` vs. `""` syntax using the `QuotedHeaders` and `AngledHeaders` config
+  options under `Style` (#GH67749)
 - Added completion for C++20 keywords.
+- Clangd's `HeuristicResolver` component was upstreamed to `libSema` where
+  code completion can take advantage of it, resulting in improved code
+  completion in templated code
+- Code completion proposals for symbols defined in included headers now
+  include documentation comments (#GH120099)
 
 Code actions
 
 
 - Added `Swap operands` tweak for certain binary operators.
-
 - Improved the extract-to-function code action to allow extracting statements
   with overloaded operators like ``<<`` of ``std::ostream``.
+- `Define outline` now handles member functions of class templates, and
+  member function templates.
+- `Extract variable` can now operate on the top-level expression in an
+  expression statement (#GH112525)
 
 Signature help
 ^^
 
 Cross-references
 
 
+- Clangd now supports the "outgoing calls" direction of call hierarchy
+  (#GH77556)
+- Call hierarchy can now be invoked on fields and namespace-scope
+  variables (#GH113900)
+- Improved heuristics for filtering out generated Protobuf symbol names
+  during indexing (#GH110091)
+- Compiler intrinsics defined in `*intrin.h` system headers are now
+  indexed even if they have reserved names (#GH119735)
+- Various improvements to go-to-definition in templated code
+
 Objective-C
 ^^^
 
+Clang-tidy integration
+^^
+
+- Improved robustness in handling clang-tidy check names (#GH109421)
+
+C++20 Modules Support

HighCommander4 wrote:

@ChuanqiXu9 I would appreciate if you could look over this section in 
particular. I added entries for the modules-related commits that seemed notable 
to me, but I'm definitely happy to add other entries / add more details / 
adjust wording etc.

https://github.com/llvm/llvm-project/pull/127358
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] [clangd] Add clangd 20 release notes (PR #127358)

2025-02-15 Thread Nathan Ridge via llvm-branch-commits


@@ -67,35 +68,84 @@ Semantic Highlighting
 Compile flags
 ^
 
+- Fixed a bug where clangd would unnecessarily reparse open files whose
+  compile command did not change when receiving a new compile command
+  via an LSP `workspace/configuration` request (#GH115438)
+
 Hover
 ^
 
+- Hovering over a function name now shows the function's documentation
+  comment even if the comment is written above the function's out-of-line
+  definition in a different source file (#GH67802)
+
 Code completion
 ^^^
 
+- Added an `ArgumentLists` config option under `Completion`. This is a more
+  flexible version of the `--function-arg-placeholders` command line flag,
+  allowing users more detailed control of what is inserted in argument list
+  position when clangd completes the name of a function in a function call
+  context. (#GH111322)
+- Clangd now supports configuring which headers should be inserted using 
+  `<>` vs. `""` syntax using the `QuotedHeaders` and `AngledHeaders` config
+  options under `Style` (#GH67749)
 - Added completion for C++20 keywords.
+- Clangd's `HeuristicResolver` component was upstreamed to `libSema` where
+  code completion can take advantage of it, resulting in improved code
+  completion in templated code
+- Code completion proposals for symbols defined in included headers now
+  include documentation comments (#GH120099)
 
 Code actions
 
 
 - Added `Swap operands` tweak for certain binary operators.
-
 - Improved the extract-to-function code action to allow extracting statements
   with overloaded operators like ``<<`` of ``std::ostream``.
+- `Define outline` now handles member functions of class templates, and
+  member function templates.
+- `Extract variable` can now operate on the top-level expression in an
+  expression statement (#GH112525)
 
 Signature help
 ^^
 
 Cross-references
 
 
+- Clangd now supports the "outgoing calls" direction of call hierarchy
+  (#GH77556)
+- Call hierarchy can now be invoked on fields and namespace-scope
+  variables (#GH113900)
+- Improved heuristics for filtering out generated Protobuf symbol names
+  during indexing (#GH110091)
+- Compiler intrinsics defined in `*intrin.h` system headers are now
+  indexed even if they have reserved names (#GH119735)
+- Various improvements to go-to-definition in templated code
+
 Objective-C
 ^^^
 
+Clang-tidy integration
+^^
+
+- Improved robustness in handling clang-tidy check names (#GH109421)
+
+C++20 Modules Support

HighCommander4 wrote:

@ChuanqiXu9 and a follow-up question, do you think we should make any update to 
https://clangd.llvm.org/features#experimental-c20-modules-support for clangd 20?

https://github.com/llvm/llvm-project/pull/127358
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang-tools-extra] [clang][HeuristicResolver] Apply default argument heuristic in resolveDeclRefExpr as well (PR #132576)

2025-03-22 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/132576

None

>From ea949861a4b03123d7784fe5ef3bc1fe2f3cf2cd Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Sat, 22 Mar 2025 20:54:02 -0400
Subject: [PATCH] [clang][HeuristicResolver] Apply default argument heuristic
 in resolveDeclRefExpr as well

---
 .../clangd/unittests/XRefsTests.cpp |  2 +-
 clang/lib/Sema/HeuristicResolver.cpp|  6 +++---
 clang/unittests/Sema/HeuristicResolverTest.cpp  | 17 +
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp 
b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index e12d7691c58fb..693e965e78a96 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1091,7 +1091,7 @@ TEST(LocateSymbol, All) {
   )objc",
   R"cpp(
 struct PointerIntPairInfo {
-  static void *getPointer(void *Value);
+  static void *$decl[[getPointer]](void *Value);
 };
 
 template  struct PointerIntPair {
diff --git a/clang/lib/Sema/HeuristicResolver.cpp 
b/clang/lib/Sema/HeuristicResolver.cpp
index d377379c627db..5f1495f5334b9 100644
--- a/clang/lib/Sema/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -300,9 +300,9 @@ std::vector 
HeuristicResolverImpl::resolveMemberExpr(
 
 std::vector
 HeuristicResolverImpl::resolveDeclRefExpr(const DependentScopeDeclRefExpr *RE) 
{
-  return resolveDependentMember(
-  resolveNestedNameSpecifierToType(RE->getQualifier()), RE->getDeclName(),
-  StaticFilter);
+  QualType Qualifier = resolveNestedNameSpecifierToType(RE->getQualifier());
+  Qualifier = simplifyType(Qualifier, nullptr, /*UnwrapPointer=*/false);
+  return resolveDependentMember(Qualifier, RE->getDeclName(), StaticFilter);
 }
 
 std::vector
diff --git a/clang/unittests/Sema/HeuristicResolverTest.cpp 
b/clang/unittests/Sema/HeuristicResolverTest.cpp
index c7cfe7917c532..b4994c315b2ff 100644
--- a/clang/unittests/Sema/HeuristicResolverTest.cpp
+++ b/clang/unittests/Sema/HeuristicResolverTest.cpp
@@ -429,6 +429,23 @@ TEST(HeuristicResolver, DeclRefExpr_StaticMethod) {
   cxxMethodDecl(hasName("bar")).bind("output"));
 }
 
+TEST(HeuristicResolver, DeclRefExpr_DefaultTemplateArgument) {
+  std::string Code = R"cpp(
+struct Default {
+  static void foo();
+};
+template 
+void bar() {
+  T::foo();
+}
+  )cpp";
+  // Test resolution of "foo" in "T::foo()".
+  expectResolution(
+  Code, &HeuristicResolver::resolveDeclRefExpr,
+  dependentScopeDeclRefExpr(hasDependentName("foo")).bind("input"),
+  cxxMethodDecl(hasName("foo")).bind("output"));
+}
+
 TEST(HeuristicResolver, DeclRefExpr_StaticOverloads) {
   std::string Code = R"cpp(
 template 

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang-tools-extra] [clang][HeuristicResolver] Apply default argument heuristic in resolveDeclRefExpr as well (PR #132576)

2025-03-22 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

This is a follow-up to https://github.com/llvm/llvm-project/pull/131074. After 
moving the default argument heuristic to `simplifyType` as per [this 
discussion](https://github.com/llvm/llvm-project/pull/131074#discussion_r2006918564),
 I realized that this made it no longer apply to the 
`DependentScopeDeclRefExpr` case, because that wasn't using `simplifyType`.

This patch fixes that, with an added testcase.

https://github.com/llvm/llvm-project/pull/132576
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang-tools-extra] [clang][HeuristicResolver] Default argument heuristic for template parameters (PR #131074)

2025-03-20 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/131074

>From 9530a2186f46fa852021a67c17d06085360d5b9c Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Thu, 13 Mar 2025 01:23:03 -0400
Subject: [PATCH] [clang][HeuristicResolver] Default argument heuristic for
 template parameters

---
 .../clangd/unittests/XRefsTests.cpp   |  2 +-
 clang/lib/Sema/HeuristicResolver.cpp  | 17 ++
 .../unittests/Sema/HeuristicResolverTest.cpp  | 34 +++
 3 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp 
b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index e12d7691c58fb..693e965e78a96 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1091,7 +1091,7 @@ TEST(LocateSymbol, All) {
   )objc",
   R"cpp(
 struct PointerIntPairInfo {
-  static void *getPointer(void *Value);
+  static void *$decl[[getPointer]](void *Value);
 };
 
 template  struct PointerIntPair {
diff --git a/clang/lib/Sema/HeuristicResolver.cpp 
b/clang/lib/Sema/HeuristicResolver.cpp
index d377379c627db..7c88a3097a044 100644
--- a/clang/lib/Sema/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -11,7 +11,9 @@
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/TemplateBase.h"
 #include "clang/AST/Type.h"
+#include "llvm/Support/Casting.h"
 
 namespace clang {
 
@@ -122,6 +124,7 @@ TemplateName getReferencedTemplateName(const Type *T) {
 // resolves it to a CXXRecordDecl in which we can try name lookup.
 TagDecl *HeuristicResolverImpl::resolveTypeToTagDecl(QualType QT) {
   const Type *T = QT.getTypePtrOrNull();
+
   if (!T)
 return nullptr;
 
@@ -245,6 +248,20 @@ QualType HeuristicResolverImpl::simplifyType(QualType 
Type, const Expr *E,
 }
   }
 }
+if (const auto *TTPT = dyn_cast_if_present(T.Type)) {
+  // We can't do much useful with a template parameter (e.g. we cannot look
+  // up member names inside it). However, if the template parameter has a
+  // default argument, as a heuristic we can replace T with the default
+  // argument type.
+  if (const auto *TTPD = TTPT->getDecl()) {
+if (TTPD->hasDefaultArgument()) {
+  const auto &DefaultArg = TTPD->getDefaultArgument().getArgument();
+  if (DefaultArg.getKind() == TemplateArgument::Type) {
+return {DefaultArg.getAsType()};
+  }
+}
+  }
+}
 return T;
   };
   // As an additional protection against infinite loops, bound the number of
diff --git a/clang/unittests/Sema/HeuristicResolverTest.cpp 
b/clang/unittests/Sema/HeuristicResolverTest.cpp
index c7cfe7917c532..f7eb4b23c2ab0 100644
--- a/clang/unittests/Sema/HeuristicResolverTest.cpp
+++ b/clang/unittests/Sema/HeuristicResolverTest.cpp
@@ -410,6 +410,40 @@ TEST(HeuristicResolver, MemberExpr_HangIssue126536) {
   cxxDependentScopeMemberExpr(hasMemberName("foo")).bind("input"));
 }
 
+TEST(HeuristicResolver, MemberExpr_DefaultTemplateArgument) {
+  std::string Code = R"cpp(
+struct Default {
+  void foo();
+};
+template 
+void bar(T t) {
+  t.foo();
+}
+  )cpp";
+  // Test resolution of "foo" in "t.foo()".
+  expectResolution(
+  Code, &HeuristicResolver::resolveMemberExpr,
+  cxxDependentScopeMemberExpr(hasMemberName("foo")).bind("input"),
+  cxxMethodDecl(hasName("foo")).bind("output"));
+}
+
+TEST(HeuristicResolver, MemberExpr_DefaultTemplateArgument_Recursive) {
+  std::string Code = R"cpp(
+struct Default {
+  void foo();
+};
+template 
+void bar(T t) {
+  t.foo();
+}
+  )cpp";
+  // Test resolution of "foo" in "t.foo()".
+  expectResolution(
+  Code, &HeuristicResolver::resolveMemberExpr,
+  cxxDependentScopeMemberExpr(hasMemberName("foo")).bind("input"),
+  cxxMethodDecl(hasName("foo")).bind("output"));
+}
+
 TEST(HeuristicResolver, DeclRefExpr_StaticMethod) {
   std::string Code = R"cpp(
 template 

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][HeuristicResolver] Default argument heuristic for template parameters (PR #131074)

2025-03-21 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

Resubmitted at https://github.com/llvm/llvm-project/pull/132465

https://github.com/llvm/llvm-project/pull/131074
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][HeuristicResolver] Default argument heuristic for template parameters (PR #131074)

2025-03-21 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

> @HighCommander4 did you merge it into a wrong branch?

Oops. I forgot that the patch was stacked on top of another patch for 
https://github.com/llvm/llvm-project/issues/130468.

I will resubmit and reland.

https://github.com/llvm/llvm-project/pull/131074
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][HeuristicResolver] Default argument heuristic for template parameters (PR #131074)

2025-03-21 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 closed 
https://github.com/llvm/llvm-project/pull/131074
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][HeuristicResolver] Default argument heuristic for template parameters (PR #131074)

2025-04-05 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/131074

>From 556926d2644160405958a5d01963714f97ab522e Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Thu, 13 Mar 2025 01:23:03 -0400
Subject: [PATCH] [clang][HeuristicResolver] Default argument heuristic for
 template parameters

---
 clang/lib/Sema/HeuristicResolver.cpp  | 17 ++
 .../unittests/Sema/HeuristicResolverTest.cpp  | 34 +++
 2 files changed, 51 insertions(+)

diff --git a/clang/lib/Sema/HeuristicResolver.cpp 
b/clang/lib/Sema/HeuristicResolver.cpp
index d377379c627db..7c88a3097a044 100644
--- a/clang/lib/Sema/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -11,7 +11,9 @@
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/TemplateBase.h"
 #include "clang/AST/Type.h"
+#include "llvm/Support/Casting.h"
 
 namespace clang {
 
@@ -122,6 +124,7 @@ TemplateName getReferencedTemplateName(const Type *T) {
 // resolves it to a CXXRecordDecl in which we can try name lookup.
 TagDecl *HeuristicResolverImpl::resolveTypeToTagDecl(QualType QT) {
   const Type *T = QT.getTypePtrOrNull();
+
   if (!T)
 return nullptr;
 
@@ -245,6 +248,20 @@ QualType HeuristicResolverImpl::simplifyType(QualType 
Type, const Expr *E,
 }
   }
 }
+if (const auto *TTPT = dyn_cast_if_present(T.Type)) {
+  // We can't do much useful with a template parameter (e.g. we cannot look
+  // up member names inside it). However, if the template parameter has a
+  // default argument, as a heuristic we can replace T with the default
+  // argument type.
+  if (const auto *TTPD = TTPT->getDecl()) {
+if (TTPD->hasDefaultArgument()) {
+  const auto &DefaultArg = TTPD->getDefaultArgument().getArgument();
+  if (DefaultArg.getKind() == TemplateArgument::Type) {
+return {DefaultArg.getAsType()};
+  }
+}
+  }
+}
 return T;
   };
   // As an additional protection against infinite loops, bound the number of
diff --git a/clang/unittests/Sema/HeuristicResolverTest.cpp 
b/clang/unittests/Sema/HeuristicResolverTest.cpp
index c7cfe7917c532..f7eb4b23c2ab0 100644
--- a/clang/unittests/Sema/HeuristicResolverTest.cpp
+++ b/clang/unittests/Sema/HeuristicResolverTest.cpp
@@ -410,6 +410,40 @@ TEST(HeuristicResolver, MemberExpr_HangIssue126536) {
   cxxDependentScopeMemberExpr(hasMemberName("foo")).bind("input"));
 }
 
+TEST(HeuristicResolver, MemberExpr_DefaultTemplateArgument) {
+  std::string Code = R"cpp(
+struct Default {
+  void foo();
+};
+template 
+void bar(T t) {
+  t.foo();
+}
+  )cpp";
+  // Test resolution of "foo" in "t.foo()".
+  expectResolution(
+  Code, &HeuristicResolver::resolveMemberExpr,
+  cxxDependentScopeMemberExpr(hasMemberName("foo")).bind("input"),
+  cxxMethodDecl(hasName("foo")).bind("output"));
+}
+
+TEST(HeuristicResolver, MemberExpr_DefaultTemplateArgument_Recursive) {
+  std::string Code = R"cpp(
+struct Default {
+  void foo();
+};
+template 
+void bar(T t) {
+  t.foo();
+}
+  )cpp";
+  // Test resolution of "foo" in "t.foo()".
+  expectResolution(
+  Code, &HeuristicResolver::resolveMemberExpr,
+  cxxDependentScopeMemberExpr(hasMemberName("foo")).bind("input"),
+  cxxMethodDecl(hasName("foo")).bind("output"));
+}
+
 TEST(HeuristicResolver, DeclRefExpr_StaticMethod) {
   std::string Code = R"cpp(
 template 

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang-tools-extra] [clang][HeuristicResolver] Default argument heuristic for template parameters (PR #131074)

2025-04-05 Thread Nathan Ridge via llvm-branch-commits


@@ -125,6 +126,20 @@ TagDecl 
*HeuristicResolverImpl::resolveTypeToTagDecl(QualType QT) {
   if (!T)
 return nullptr;
 
+  // If T is the type of a template parameter, we can't get a useful TagDecl
+  // out of it. However, if the template parameter has a default argument,
+  // as a heuristic we can replace T with the default argument type.
+  if (const auto *TTPT = dyn_cast(T)) {
+if (const auto *TTPD = TTPT->getDecl()) {
+  if (TTPD->hasDefaultArgument()) {
+const auto &DefaultArg = TTPD->getDefaultArgument().getArgument();
+if (DefaultArg.getKind() == TemplateArgument::Type) {
+  T = DefaultArg.getAsType().getTypePtrOrNull();

HighCommander4 wrote:

Thanks for the added testcases!

The recursive case made me realize that application of this heuristic is 
probably better done in `simplifyType`. I updated the patch and added the 
testcase.

For the template template parameter case, I agree that it would be nice to make 
this work as well, but I'd rather leave that to a follow-up patch.

https://github.com/llvm/llvm-project/pull/131074
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang-tools-extra] [clang][HeuristicResolver] Default argument heuristic for template parameters (PR #131074)

2025-03-13 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/131074

>From aeeb8f20927850b11c66110021fe404576ff084f Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Thu, 13 Mar 2025 01:23:03 -0400
Subject: [PATCH] [clang][HeuristicResolver] Default argument heuristic for
 template parameters

---
 .../clangd/unittests/XRefsTests.cpp |  2 +-
 clang/lib/Sema/HeuristicResolver.cpp| 15 +++
 clang/unittests/Sema/HeuristicResolverTest.cpp  | 17 +
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp 
b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index e12d7691c58fb..693e965e78a96 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1091,7 +1091,7 @@ TEST(LocateSymbol, All) {
   )objc",
   R"cpp(
 struct PointerIntPairInfo {
-  static void *getPointer(void *Value);
+  static void *$decl[[getPointer]](void *Value);
 };
 
 template  struct PointerIntPair {
diff --git a/clang/lib/Sema/HeuristicResolver.cpp 
b/clang/lib/Sema/HeuristicResolver.cpp
index d377379c627db..feda9696b8e05 100644
--- a/clang/lib/Sema/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -11,6 +11,7 @@
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/TemplateBase.h"
 #include "clang/AST/Type.h"
 
 namespace clang {
@@ -125,6 +126,20 @@ TagDecl 
*HeuristicResolverImpl::resolveTypeToTagDecl(QualType QT) {
   if (!T)
 return nullptr;
 
+  // If T is the type of a template parameter, we can't get a useful TagDecl
+  // out of it. However, if the template parameter has a default argument,
+  // as a heuristic we can replace T with the default argument type.
+  if (const auto *TTPT = dyn_cast(T)) {
+if (const auto *TTPD = TTPT->getDecl()) {
+  if (TTPD->hasDefaultArgument()) {
+const auto &DefaultArg = TTPD->getDefaultArgument().getArgument();
+if (DefaultArg.getKind() == TemplateArgument::Type) {
+  T = DefaultArg.getAsType().getTypePtrOrNull();
+}
+  }
+}
+  }
+
   // Unwrap type sugar such as type aliases.
   T = T->getCanonicalTypeInternal().getTypePtr();
 
diff --git a/clang/unittests/Sema/HeuristicResolverTest.cpp 
b/clang/unittests/Sema/HeuristicResolverTest.cpp
index c7cfe7917c532..5e36108172702 100644
--- a/clang/unittests/Sema/HeuristicResolverTest.cpp
+++ b/clang/unittests/Sema/HeuristicResolverTest.cpp
@@ -410,6 +410,23 @@ TEST(HeuristicResolver, MemberExpr_HangIssue126536) {
   cxxDependentScopeMemberExpr(hasMemberName("foo")).bind("input"));
 }
 
+TEST(HeuristicResolver, MemberExpr_DefaultTemplateArgument) {
+  std::string Code = R"cpp(
+struct Default {
+  void foo();
+};
+template 
+void bar(T t) {
+  t.foo();
+}
+  )cpp";
+  // Test resolution of "foo" in "t.foo()".
+  expectResolution(
+  Code, &HeuristicResolver::resolveMemberExpr,
+  cxxDependentScopeMemberExpr(hasMemberName("foo")).bind("input"),
+  cxxMethodDecl(hasName("foo")).bind("output"));
+}
+
 TEST(HeuristicResolver, DeclRefExpr_StaticMethod) {
   std::string Code = R"cpp(
 template 

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang-tools-extra] [clang][HeuristicResolver] Default argument heuristic for template parameters (PR #131074)

2025-03-14 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 ready_for_review 
https://github.com/llvm/llvm-project/pull/131074
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][HeuristicResolver] Default argument heuristic for template parameters (PR #131074)

2025-03-15 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/131074

Fixes https://github.com/clangd/clangd/discussions/1056

>From 32ca27b5daa8cd1a0a9ad7b60c0ceecebaf9e8b6 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Thu, 13 Mar 2025 01:23:03 -0400
Subject: [PATCH] [clang][HeuristicResolver] Default argument heuristic for
 template parameters

---
 clang/lib/Sema/HeuristicResolver.cpp   | 15 +++
 clang/unittests/Sema/HeuristicResolverTest.cpp | 17 +
 2 files changed, 32 insertions(+)

diff --git a/clang/lib/Sema/HeuristicResolver.cpp 
b/clang/lib/Sema/HeuristicResolver.cpp
index d377379c627db..feda9696b8e05 100644
--- a/clang/lib/Sema/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -11,6 +11,7 @@
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/TemplateBase.h"
 #include "clang/AST/Type.h"
 
 namespace clang {
@@ -125,6 +126,20 @@ TagDecl 
*HeuristicResolverImpl::resolveTypeToTagDecl(QualType QT) {
   if (!T)
 return nullptr;
 
+  // If T is the type of a template parameter, we can't get a useful TagDecl
+  // out of it. However, if the template parameter has a default argument,
+  // as a heuristic we can replace T with the default argument type.
+  if (const auto *TTPT = dyn_cast(T)) {
+if (const auto *TTPD = TTPT->getDecl()) {
+  if (TTPD->hasDefaultArgument()) {
+const auto &DefaultArg = TTPD->getDefaultArgument().getArgument();
+if (DefaultArg.getKind() == TemplateArgument::Type) {
+  T = DefaultArg.getAsType().getTypePtrOrNull();
+}
+  }
+}
+  }
+
   // Unwrap type sugar such as type aliases.
   T = T->getCanonicalTypeInternal().getTypePtr();
 
diff --git a/clang/unittests/Sema/HeuristicResolverTest.cpp 
b/clang/unittests/Sema/HeuristicResolverTest.cpp
index c7cfe7917c532..5e36108172702 100644
--- a/clang/unittests/Sema/HeuristicResolverTest.cpp
+++ b/clang/unittests/Sema/HeuristicResolverTest.cpp
@@ -410,6 +410,23 @@ TEST(HeuristicResolver, MemberExpr_HangIssue126536) {
   cxxDependentScopeMemberExpr(hasMemberName("foo")).bind("input"));
 }
 
+TEST(HeuristicResolver, MemberExpr_DefaultTemplateArgument) {
+  std::string Code = R"cpp(
+struct Default {
+  void foo();
+};
+template 
+void bar(T t) {
+  t.foo();
+}
+  )cpp";
+  // Test resolution of "foo" in "t.foo()".
+  expectResolution(
+  Code, &HeuristicResolver::resolveMemberExpr,
+  cxxDependentScopeMemberExpr(hasMemberName("foo")).bind("input"),
+  cxxMethodDecl(hasName("foo")).bind("output"));
+}
+
 TEST(HeuristicResolver, DeclRefExpr_StaticMethod) {
   std::string Code = R"cpp(
 template 

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/20.x: [clang][AST] Handle implicit first argument in CallExpr::getBeginLoc() (PR #135927)

2025-04-16 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/135927

Backport 
https://github.com/llvm/llvm-project/commit/289baf1f42c8b5773271b611cd235d4ab94bb4e8

Fixes https://github.com/llvm/llvm-project/issues/135922

>From a9ea5de20db3ff08d691856e7da5b185d438e228 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Tue, 15 Apr 2025 03:40:37 -0400
Subject: [PATCH] [clang][AST] Handle implicit first argument in
 CallExpr::getBeginLoc()

---
 clang/lib/AST/Expr.cpp | 7 +--
 clang/test/SemaCXX/cxx2b-deducing-this.cpp | 7 +++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 8571b617c70eb..a5b7ef8c4271b 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1665,8 +1665,11 @@ SourceLocation CallExpr::getBeginLoc() const {
 Method && Method->isExplicitObjectMemberFunction()) {
   bool HasFirstArg = getNumArgs() > 0 && getArg(0);
   assert(HasFirstArg);
-  if (HasFirstArg)
-return getArg(0)->getBeginLoc();
+  if (HasFirstArg) {
+if (auto FirstArgLoc = getArg(0)->getBeginLoc(); 
FirstArgLoc.isValid()) {
+  return FirstArgLoc;
+}
+  }
 }
   }
 
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index 6f17ce7275456..7e392213710a4 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -1134,3 +1134,10 @@ struct S {
 static_assert((S{} << 11) == a);
 // expected-error@-1 {{use of undeclared identifier 'a'}}
 }
+
+namespace GH135522 {
+struct S {
+  auto f(this auto) -> S;
+  bool g() { return f(); } // expected-error {{no viable conversion from 
returned value of type 'S' to function return type 'bool'}}
+};
+}

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/20.x: [clang][AST] Handle implicit first argument in CallExpr::getBeginLoc() (PR #135927)

2025-04-16 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 milestoned 
https://github.com/llvm/llvm-project/pull/135927
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] [clangd] Add clangd 20 release notes (PR #127358)

2025-02-17 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/127358

>From 8359f75adaacd9d2b7247e8887151cce59e7c086 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Sat, 15 Feb 2025 01:30:48 -0500
Subject: [PATCH] [clangd] Add clangd 20 release notes

---
 clang-tools-extra/docs/ReleaseNotes.rst | 53 +++--
 1 file changed, 50 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index cc5f64a3f9fa3..316ac1743ccb7 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -56,7 +56,8 @@ Improvements to clangd
 Inlay hints
 ^^^
 
-- Added `DefaultArguments` Inlay Hints option.
+- Added support for inlay hints for default arguments, enabled using the
+  `DefaultArguments` config option (#GH95712)
 
 Diagnostics
 ^^^
@@ -67,21 +68,42 @@ Semantic Highlighting
 Compile flags
 ^
 
+- Fixed a bug where clangd would unnecessarily reparse open files whose
+  compile command did not change when receiving a new compile command
+  via an LSP `workspace/configuration` request (#GH115438)
+
 Hover
 ^
 
+- Hovering over a function name now shows the function's documentation
+  comment even if the comment is written above the function's out-of-line
+  definition in a different source file (#GH67802)
+
 Code completion
 ^^^
 
+- Added an `ArgumentLists` config option under `Completion`. This is a more
+  flexible version of the `--function-arg-placeholders` command line flag,
+  allowing users more detailed control of what is inserted in argument list
+  position when clangd completes the name of a function in a function call
+  context. (#GH111322)
+- Clangd now supports configuring which headers should be inserted using 
+  `<>` vs. `""` syntax using the `QuotedHeaders` and `AngledHeaders` config
+  options under `Style` (#GH67749)
 - Added completion for C++20 keywords.
+- Improved code completion behaviour in dependent/templated code
+- Completion items now include documentation comments in more cases (#GH120099)
 
 Code actions
 
 
 - Added `Swap operands` tweak for certain binary operators.
-
 - Improved the extract-to-function code action to allow extracting statements
   with overloaded operators like ``<<`` of ``std::ostream``.
+- `Define outline` now handles member functions of class templates, and
+  member function templates.
+- `Extract variable` can now operate on the top-level expression in an
+  expression statement (#GH112525)
 
 Signature help
 ^^
@@ -89,13 +111,38 @@ Signature help
 Cross-references
 
 
+- Clangd now supports the "outgoing calls" direction of call hierarchy
+  (#GH77556)
+- Call hierarchy can now be invoked on fields and namespace-scope
+  variables (#GH113900)
+- Improved heuristics for filtering out generated Protobuf symbol names
+  during indexing (#GH110091)
+- Compiler intrinsics defined in `*intrin.h` system headers are now
+  indexed even if they have reserved names (#GH119735)
+- Various improvements to go-to-definition in templated code
+
 Objective-C
 ^^^
 
+Clang-tidy integration
+^^
+
+- Improved robustness in handling clang-tidy check names (#GH109421)
+
+C++20 Modules Support
+^
+
+- Support code completion for symbols defined in modules (#GH110083)
+- Improve performance when opening files that import modules (#GH106683)
+- Compile commands for modules now respect modifications specified in `.clangd`
+  files (#GH122606)
+
 Miscellaneous
 ^
 
-- The DefineOutline tweak now handles member functions of class templates.
+- Fixed an OOM affecting some versions of libcxx headers compiled in C++20
+  mode (#GH108866)
+- Various other stability improvements, e.g. crash fixes
 
 Improvements to clang-doc
 -

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] [clangd] Add clangd 20 release notes (PR #127358)

2025-02-17 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

Thanks all for the reviews!

Adding @tstellar to request merging this to the llvm 20 branch.

https://github.com/llvm/llvm-project/pull/127358
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][NFC] Remove CXXRecordDecl::lookupDependentName() and its helpers (PR #128392)

2025-02-22 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/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);
```

>From 4bb5f832edc9370e3d782427db8cd51b8ffdc835 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Sat, 22 Feb 2025 22:48:03 -0500
Subject: [PATCH] [clang][NFC] Remove CXXRecordDecl::lookupDependentName() and
 its helpers

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);
```
---
 clang/include/clang/AST/DeclCXX.h |  8 -
 clang/lib/AST/CXXInheritance.cpp  | 53 ---
 2 files changed, 61 deletions(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 266b93a64a390..dbd02ef7f8011 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1720,14 +1720,6 @@ class CXXRecordDecl : public RecordDecl {
   /// static analysis, or similar.
   bool hasMemberName(DeclarationName N) const;
 
-  /// Performs an imprecise lookup of a dependent name in this class.
-  ///
-  /// This function does not follow strict semantic rules and should be used
-  /// only when lookup rules can be relaxed, e.g. indexing.
-  std::vector
-  lookupDependentName(DeclarationName Name,
-  llvm::function_ref Filter);
-
   /// Renders and displays an inheritance diagram
   /// for this C++ class and all of its base classes (transitively) using
   /// GraphViz.
diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index ee5775837d535..ab862d57eae89 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -411,59 +411,6 @@ bool CXXRecordDecl::hasMemberName(DeclarationName Name) 
const {
   Paths);
 }
 
-static bool
-findOrdinaryMemberInDependentClasses(const CXXBaseSpecifier *Specifier,
- CXXBasePath &Path, DeclarationName Name) {
-  const TemplateSpecializationType *TST =
-  Specifier->getType()->getAs();
-  if (!TST) {
-auto *RT = Specifier->getType()->getAs();
-if (!RT)
-  return false;
-return findOrdinaryMember(cast(RT->getDecl()), Path, Name);
-  }
-  TemplateName TN = TST->getTemplateName();
-  const auto *TD = dyn_cast_or_null(TN.getAsTemplateDecl());
-  if (!TD)
-return false;
-  CXXRecordDecl *RD = TD->getTemplatedDecl();
-  if (!RD)
-return false;
-  return findOrdinaryMember(RD, Path, Name);
-}
-
-std::vector CXXRecordDecl::lookupDependentName(
-DeclarationName Name,
-llvm::function_ref Filter) {
-  std::vector Results;
-  // Lookup in the class.
-  bool AnyOrdinaryMembers = false;
-  for (const NamedDecl *ND : lookup(Name)) {
-if (isOrdinaryMember(ND))
-  AnyOrdinaryMembers = true;
-if (Filter(ND))
-  Results.push_back(ND);
-  }
-  if (AnyOrdinaryMembers)
-return Results;
-
-  // Perform lookup into our base classes.
-  CXXBasePaths Paths;
-  Paths.setOrigin(this);
-  if (!lookupInBases(
-  [&](const CXXBaseSpecifier *Specifier, CXXBasePath &Path) {
-return findOrdinaryMemberInDependentClasses(Specifier, Path, Name);
-  },
-  Paths, /*LookupInDependent=*/true))
-return Results;
-  for (DeclContext::lookup_iterator I = Paths.front().Decls, E = I.end();
-   I != E; ++I) {
-if (isOrdinaryMember(*I) && Filter(*I))
-  Results.push_back(*I);
-  }
-  return Results;
-}
-
 void OverridingMethods::add(unsigned OverriddenSubobject,
 UniqueVirtualMethod Overriding) {
   SmallVectorImpl &SubobjectOverrides

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][NFC] Remove CXXRecordDecl::lookupDependentName() and its helpers (PR #128392)

2025-02-22 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

For reference, the callers of `CXXRecordDecl::lookupDependentName()` have been 
ported over to `HeuristicResolver` over the following series of patches:

https://github.com/llvm/llvm-project/pull/124888
https://github.com/llvm/llvm-project/pull/125153
https://github.com/llvm/llvm-project/pull/128106
https://github.com/llvm/llvm-project/pull/128391

https://github.com/llvm/llvm-project/pull/128392
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][NFC] Remove CXXRecordDecl::lookupDependentName() and its helpers (PR #128392)

2025-02-23 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

> LGTM in general, but my concern would be that we're less clear about the 
> number of uses of this function out-of-tree (and how hard it could be to 
> migrate them to HeuristicResolver), so as an alternative, can we turn the 
> implementation to use HeuristicResolver and explicitly deprecate it for a 
> while before eventually removing it?

I tried this, but this would require linking `clangSema` into `clang/lib/AST` 
which creates a circular dependency.

FWIW I did a Github code search and could only find 
[one](https://github.com/sourcegraph/scip-clang/blob/cc64149ae5f7819ac34c987807753b440c681b6a/indexer/ApproximateNameResolver.cc#L69)
 out-of-tree use in public code available on Github, and it looks 
straightforward to port to HeuristicResolver.

https://github.com/llvm/llvm-project/pull/128392
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang-tools-extra] [clang][HeuristicResolver] Apply default argument heuristic in resolveDeclRefExpr as well (PR #132576)

2025-03-22 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/132576

>From 2c9fc17bf2ef28c42df472598e4b7d09297cb668 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Sat, 22 Mar 2025 20:54:02 -0400
Subject: [PATCH] [clang][HeuristicResolver] Apply default argument heuristic
 in resolveDeclRefExpr as well

---
 .../clangd/unittests/XRefsTests.cpp |  2 +-
 clang/lib/Sema/HeuristicResolver.cpp|  6 +++---
 clang/unittests/Sema/HeuristicResolverTest.cpp  | 17 +
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp 
b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index e12d7691c58fb..693e965e78a96 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1091,7 +1091,7 @@ TEST(LocateSymbol, All) {
   )objc",
   R"cpp(
 struct PointerIntPairInfo {
-  static void *getPointer(void *Value);
+  static void *$decl[[getPointer]](void *Value);
 };
 
 template  struct PointerIntPair {
diff --git a/clang/lib/Sema/HeuristicResolver.cpp 
b/clang/lib/Sema/HeuristicResolver.cpp
index 9b793e876a49f..5202ae340bbfd 100644
--- a/clang/lib/Sema/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -315,9 +315,9 @@ std::vector 
HeuristicResolverImpl::resolveMemberExpr(
 
 std::vector
 HeuristicResolverImpl::resolveDeclRefExpr(const DependentScopeDeclRefExpr *RE) 
{
-  return resolveDependentMember(
-  resolveNestedNameSpecifierToType(RE->getQualifier()), RE->getDeclName(),
-  StaticFilter);
+  QualType Qualifier = resolveNestedNameSpecifierToType(RE->getQualifier());
+  Qualifier = simplifyType(Qualifier, nullptr, /*UnwrapPointer=*/false);
+  return resolveDependentMember(Qualifier, RE->getDeclName(), StaticFilter);
 }
 
 std::vector
diff --git a/clang/unittests/Sema/HeuristicResolverTest.cpp 
b/clang/unittests/Sema/HeuristicResolverTest.cpp
index f7eb4b23c2ab0..3ed6bba790be3 100644
--- a/clang/unittests/Sema/HeuristicResolverTest.cpp
+++ b/clang/unittests/Sema/HeuristicResolverTest.cpp
@@ -463,6 +463,23 @@ TEST(HeuristicResolver, DeclRefExpr_StaticMethod) {
   cxxMethodDecl(hasName("bar")).bind("output"));
 }
 
+TEST(HeuristicResolver, DeclRefExpr_DefaultTemplateArgument) {
+  std::string Code = R"cpp(
+struct Default {
+  static void foo();
+};
+template 
+void bar() {
+  T::foo();
+}
+  )cpp";
+  // Test resolution of "foo" in "T::foo()".
+  expectResolution(
+  Code, &HeuristicResolver::resolveDeclRefExpr,
+  dependentScopeDeclRefExpr(hasDependentName("foo")).bind("input"),
+  cxxMethodDecl(hasName("foo")).bind("output"));
+}
+
 TEST(HeuristicResolver, DeclRefExpr_StaticOverloads) {
   std::string Code = R"cpp(
 template 

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang-tools-extra] [clang][HeuristicResolver] Apply default argument heuristic in resolveDeclRefExpr as well (PR #132576)

2025-03-22 Thread Nathan Ridge via llvm-branch-commits

HighCommander4 wrote:

(Rebased)

https://github.com/llvm/llvm-project/pull/132576
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang-tools-extra] [clang][HeuristicResolver] Apply default argument heuristic in resolveDeclRefExpr as well (PR #132576)

2025-03-22 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 edited 
https://github.com/llvm/llvm-project/pull/132576
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang-tools-extra] release/20.x: [clangd] Guard against trivial FunctionProtoTypeLoc when creating inlay hints (#143087) (PR #143344)

2025-06-08 Thread Nathan Ridge via llvm-branch-commits

https://github.com/HighCommander4 approved this pull request.


https://github.com/llvm/llvm-project/pull/143344
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits