clang  19.0.0git
Macros | Functions | Variables
SemaLookup.cpp File Reference
#include "clang/AST/ASTContext.h"
#include "clang/AST/CXXInheritance.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclLookups.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/ModuleLoader.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Overload.h"
#include "clang/Sema/RISCVIntrinsicManager.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/SemaRISCV.h"
#include "clang/Sema/TemplateDeduction.h"
#include "clang/Sema/TypoCorrection.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/TinyPtrVector.h"
#include "llvm/ADT/edit_distance.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
#include <algorithm>
#include <iterator>
#include <list>
#include <optional>
#include <set>
#include <utility>
#include <vector>
#include "OpenCLBuiltins.inc"
#include "SPIRVBuiltins.inc"
#include "clang/AST/TypeNodes.inc"

Go to the source code of this file.

Macros

#define TYPE(Class, Base)
 
#define DEPENDENT_TYPE(Class, Base)   case Type::Class:
 
#define NON_CANONICAL_TYPE(Class, Base)   case Type::Class:
 
#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base)   case Type::Class:
 
#define ABSTRACT_TYPE(Class, Base)
 

Functions

static clang::QualType GetFloat16Type (clang::ASTContext &Context)
 
static unsigned getIDNS (Sema::LookupNameKind NameKind, bool CPlusPlus, bool Redeclaration)
 
static const DeclContextgetContextForScopeMatching (const Decl *D)
 Get a representative context for a declaration such that two declarations will have the same context if they were found within the same scope. More...
 
static bool isPreferredLookupResult (Sema &S, Sema::LookupNameKind Kind, const NamedDecl *D, const NamedDecl *Existing)
 Determine whether D is a better lookup result than Existing, given that they declare the same entity. More...
 
static bool canHideTag (const NamedDecl *D)
 Determine whether D can hide a tag declaration. More...
 
static QualType diagOpenCLBuiltinTypeError (Sema &S, llvm::StringRef TypeClass, llvm::StringRef Name)
 Diagnose a missing builtin type. More...
 
static QualType getOpenCLEnumType (Sema &S, llvm::StringRef Name)
 Lookup an OpenCL enum type. More...
 
static QualType getOpenCLTypedefType (Sema &S, llvm::StringRef Name)
 Lookup an OpenCL typedef type. More...
 
template<typename ProgModel >
static void GetQualTypesForProgModelBuiltin (Sema &S, const typename ProgModel::BuiltinStruct &Builtin, unsigned &GenTypeMaxCnt, SmallVector< QualType, 1 > &RetTypes, SmallVector< SmallVector< QualType, 1 >, 5 > &ArgTypes)
 Get the QualType instances of the return type and arguments for a ProgModel builtin function signature. More...
 
static void GetProgModelBuiltinFctOverloads (ASTContext &Context, unsigned GenTypeMaxCnt, std::vector< QualType > &FunctionList, SmallVector< QualType, 1 > &RetTypes, SmallVector< SmallVector< QualType, 1 >, 5 > &ArgTypes, bool IsVariadic)
 Create a list of the candidate function overloads for a ProgModel builtin function. More...
 
template<typename ProgModel >
static bool isVersionInMask (const LangOptions &O, unsigned Mask)
 
template<>
bool isVersionInMask< OpenCLBuiltin > (const LangOptions &LO, unsigned Mask)
 
template<>
bool isVersionInMask< SPIRVBuiltin > (const LangOptions &LO, unsigned Mask)
 
template<typename ProgModel >
static void InsertBuiltinDeclarationsFromTable (Sema &S, LookupResult &LR, IdentifierInfo *II, const unsigned FctIndex, const unsigned Len, std::function< void(const typename ProgModel::BuiltinStruct &, FunctionDecl &)> ProgModelFinalizer)
 When trying to resolve a function name, if ProgModel::isBuiltin() returns a non-null <Index, Len> pair, then the name is referencing a builtin function. More...
 
static void LookupPredefedObjCSuperType (Sema &Sema, Scope *S)
 Looks up the declaration of "struct objc_super" and saves it for later use in building builtin declaration of objc_msgSendSuper and objc_msgSendSuper_stret. More...
 
static bool CanDeclareSpecialMemberFunction (const CXXRecordDecl *Class)
 Determine whether we can declare a special member function within the class at this point. More...
 
static bool isImplicitlyDeclaredMemberFunctionName (DeclarationName Name)
 Determine whether this is the name of an implicitly-declared special member function. More...
 
static void DeclareImplicitMemberFunctionsWithName (Sema &S, DeclarationName Name, SourceLocation Loc, const DeclContext *DC)
 If there are any implicit member functions with the given name that need to be declared in the given declaration context, do so. More...
 
static bool LookupDirect (Sema &S, LookupResult &R, const DeclContext *DC)
 
static bool CppNamespaceLookup (Sema &S, LookupResult &R, ASTContext &Context, const DeclContext *NS, UnqualUsingDirectiveSet &UDirs)
 
static bool isNamespaceOrTranslationUnitScope (Scope *S)
 
static DeclContextfindOuterContext (Scope *S)
 Find the outer declaration context from this scope. More...
 
static ModulegetDefiningModule (Sema &S, Decl *Entity)
 Find the module in which the given declaration was defined. More...
 
template<typename ParmDecl >
static bool hasAcceptableDefaultArgument (Sema &S, const ParmDecl *D, llvm::SmallVectorImpl< Module * > *Modules, Sema::AcceptableKind Kind)
 
template<typename Filter >
static bool hasAcceptableDeclarationImpl (Sema &S, const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules, Filter F, Sema::AcceptableKind Kind)
 
static bool hasAcceptableExplicitSpecialization (Sema &S, const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules, Sema::AcceptableKind Kind)
 
static bool hasAcceptableMemberSpecialization (Sema &S, const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules, Sema::AcceptableKind Kind)
 
static NamedDeclfindAcceptableDecl (Sema &SemaRef, NamedDecl *D, unsigned IDNS)
 Retrieve the visible declaration corresponding to D, if any. More...
 
static bool LookupQualifiedNameInUsingDirectives (Sema &S, LookupResult &R, DeclContext *StartDC)
 Perform qualified name lookup in the namespaces nominated by using directives by the given context. More...
 
static void addAssociatedClassesAndNamespaces (AssociatedLookup &Result, QualType T)
 
static void CollectEnclosingNamespace (Sema::AssociatedNamespaceSet &Namespaces, DeclContext *Ctx)
 
static void addAssociatedClassesAndNamespaces (AssociatedLookup &Result, const TemplateArgument &Arg)
 
static void addAssociatedClassesAndNamespaces (AssociatedLookup &Result, CXXRecordDecl *Class)
 
static bool isCandidateViable (CorrectionCandidateCallback &CCC, TypoCorrection &Candidate)
 
static void LookupPotentialTypoResult (Sema &SemaRef, LookupResult &Res, IdentifierInfo *Name, Scope *S, CXXScopeSpec *SS, DeclContext *MemberContext, bool EnteringContext, bool isObjCIvarLookup, bool FindHidden)
 Perform name lookup for a possible result for typo correction. More...
 
static void checkCorrectionVisibility (Sema &SemaRef, TypoCorrection &TC)
 Check whether the declarations found for a typo correction are visible. More...
 
static void getNestedNameSpecifierIdentifiers (NestedNameSpecifier *NNS, SmallVectorImpl< const IdentifierInfo * > &Identifiers)
 
static void AddKeywordsToConsumer (Sema &SemaRef, TypoCorrectionConsumer &Consumer, Scope *S, CorrectionCandidateCallback &CCC, bool AfterNestedNameSpecifier)
 Add keywords to the consumer as possible typo corrections. More...
 
static const NamedDeclgetDefinitionToImport (const NamedDecl *D)
 Find which declaration we should import to provide the definition of the given declaration. More...
 
static std::string getHeaderNameForHeader (Preprocessor &PP, FileEntryRef E, llvm::StringRef IncludingFile)
 Get a "quoted.h" or <angled.h> include path to use in a diagnostic suggesting the addition of a #include of the specified file. More...
 

Variables

static const unsigned MaxTypoDistanceResultSets = 5
 

Macro Definition Documentation

◆ ABSTRACT_TYPE

#define ABSTRACT_TYPE (   Class,
  Base 
)

◆ DEPENDENT_TYPE

#define DEPENDENT_TYPE (   Class,
  Base 
)    case Type::Class:

◆ NON_CANONICAL_TYPE

#define NON_CANONICAL_TYPE (   Class,
  Base 
)    case Type::Class:

◆ NON_CANONICAL_UNLESS_DEPENDENT_TYPE

#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE (   Class,
  Base 
)    case Type::Class:

◆ TYPE

#define TYPE (   Class,
  Base 
)

Function Documentation

◆ addAssociatedClassesAndNamespaces() [1/3]

static void addAssociatedClassesAndNamespaces ( AssociatedLookup &  Result,
const TemplateArgument Arg 
)
static

◆ addAssociatedClassesAndNamespaces() [2/3]

static void addAssociatedClassesAndNamespaces ( AssociatedLookup &  Result,
CXXRecordDecl Class 
)
static

◆ addAssociatedClassesAndNamespaces() [3/3]

static void addAssociatedClassesAndNamespaces ( AssociatedLookup &  Result,
QualType  T 
)
static

◆ AddKeywordsToConsumer()

static void AddKeywordsToConsumer ( Sema SemaRef,
TypoCorrectionConsumer Consumer,
Scope S,
CorrectionCandidateCallback CCC,
bool  AfterNestedNameSpecifier 
)
static

Add keywords to the consumer as possible typo corrections.

Definition at line 5136 of file SemaLookup.cpp.

◆ CanDeclareSpecialMemberFunction()

static bool CanDeclareSpecialMemberFunction ( const CXXRecordDecl Class)
static

Determine whether we can declare a special member function within the class at this point.

Definition at line 1051 of file SemaLookup.cpp.

References clang::Class.

Referenced by clang::Sema::ForceDeclarationOfImplicitMembers(), clang::Sema::LookupConstructors(), and clang::Sema::LookupSpecialMember().

◆ canHideTag()

static bool canHideTag ( const NamedDecl D)
static

Determine whether D can hide a tag declaration.

Definition at line 468 of file SemaLookup.cpp.

References clang::NamedDecl::getUnderlyingDecl().

Referenced by clang::LookupResult::resolveKind().

◆ checkCorrectionVisibility()

static void checkCorrectionVisibility ( Sema SemaRef,
TypoCorrection TC 
)
static

Check whether the declarations found for a typo correction are visible.

Set the correction's RequiresImport flag to true if none of the declarations are visible, false otherwise.

Definition at line 4584 of file SemaLookup.cpp.

References clang::TypoCorrection::begin(), clang::TypoCorrection::end(), clang::LookupResult::isVisible(), clang::TypoCorrection::setCorrectionDecls(), and clang::TypoCorrection::setRequiresImport().

◆ CollectEnclosingNamespace()

static void CollectEnclosingNamespace ( Sema::AssociatedNamespaceSet Namespaces,
DeclContext Ctx 
)
static

◆ CppNamespaceLookup()

static bool CppNamespaceLookup ( Sema S,
LookupResult R,
ASTContext Context,
const DeclContext NS,
UnqualUsingDirectiveSet &  UDirs 
)
static

Definition at line 1267 of file SemaLookup.cpp.

◆ DeclareImplicitMemberFunctionsWithName()

static void DeclareImplicitMemberFunctionsWithName ( Sema S,
DeclarationName  Name,
SourceLocation  Loc,
const DeclContext DC 
)
static

If there are any implicit member functions with the given name that need to be declared in the given declaration context, do so.

Definition at line 1111 of file SemaLookup.cpp.

◆ diagOpenCLBuiltinTypeError()

static QualType diagOpenCLBuiltinTypeError ( Sema S,
llvm::StringRef  TypeClass,
llvm::StringRef  Name 
)
static

Diagnose a missing builtin type.

Definition at line 706 of file SemaLookup.cpp.

◆ findAcceptableDecl()

static NamedDecl* findAcceptableDecl ( Sema SemaRef,
NamedDecl D,
unsigned  IDNS 
)
static

Retrieve the visible declaration corresponding to D, if any.

This routine determines whether the declaration D is visible in the current module, with the current imports. If not, it checks whether any redeclaration of D is visible, and if so, returns that declaration.

Returns
D, or a visible previous declaration of D, whichever is more recent and visible. If no declaration of D is visible, returns null.

Definition at line 2083 of file SemaLookup.cpp.

References clang::LookupResult::isAvailableForLookup(), and clang::Decl::redecls().

◆ findOuterContext()

static DeclContext* findOuterContext ( Scope S)
static

Find the outer declaration context from this scope.

This indicates the context that we should search up to (exclusive) before considering the parent of the specified scope.

Definition at line 1296 of file SemaLookup.cpp.

◆ getContextForScopeMatching()

static const DeclContext* getContextForScopeMatching ( const Decl D)
static

Get a representative context for a declaration such that two declarations will have the same context if they were found within the same scope.

Definition at line 359 of file SemaLookup.cpp.

References clang::Decl::getDeclContext(), clang::Decl::getLexicalDeclContext(), clang::DeclContext::getRedeclContext(), and clang::DeclContext::isFunctionOrMethod().

Referenced by clang::LookupResult::resolveKind().

◆ getDefiningModule()

static Module* getDefiningModule ( Sema S,
Decl Entity 
)
static

Find the module in which the given declaration was defined.

Definition at line 1609 of file SemaLookup.cpp.

Referenced by clang::Sema::getLookupModules().

◆ getDefinitionToImport()

static const NamedDecl* getDefinitionToImport ( const NamedDecl D)
static

Find which declaration we should import to provide the definition of the given declaration.

Definition at line 5765 of file SemaLookup.cpp.

References ID.

Referenced by clang::Sema::diagnoseMissingImport().

◆ GetFloat16Type()

static QualType GetFloat16Type ( clang::ASTContext Context)
inlinestatic

Definition at line 701 of file SemaLookup.cpp.

◆ getHeaderNameForHeader()

static std::string getHeaderNameForHeader ( Preprocessor PP,
FileEntryRef  E,
llvm::StringRef  IncludingFile 
)
static

Get a "quoted.h" or <angled.h> include path to use in a diagnostic suggesting the addition of a #include of the specified file.

Definition at line 5804 of file SemaLookup.cpp.

References clang::Preprocessor::getHeaderSearchInfo(), and clang::HeaderSearch::suggestPathToFileForDiagnostics().

Referenced by clang::Sema::diagnoseMissingImport().

◆ getIDNS()

static unsigned getIDNS ( Sema::LookupNameKind  NameKind,
bool  CPlusPlus,
bool  Redeclaration 
)
inlinestatic

◆ getNestedNameSpecifierIdentifiers()

static void getNestedNameSpecifierIdentifiers ( NestedNameSpecifier NNS,
SmallVectorImpl< const IdentifierInfo * > &  Identifiers 
)
static

◆ getOpenCLEnumType()

static QualType getOpenCLEnumType ( Sema S,
llvm::StringRef  Name 
)
static

Lookup an OpenCL enum type.

Definition at line 714 of file SemaLookup.cpp.

◆ getOpenCLTypedefType()

static QualType getOpenCLTypedefType ( Sema S,
llvm::StringRef  Name 
)
static

Lookup an OpenCL typedef type.

Definition at line 727 of file SemaLookup.cpp.

◆ GetProgModelBuiltinFctOverloads()

static void GetProgModelBuiltinFctOverloads ( ASTContext Context,
unsigned  GenTypeMaxCnt,
std::vector< QualType > &  FunctionList,
SmallVector< QualType, 1 > &  RetTypes,
SmallVector< SmallVector< QualType, 1 >, 5 > &  ArgTypes,
bool  IsVariadic 
)
static

Create a list of the candidate function overloads for a ProgModel builtin function.

Parameters
Context(in) The ASTContext instance.
GenTypeMaxCnt(in) Maximum number of types contained in a generic type used as return type or as argument. Only meaningful for generic types, otherwise equals 1.
FunctionList(out) List of FunctionTypes.
RetTypes(in) List of the possible return types.
ArgTypes(in) List of the possible types for the arguments.

Definition at line 783 of file SemaLookup.cpp.

◆ GetQualTypesForProgModelBuiltin()

template<typename ProgModel >
static void GetQualTypesForProgModelBuiltin ( Sema S,
const typename ProgModel::BuiltinStruct &  Builtin,
unsigned GenTypeMaxCnt,
SmallVector< QualType, 1 > &  RetTypes,
SmallVector< SmallVector< QualType, 1 >, 5 > &  ArgTypes 
)
static

Get the QualType instances of the return type and arguments for a ProgModel builtin function signature.

Parameters
Context(in) The Context instance.
Builtin(in) The signature currently handled.
GenTypeMaxCnt(out) Maximum number of types contained in a generic type used as return type or as argument. Only meaningful for generic types, otherwise equals 1.
RetTypes(out) List of the possible return types.
ArgTypes(out) List of the possible argument types. For each argument, ArgTypes contains QualTypes for the Cartesian product of (vector sizes) x (types) .

Definition at line 751 of file SemaLookup.cpp.

◆ hasAcceptableDeclarationImpl()

template<typename Filter >
static bool hasAcceptableDeclarationImpl ( Sema S,
const NamedDecl D,
llvm::SmallVectorImpl< Module * > *  Modules,
Filter  F,
Sema::AcceptableKind  Kind 
)
static

◆ hasAcceptableDefaultArgument()

template<typename ParmDecl >
static bool hasAcceptableDefaultArgument ( Sema S,
const ParmDecl *  D,
llvm::SmallVectorImpl< Module * > *  Modules,
Sema::AcceptableKind  Kind 
)
static

◆ hasAcceptableExplicitSpecialization()

static bool hasAcceptableExplicitSpecialization ( Sema S,
const NamedDecl D,
llvm::SmallVectorImpl< Module * > *  Modules,
Sema::AcceptableKind  Kind 
)
static

◆ hasAcceptableMemberSpecialization()

static bool hasAcceptableMemberSpecialization ( Sema S,
const NamedDecl D,
llvm::SmallVectorImpl< Module * > *  Modules,
Sema::AcceptableKind  Kind 
)
static

◆ InsertBuiltinDeclarationsFromTable()

template<typename ProgModel >
static void InsertBuiltinDeclarationsFromTable ( Sema S,
LookupResult LR,
IdentifierInfo II,
const unsigned  FctIndex,
const unsigned  Len,
std::function< void(const typename ProgModel::BuiltinStruct &, FunctionDecl &)>  ProgModelFinalizer 
)
static

When trying to resolve a function name, if ProgModel::isBuiltin() returns a non-null <Index, Len> pair, then the name is referencing a builtin function.

Add all candidate signatures to the LookUpResult.

Parameters
S(in) The Sema instance.
LR(inout) The LookupResult instance.
II(in) The identifier being resolved.
FctIndex(in) Starting index in the BuiltinTable.
Len(in) The signature list has Len elements.

Definition at line 843 of file SemaLookup.cpp.

◆ isCandidateViable()

static bool isCandidateViable ( CorrectionCandidateCallback CCC,
TypoCorrection Candidate 
)
static

◆ isImplicitlyDeclaredMemberFunctionName()

static bool isImplicitlyDeclaredMemberFunctionName ( DeclarationName  Name)
static

Determine whether this is the name of an implicitly-declared special member function.

Definition at line 1093 of file SemaLookup.cpp.

◆ isNamespaceOrTranslationUnitScope()

static bool isNamespaceOrTranslationUnitScope ( Scope S)
static

Definition at line 1287 of file SemaLookup.cpp.

◆ isPreferredLookupResult()

static bool isPreferredLookupResult ( Sema S,
Sema::LookupNameKind  Kind,
const NamedDecl D,
const NamedDecl Existing 
)
static

Determine whether D is a better lookup result than Existing, given that they declare the same entity.

Definition at line 374 of file SemaLookup.cpp.

◆ isVersionInMask()

template<typename ProgModel >
static bool isVersionInMask ( const LangOptions O,
unsigned  Mask 
)
static

◆ isVersionInMask< OpenCLBuiltin >()

template<>
bool isVersionInMask< OpenCLBuiltin > ( const LangOptions LO,
unsigned  Mask 
)

Definition at line 822 of file SemaLookup.cpp.

◆ isVersionInMask< SPIRVBuiltin >()

template<>
bool isVersionInMask< SPIRVBuiltin > ( const LangOptions LO,
unsigned  Mask 
)

Definition at line 829 of file SemaLookup.cpp.

◆ LookupDirect()

static bool LookupDirect ( Sema S,
LookupResult R,
const DeclContext DC 
)
static

Definition at line 1167 of file SemaLookup.cpp.

◆ LookupPotentialTypoResult()

static void LookupPotentialTypoResult ( Sema SemaRef,
LookupResult Res,
IdentifierInfo Name,
Scope S,
CXXScopeSpec SS,
DeclContext MemberContext,
bool  EnteringContext,
bool  isObjCIvarLookup,
bool  FindHidden 
)
static

Perform name lookup for a possible result for typo correction.

Definition at line 5081 of file SemaLookup.cpp.

◆ LookupPredefedObjCSuperType()

static void LookupPredefedObjCSuperType ( Sema Sema,
Scope S 
)
static

Looks up the declaration of "struct objc_super" and saves it for later use in building builtin declaration of objc_msgSendSuper and objc_msgSendSuper_stret.

Definition at line 1034 of file SemaLookup.cpp.

◆ LookupQualifiedNameInUsingDirectives()

static bool LookupQualifiedNameInUsingDirectives ( Sema S,
LookupResult R,
DeclContext StartDC 
)
static

Perform qualified name lookup in the namespaces nominated by using directives by the given context.

C++98 [namespace.qual]p2: Given X::m (where X is a user-declared namespace), or given ::m (where X is the global namespace), let S be the set of all declarations of m in X and in the transitive closure of all namespaces nominated by using-directives in X and its used namespaces, except that using-directives are ignored in any namespace, including X, directly containing one or more declarations of m. No namespace is searched more than once in the lookup of a name. If S is the empty set, the program is ill-formed. Otherwise, if S has exactly one member, or if the context of the reference is a using-declaration (namespace.udecl), S is the required set of declarations of m. Otherwise if the use of m is not one that allows a unique declaration to be chosen from S, the program is ill-formed.

C++98 [namespace.qual]p5: During the lookup of a qualified namespace member name, if the lookup finds more than one declaration of the member, and if one declaration introduces a class name or enumeration name and the other declarations either introduce the same object, the same enumerator or a set of functions, the non-type name hides the class or enumeration name if and only if the declarations are from the same namespace; otherwise (the declarations are from different namespaces), the program is ill-formed.

Definition at line 2385 of file SemaLookup.cpp.

Variable Documentation

◆ MaxTypoDistanceResultSets

const unsigned MaxTypoDistanceResultSets = 5
static

Definition at line 4715 of file SemaLookup.cpp.