https://github.com/Michael137 created 
https://github.com/llvm/llvm-project/pull/84891

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.

The associated LLDB tests: https://github.com/llvm/llvm-project/pull/84890

rdar://124098023

>From 5fad198ae29d0e377ab101a25b15c4a52f6955bc Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuc...@gmail.com>
Date: Tue, 12 Mar 2024 09:56:58 +0000
Subject: [PATCH] [clang][CodeCompletion] Allow debuggers to code-complete
 reserved identifiers

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.
---
 clang/lib/Sema/SemaCodeComplete.cpp       | 4 ++++
 clang/test/CodeCompletion/ordinary-name.c | 7 ++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

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

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

Reply via email to