Skip to content

[cherry-pick][stable/20230725] [clang][CodeCompletion] Allow debuggers to code-complete reserved identifiers #8383

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/lib/Sema/SemaCodeComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,10 @@ ResultBuilder::ShadowMapEntry::end() const {
// Filter out names reserved for the implementation if they come from a
// system header.
static bool shouldIgnoreDueToReservedName(const NamedDecl *ND, Sema &SemaRef) {
// Debuggers want access to all identifiers, including reserved ones.
if (SemaRef.getLangOpts().DebuggerSupport)
return false;

ReservedIdentifierStatus Status = ND->isReserved(SemaRef.getLangOpts());
// Ignore reserved names for compiler provided decls.
if (isReservedInAllContexts(Status) && ND->getLocation().isInvalid())
Expand Down
7 changes: 6 additions & 1 deletion clang/test/CodeCompletion/ordinary-name.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ typedef struct t _TYPEDEF;
void foo() {
int y;
// RUN: %clang_cc1 -isystem %S/Inputs -fsyntax-only -code-completion-at=%s:%(line-1):9 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
// CHECK-CC1-NOT: __builtin_va_list
// CHECK-CC1-NOT: __INTEGER_TYPE
// CHECK-CC1: _Imaginary
// CHECK-CC1: _MyPrivateType
Expand All @@ -15,4 +16,8 @@ void foo() {
// CHECK-CC1: y

// PR8744
// RUN: %clang_cc1 -isystem %S/Inputs -fsyntax-only -code-completion-at=%s:%(line-17):11 %s
// RUN: %clang_cc1 -isystem %S/Inputs -fsyntax-only -code-completion-at=%s:%(line-18):11 %s

// RUN: %clang_cc1 -isystem %S/Inputs -fsyntax-only -fdebugger-support -code-completion-at=%s:%(line-15):9 %s -o - | FileCheck -check-prefix=CHECK-DBG %s
// CHECK-DBG: __builtin_va_list
// CHECK-DBG: __INTEGER_TYPE
1 change: 1 addition & 0 deletions lldb/test/API/commands/expression/completion/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CXX_SOURCES := main.cpp other.cpp
CXXFLAGS += -isystem $(SRCDIR)/sys

include Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ def test_expr_completion(self):
"expr some_expr.Self(). FooNoArgs", "expr some_expr.Self(). FooNoArgsBar()"
)

self.complete_from_to("expr myVec.__f", "expr myVec.__func()")
self.complete_from_to("expr myVec._F", "expr myVec._Func()")
self.complete_from_to("expr myVec.__m", "expr myVec.__mem")
self.complete_from_to("expr myVec._M", "expr myVec._Mem")

def test_expr_completion_with_descriptions(self):
self.build()
self.main_source = "main.cpp"
Expand Down
5 changes: 5 additions & 0 deletions lldb/test/API/commands/expression/completion/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <reserved.h>

namespace LongNamespaceName { class NestedClass { long m; }; }

// Defined in other.cpp, we only have a forward declaration here.
Expand Down Expand Up @@ -31,5 +33,8 @@ int main()
some_expr.FooNumbersBar1();
Expr::StaticMemberMethodBar();
ForwardDecl *fwd_decl_ptr = &fwd_decl;
MyVec myVec;
myVec.__func();
myVec._Func();
return 0; // Break here
}
8 changes: 8 additions & 0 deletions lldb/test/API/commands/expression/completion/sys/reserved.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class MyVec {
int __mem;
int _Mem;

public:
void __func() {}
void _Func() {}
};