-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][CodeComplete] Use HeuristicResolver to resolve pointee types #121315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Depends on #121314 |
The buildkite run shows the test This made me realize that |
4a1f5a1
to
4f0e828
Compare
Filed #123549 to track this. |
5165ce9
to
fd71bd3
Compare
fd71bd3
to
25fdf43
Compare
Rebased. Publishing for review. |
@llvm/pr-subscribers-clang Author: Nathan Ridge (HighCommander4) ChangesFixes clangd/clangd#810 Full diff: https://github.com/llvm/llvm-project/pull/121315.diff 3 Files Affected:
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 8a848df70cc5a1..69cda6e68bd36b 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"
@@ -5861,8 +5862,10 @@ void SemaCodeCompletion::CodeCompleteMemberReferenceExpr(
enum CodeCompletionContext::Kind contextKind;
if (IsArrow) {
- if (const auto *Ptr = ConvertedBaseType->getAs<PointerType>())
- ConvertedBaseType = Ptr->getPointeeType();
+ if (QualType PointeeType = Resolver.getPointeeType(ConvertedBaseType);
+ !PointeeType.isNull()) {
+ ConvertedBaseType = PointeeType;
+ }
}
if (IsArrow) {
@@ -5899,8 +5902,9 @@ void SemaCodeCompletion::CodeCompleteMemberReferenceExpr(
ExprValueKind BaseKind = Base->getValueKind();
if (IsArrow) {
- if (const PointerType *Ptr = BaseType->getAs<PointerType>()) {
- BaseType = Ptr->getPointeeType();
+ if (QualType PointeeType = Resolver.getPointeeType(BaseType);
+ !PointeeType.isNull()) {
+ BaseType = PointeeType;
BaseKind = VK_LValue;
} else if (BaseType->isObjCObjectPointerType() ||
BaseType->isTemplateTypeParmType()) {
@@ -10472,4 +10476,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 <typename T>
+struct smart_pointer {
+ T* operator->();
+};
+
+template <typename T>
+struct node {
+ smart_pointer<node<T>> 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<node<T>>#]next
+ }
+};
+}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/12151 Here is the relevant piece of the build log for the reference
|
Fixes clangd/clangd#810