Author: akirtzidis Date: Thu Jun 30 20:17:02 2016 New Revision: 274314 URL: http://llvm.org/viewvc/llvm-project?rev=274314&view=rev Log: [CodeCompletion] Allow system headers providing private symbols with a single underscore.
rdar://24677150 Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp cfe/trunk/test/CodeCompletion/Inputs/reserved.h cfe/trunk/test/CodeCompletion/ordinary-name.c Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=274314&r1=274313&r2=274314&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original) +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Thu Jun 30 20:17:02 2016 @@ -481,12 +481,37 @@ getRequiredQualification(ASTContext &Con /// 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(co // Using declarations themselves are never added as results. if (isa<UsingDecl>(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<NamespaceDecl>(ND) && Modified: cfe/trunk/test/CodeCompletion/Inputs/reserved.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/Inputs/reserved.h?rev=274314&r1=274313&r2=274314&view=diff ============================================================================== --- cfe/trunk/test/CodeCompletion/Inputs/reserved.h (original) +++ cfe/trunk/test/CodeCompletion/Inputs/reserved.h Thu Jun 30 20:17:02 2016 @@ -1,2 +1,4 @@ -typedef int _INTEGER_TYPE; +typedef int __INTEGER_TYPE; typedef float FLOATING_TYPE; + +typedef int _MyPrivateType; Modified: cfe/trunk/test/CodeCompletion/ordinary-name.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/ordinary-name.c?rev=274314&r1=274313&r2=274314&view=diff ============================================================================== --- cfe/trunk/test/CodeCompletion/ordinary-name.c (original) +++ cfe/trunk/test/CodeCompletion/ordinary-name.c Thu Jun 30 20:17:02 2016 @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits