[clang] [clang][CodeComplete] Handle deref operator in getApproximateType (PR #86466)
HighCommander4 wrote: Thanks for the review! https://github.com/llvm/llvm-project/pull/86466 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeComplete] Handle deref operator in getApproximateType (PR #86466)
https://github.com/HighCommander4 closed https://github.com/llvm/llvm-project/pull/86466 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeComplete] Handle deref operator in getApproximateType (PR #86466)
https://github.com/HighCommander4 updated https://github.com/llvm/llvm-project/pull/86466 >From 73d2082c164ba629babec3cc3dc9b1d06b41ec60 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Mon, 25 Mar 2024 02:14:00 -0400 Subject: [PATCH] [clang][CodeComplete] Handle deref operator in getApproximateType This allows completing after `(*this).` in a dependent context. Fixes https://github.com/clangd/clangd/issues/1952 --- clang/lib/Sema/SemaCodeComplete.cpp | 5 + clang/test/CodeCompletion/member-access.cpp | 20 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index c44be0df9b0a85..5884b24d66a3eb 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -20,6 +20,7 @@ #include "clang/AST/ExprConcepts.h" #include "clang/AST/ExprObjC.h" #include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/OperationKinds.h" #include "clang/AST/QualTypeNames.h" #include "clang/AST/RecursiveASTVisitor.h" #include "clang/AST/Type.h" @@ -5674,6 +5675,10 @@ QualType getApproximateType(const Expr *E) { return getApproximateType(VD->getInit()); } } + if (const auto *UO = llvm::dyn_cast(E)) { +if (UO->getOpcode() == UnaryOperatorKind::UO_Deref) + return UO->getSubExpr()->getType()->getPointeeType(); + } return Unresolved; } diff --git a/clang/test/CodeCompletion/member-access.cpp b/clang/test/CodeCompletion/member-access.cpp index 474b909ab11592..9f8c21c0bca6de 100644 --- a/clang/test/CodeCompletion/member-access.cpp +++ b/clang/test/CodeCompletion/member-access.cpp @@ -348,7 +348,23 @@ namespace function_can_be_call { T foo(U, V); }; - ::f - // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:351:7 %s -o - | FileCheck -check-prefix=CHECK_FUNCTION_CAN_BE_CALL %s + void test() { +::f + } + // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:352:9 %s -o - | FileCheck -check-prefix=CHECK_FUNCTION_CAN_BE_CALL %s // CHECK_FUNCTION_CAN_BE_CALL: COMPLETION: foo : [#T#]foo<<#typename T#>, <#typename U#>>(<#U#>, <#V#>) } + +namespace deref_dependent_this { +template +class A { + int field; + + void function() { +(*this).field; +// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:364:13 %s -o - | FileCheck -check-prefix=CHECK-DEREF-THIS %s +// CHECK-DEREF-THIS: field : [#int#]field +// CHECK-DEREF-THIS: [#void#]function() + } +}; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeComplete] Handle deref operator in getApproximateType (PR #86466)
https://github.com/zyn0217 edited https://github.com/llvm/llvm-project/pull/86466 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeComplete] Handle deref operator in getApproximateType (PR #86466)
@@ -5674,6 +5675,11 @@ QualType getApproximateType(const Expr *E) { return getApproximateType(VD->getInit()); } } + if (const auto *UO = llvm::dyn_cast(E)) { +if (UO->getOpcode() == UnaryOperatorKind::UO_Deref) { zyn0217 wrote: nit: We [don't](https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements) usually wrap a single statement with braces. https://github.com/llvm/llvm-project/pull/86466 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeComplete] Handle deref operator in getApproximateType (PR #86466)
https://github.com/zyn0217 approved this pull request. Thanks. LGTM apart from one nit. https://github.com/llvm/llvm-project/pull/86466 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeComplete] Handle deref operator in getApproximateType (PR #86466)
github-actions[bot] wrote: :white_check_mark: With the latest revision this PR passed the Python code formatter. https://github.com/llvm/llvm-project/pull/86466 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeComplete] Handle deref operator in getApproximateType (PR #86466)
github-actions[bot] wrote: :white_check_mark: With the latest revision this PR passed the C/C++ code formatter. https://github.com/llvm/llvm-project/pull/86466 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeComplete] Handle deref operator in getApproximateType (PR #86466)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Nathan Ridge (HighCommander4) Changes This allows completing after `(*this).` in a dependent context. Fixes https://github.com/clangd/clangd/issues/1952 --- Full diff: https://github.com/llvm/llvm-project/pull/86466.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaCodeComplete.cpp (+6) - (modified) clang/test/CodeCompletion/member-access.cpp (+18-2) ``diff diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index c44be0df9b0a85..0e44b0f444ed73 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -20,6 +20,7 @@ #include "clang/AST/ExprConcepts.h" #include "clang/AST/ExprObjC.h" #include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/OperationKinds.h" #include "clang/AST/QualTypeNames.h" #include "clang/AST/RecursiveASTVisitor.h" #include "clang/AST/Type.h" @@ -5674,6 +5675,11 @@ QualType getApproximateType(const Expr *E) { return getApproximateType(VD->getInit()); } } + if (const auto *UO = llvm::dyn_cast(E)) { +if (UO->getOpcode() == UnaryOperatorKind::UO_Deref) { + return UO->getSubExpr()->getType()->getPointeeType(); +} + } return Unresolved; } diff --git a/clang/test/CodeCompletion/member-access.cpp b/clang/test/CodeCompletion/member-access.cpp index 474b909ab11592..9f8c21c0bca6de 100644 --- a/clang/test/CodeCompletion/member-access.cpp +++ b/clang/test/CodeCompletion/member-access.cpp @@ -348,7 +348,23 @@ namespace function_can_be_call { T foo(U, V); }; - ::f - // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:351:7 %s -o - | FileCheck -check-prefix=CHECK_FUNCTION_CAN_BE_CALL %s + void test() { +::f + } + // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:352:9 %s -o - | FileCheck -check-prefix=CHECK_FUNCTION_CAN_BE_CALL %s // CHECK_FUNCTION_CAN_BE_CALL: COMPLETION: foo : [#T#]foo<<#typename T#>, <#typename U#>>(<#U#>, <#V#>) } + +namespace deref_dependent_this { +template +class A { + int field; + + void function() { +(*this).field; +// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:364:13 %s -o - | FileCheck -check-prefix=CHECK-DEREF-THIS %s +// CHECK-DEREF-THIS: field : [#int#]field +// CHECK-DEREF-THIS: [#void#]function() + } +}; +} `` https://github.com/llvm/llvm-project/pull/86466 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeComplete] Handle deref operator in getApproximateType (PR #86466)
https://github.com/HighCommander4 created https://github.com/llvm/llvm-project/pull/86466 This allows completing after `(*this).` in a dependent context. Fixes https://github.com/clangd/clangd/issues/1952 >From 6cac58d2e5c3c7effc0f0cc01c1368b9ddd6c21a Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Mon, 25 Mar 2024 02:14:00 -0400 Subject: [PATCH] [clang][CodeComplete] Handle deref operator in getApproximateType This allows completing after `(*this).` in a dependent context. Fixes https://github.com/clangd/clangd/issues/1952 --- clang/lib/Sema/SemaCodeComplete.cpp | 6 ++ clang/test/CodeCompletion/member-access.cpp | 20 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index c44be0df9b0a85..0e44b0f444ed73 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -20,6 +20,7 @@ #include "clang/AST/ExprConcepts.h" #include "clang/AST/ExprObjC.h" #include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/OperationKinds.h" #include "clang/AST/QualTypeNames.h" #include "clang/AST/RecursiveASTVisitor.h" #include "clang/AST/Type.h" @@ -5674,6 +5675,11 @@ QualType getApproximateType(const Expr *E) { return getApproximateType(VD->getInit()); } } + if (const auto *UO = llvm::dyn_cast(E)) { +if (UO->getOpcode() == UnaryOperatorKind::UO_Deref) { + return UO->getSubExpr()->getType()->getPointeeType(); +} + } return Unresolved; } diff --git a/clang/test/CodeCompletion/member-access.cpp b/clang/test/CodeCompletion/member-access.cpp index 474b909ab11592..9f8c21c0bca6de 100644 --- a/clang/test/CodeCompletion/member-access.cpp +++ b/clang/test/CodeCompletion/member-access.cpp @@ -348,7 +348,23 @@ namespace function_can_be_call { T foo(U, V); }; - ::f - // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:351:7 %s -o - | FileCheck -check-prefix=CHECK_FUNCTION_CAN_BE_CALL %s + void test() { +::f + } + // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:352:9 %s -o - | FileCheck -check-prefix=CHECK_FUNCTION_CAN_BE_CALL %s // CHECK_FUNCTION_CAN_BE_CALL: COMPLETION: foo : [#T#]foo<<#typename T#>, <#typename U#>>(<#U#>, <#V#>) } + +namespace deref_dependent_this { +template +class A { + int field; + + void function() { +(*this).field; +// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:364:13 %s -o - | FileCheck -check-prefix=CHECK-DEREF-THIS %s +// CHECK-DEREF-THIS: field : [#int#]field +// CHECK-DEREF-THIS: [#void#]function() + } +}; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits