Skip to content

[clang][CodeCompletion] Allow debuggers to code-complete reserved identifiers #84891

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

Conversation

Michael137
Copy link
Member

It is not uncommon for LLDB users to dig into internal implementation details of system types (including the STL). LLDB's expression evaluator makes use of Clang's code-completion facilities but currently reserved identifeirs are filtered out (clang::Decls created in LLDB don't have valid locations, so we would also fail to code-complete any identifiers with reserved prefixes, not just ones from system headers).

This patch permits Clang to code-complete reserved identifiers iff we're in the debugger.

The associated LLDB tests: #84890

rdar://124098023

…ntifiers

It is not uncommon for LLDB users to dig into internal implementation
details of system types (including the STL). LLDB's expression evaluator
makes use of Clang's code-completion facilities but currently reserved
identifeirs are filtered out (`clang::Decl`s created in LLDB don't have
valid locations, so we would also fail to code-complete *any*
identifiers with reserved prefixes, not just ones from system headers).

This patch permits Clang to code-complete reserved identifiers iff
we're in the debugger.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Mar 12, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 12, 2024

@llvm/pr-subscribers-clang

Author: Michael Buch (Michael137)

Changes

It is not uncommon for LLDB users to dig into internal implementation details of system types (including the STL). LLDB's expression evaluator makes use of Clang's code-completion facilities but currently reserved identifeirs are filtered out (clang::Decls created in LLDB don't have valid locations, so we would also fail to code-complete any identifiers with reserved prefixes, not just ones from system headers).

This patch permits Clang to code-complete reserved identifiers iff we're in the debugger.

The associated LLDB tests: #84890

rdar://124098023


Full diff: https://github.com/llvm/llvm-project/pull/84891.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaCodeComplete.cpp (+4)
  • (modified) clang/test/CodeCompletion/ordinary-name.c (+6-1)
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index c44be0df9b0a85..18a7f2d98340a3 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -764,6 +764,10 @@ getRequiredQualification(ASTContext &Context, const DeclContext *CurContext,
 // 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())
diff --git a/clang/test/CodeCompletion/ordinary-name.c b/clang/test/CodeCompletion/ordinary-name.c
index c8181a248daa2f..93985619206173 100644
--- a/clang/test/CodeCompletion/ordinary-name.c
+++ b/clang/test/CodeCompletion/ordinary-name.c
@@ -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
@@ -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

@Michael137 Michael137 requested a review from AaronBallman March 12, 2024 10:44
@Michael137 Michael137 merged commit beb47e7 into llvm:main Mar 12, 2024
Michael137 added a commit to Michael137/llvm-project that referenced this pull request Mar 12, 2024
Michael137 added a commit to Michael137/llvm-project that referenced this pull request Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants