From e1f24a2b85f06fedcacf7ee6ac31a25a25f697ce Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Fri, 1 Jul 2016 01:17:02 +0000 Subject: [CodeCompletion] Allow system headers providing private symbols with a single underscore. rdar://24677150 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@274314 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaCodeComplete.cpp | 43 ++++++++++++++++++++++++----------- test/CodeCompletion/Inputs/reserved.h | 4 +++- test/CodeCompletion/ordinary-name.c | 3 ++- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index d910c6f8ad..36babc4bc0 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -481,12 +481,37 @@ getRequiredQualification(ASTContext &Context, /// Determine whether \p Id is a name reserved for the implementation (C99 /// 7.1.3, C++ [lib.global.names]). -static bool isReservedName(const IdentifierInfo *Id) { +static bool isReservedName(const IdentifierInfo *Id, + bool doubleUnderscoreOnly = false) { if (Id->getLength() < 2) return false; const char *Name = Id->getNameStart(); return Name[0] == '_' && - (Name[1] == '_' || (Name[1] >= 'A' && Name[1] <= 'Z')); + (Name[1] == '_' || (Name[1] >= 'A' && Name[1] <= 'Z' && + !doubleUnderscoreOnly)); +} + +// Some declarations have reserved names that we don't want to ever show. +// Filter out names reserved for the implementation if they come from a +// system header. +static bool shouldIgnoreDueToReservedName(const NamedDecl *ND, Sema &SemaRef) { + const IdentifierInfo *Id = ND->getIdentifier(); + if (!Id) + return false; + + // Ignore reserved names for compiler provided decls. + if (isReservedName(Id) && ND->getLocation().isInvalid()) + return true; + + // For system headers ignore only double-underscore names. + // This allows for system headers providing private symbols with a single + // underscore. + if (isReservedName(Id, /*doubleUnderscoreOnly=*/true) && + SemaRef.SourceMgr.isInSystemHeader( + SemaRef.SourceMgr.getSpellingLoc(ND->getLocation()))) + return true; + + return false; } bool ResultBuilder::isInterestingDecl(const NamedDecl *ND, @@ -513,17 +538,9 @@ bool ResultBuilder::isInterestingDecl(const NamedDecl *ND, // Using declarations themselves are never added as results. if (isa(ND)) return false; - - // Some declarations have reserved names that we don't want to ever show. - // Filter out names reserved for the implementation if they come from a - // system header. - // TODO: Add a predicate for this. - if (const IdentifierInfo *Id = ND->getIdentifier()) - if (isReservedName(Id) && - (ND->getLocation().isInvalid() || - SemaRef.SourceMgr.isInSystemHeader( - SemaRef.SourceMgr.getSpellingLoc(ND->getLocation())))) - return false; + + if (shouldIgnoreDueToReservedName(ND, SemaRef)) + return false; if (Filter == &ResultBuilder::IsNestedNameSpecifier || (isa(ND) && diff --git a/test/CodeCompletion/Inputs/reserved.h b/test/CodeCompletion/Inputs/reserved.h index fafe4ac440..7b353a58fc 100644 --- a/test/CodeCompletion/Inputs/reserved.h +++ b/test/CodeCompletion/Inputs/reserved.h @@ -1,2 +1,4 @@ -typedef int _INTEGER_TYPE; +typedef int __INTEGER_TYPE; typedef float FLOATING_TYPE; + +typedef int _MyPrivateType; diff --git a/test/CodeCompletion/ordinary-name.c b/test/CodeCompletion/ordinary-name.c index dda7bb018a..1352b70730 100644 --- a/test/CodeCompletion/ordinary-name.c +++ b/test/CodeCompletion/ordinary-name.c @@ -5,8 +5,9 @@ typedef struct t _TYPEDEF; void foo() { int y; // RUN: %clang_cc1 -isystem %S/Inputs -fsyntax-only -code-completion-at=%s:6:9 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s + // CHECK-CC1-NOT: __INTEGER_TYPE // CHECK-CC1: _Imaginary - // CHECK-CC1-NOT: _INTEGER_TYPE; + // CHECK-CC1: _MyPrivateType // CHECK-CC1: _TYPEDEF // CHECK-CC1: FLOATING_TYPE // CHECK-CC1: foo -- cgit v1.2.1