Skip to content

Commit 329574e

Browse files
committed
[FOLD] LookupParsedName takes ObjectType
1 parent 5b0461f commit 329574e

File tree

12 files changed

+93
-46
lines changed

12 files changed

+93
-46
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7725,7 +7725,10 @@ class Sema final {
77257725
bool InUnqualifiedLookup = false);
77267726
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
77277727
CXXScopeSpec &SS);
7728-
bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS,
7728+
bool LookupParsedName(LookupResult &R,
7729+
Scope *S,
7730+
CXXScopeSpec *SS,
7731+
QualType ObjectType,
77297732
bool AllowBuiltinCreation = false,
77307733
bool EnteringContext = false);
77317734
ObjCProtocolDecl *

clang/lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2994,7 +2994,7 @@ bool Parser::ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
29942994
<< TokenName << TagName << getLangOpts().CPlusPlus
29952995
<< FixItHint::CreateInsertion(Tok.getLocation(), FixitTagName);
29962996

2997-
if (Actions.LookupParsedName(R, getCurScope(), SS)) {
2997+
if (Actions.LookupParsedName(R, getCurScope(), SS, /*ObjectType=*/QualType())) {
29982998
for (LookupResult::iterator I = R.begin(), IEnd = R.end();
29992999
I != IEnd; ++I)
30003000
Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)

clang/lib/Sema/HLSLExternalSemaSource.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ struct BuiltinTypeDeclBuilder {
131131
DeclarationNameInfo NameInfo =
132132
DeclarationNameInfo(DeclarationName(&II), SourceLocation());
133133
LookupResult R(S, NameInfo, Sema::LookupOrdinaryName);
134-
S.LookupParsedName(R, S.getCurScope(), &SS, false);
134+
S.LookupParsedName(R, S.getCurScope(), &SS,
135+
/*ObjectType=*/QualType(),
136+
/*AllowBuiltinCreation*/false);
135137
assert(R.isSingleResult() &&
136138
"Since this is a builtin it should always resolve!");
137139
auto *VD = cast<ValueDecl>(R.getFoundDecl());

clang/lib/Sema/SemaAttr.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,10 @@ void Sema::ActOnPragmaUnused(const Token &IdTok, Scope *curScope,
825825

826826
IdentifierInfo *Name = IdTok.getIdentifierInfo();
827827
LookupResult Lookup(*this, Name, IdTok.getLocation(), LookupOrdinaryName);
828-
LookupParsedName(Lookup, curScope, nullptr, true);
828+
LookupParsedName(Lookup, curScope,
829+
/*SS=*/nullptr,
830+
/*ObjectType=*/QualType(),
831+
/*AllowBuiltinCreation*/true);
829832

830833
if (Lookup.empty()) {
831834
Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var)

clang/lib/Sema/SemaDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ static bool isTagTypeWithMissingTag(Sema &SemaRef, LookupResult &Result,
828828
IdentifierInfo *&Name,
829829
SourceLocation NameLoc) {
830830
LookupResult R(SemaRef, Name, NameLoc, Sema::LookupTagName);
831-
SemaRef.LookupParsedName(R, S, &SS);
831+
SemaRef.LookupParsedName(R, S, &SS, /*ObjectType=*/QualType());
832832
if (TagDecl *Tag = R.getAsSingle<TagDecl>()) {
833833
StringRef FixItTagName;
834834
switch (Tag->getTagKind()) {
@@ -865,7 +865,7 @@ static bool isTagTypeWithMissingTag(Sema &SemaRef, LookupResult &Result,
865865

866866
// Replace lookup results with just the tag decl.
867867
Result.clear(Sema::LookupTagName);
868-
SemaRef.LookupParsedName(Result, S, &SS);
868+
SemaRef.LookupParsedName(Result, S, &SS, /*ObjectType=*/QualType());
869869
return true;
870870
}
871871

@@ -892,7 +892,7 @@ Sema::NameClassification Sema::ClassifyName(Scope *S, CXXScopeSpec &SS,
892892
}
893893

894894
LookupResult Result(*this, Name, NameLoc, LookupOrdinaryName);
895-
LookupParsedName(Result, S, &SS, !CurMethod);
895+
LookupParsedName(Result, S, &SS, /*ObjectType=*/QualType(), /*AllowBuiltinCreation*/!CurMethod);
896896

897897
if (SS.isInvalid())
898898
return NameClassification::Error();

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4514,7 +4514,7 @@ Sema::BuildMemInitializer(Decl *ConstructorD,
45144514
DS.getBeginLoc(), DS.getEllipsisLoc());
45154515
} else {
45164516
LookupResult R(*this, MemberOrBase, IdLoc, LookupOrdinaryName);
4517-
LookupParsedName(R, S, &SS);
4517+
LookupParsedName(R, S, &SS, /*ObjectType=*/QualType());
45184518

45194519
TypeDecl *TyD = R.getAsSingle<TypeDecl>();
45204520
if (!TyD) {
@@ -12224,7 +12224,7 @@ Decl *Sema::ActOnUsingDirective(Scope *S, SourceLocation UsingLoc,
1222412224

1222512225
// Lookup namespace name.
1222612226
LookupResult R(*this, NamespcName, IdentLoc, LookupNamespaceName);
12227-
LookupParsedName(R, S, &SS);
12227+
LookupParsedName(R, S, &SS, /*ObjectType=*/QualType());
1222812228
if (R.isAmbiguous())
1222912229
return nullptr;
1223012230

@@ -13682,7 +13682,7 @@ Decl *Sema::ActOnNamespaceAliasDef(Scope *S, SourceLocation NamespaceLoc,
1368213682

1368313683
// Lookup the namespace name.
1368413684
LookupResult R(*this, Ident, IdentLoc, LookupNamespaceName);
13685-
LookupParsedName(R, S, &SS);
13685+
LookupParsedName(R, S, &SS, /*ObjectType=*/QualType());
1368613686

1368713687
if (R.isAmbiguous())
1368813688
return nullptr;

clang/lib/Sema/SemaExpr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,7 +2751,8 @@ Sema::ActOnIdExpression(Scope *S, CXXScopeSpec &SS,
27512751
// results until we get here but it's likely not worth it.
27522752
bool MemberOfUnknownSpecialization;
27532753
AssumedTemplateKind AssumedTemplate;
2754-
if (LookupTemplateName(R, S, SS, QualType(), /*EnteringContext=*/false,
2754+
if (LookupTemplateName(R, S, SS, /*ObjectType=*/QualType(),
2755+
/*EnteringContext=*/false,
27552756
MemberOfUnknownSpecialization, TemplateKWLoc,
27562757
&AssumedTemplate))
27572758
return ExprError();
@@ -2762,7 +2763,7 @@ Sema::ActOnIdExpression(Scope *S, CXXScopeSpec &SS,
27622763
IsAddressOfOperand, TemplateArgs);
27632764
} else {
27642765
bool IvarLookupFollowUp = II && !SS.isSet() && getCurMethodDecl();
2765-
LookupParsedName(R, S, &SS, !IvarLookupFollowUp);
2766+
LookupParsedName(R, S, &SS, /*ObjectType=*/QualType(), /*AllowBuiltinCreation=*/!IvarLookupFollowUp);
27662767

27672768
// If the result might be in a dependent base class, this is a dependent
27682769
// id-expression.

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9073,7 +9073,7 @@ Sema::CheckMicrosoftIfExistsSymbol(Scope *S,
90739073
// Do the redeclaration lookup in the current scope.
90749074
LookupResult R(*this, TargetNameInfo, Sema::LookupAnyName,
90759075
Sema::NotForRedeclaration);
9076-
LookupParsedName(R, S, &SS);
9076+
LookupParsedName(R, S, &SS, /*ObjectType=*/QualType());
90779077
R.suppressDiagnostics();
90789078

90799079
switch (R.getResultKind()) {

clang/lib/Sema/SemaExprMember.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -675,13 +675,15 @@ static bool LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R,
675675
CXXScopeSpec &SS, bool HasTemplateArgs,
676676
SourceLocation TemplateKWLoc,
677677
TypoExpr *&TE) {
678+
#if 1
678679
DeclContext *DC = SemaRef.computeDeclContext(RTy);
679680
// If the object expression is dependent and isn't the current instantiation,
680681
// lookup will not find anything and we must defer until instantiation.
681682
if (!DC) {
682683
R.setNotFoundInCurrentInstantiation();
683684
return false;
684685
}
686+
#endif
685687

686688
// FIXME: Should this use Name.isDependentName()?
687689
if (DeclarationName Name = R.getLookupName();
@@ -698,15 +700,21 @@ static bool LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R,
698700
OpLoc, RTy, diag::err_typecheck_incomplete_tag, BaseRange))
699701
return true;
700702

703+
// LookupTemplateName/LookupParsedName don't expect these both to exist simultaneously.
704+
QualType ObjectType = SS.isSet() ? QualType() : RTy;
701705
if (HasTemplateArgs || TemplateKWLoc.isValid()) {
702-
// LookupTemplateName doesn't expect these both to exist simultaneously.
703-
QualType ObjectType = SS.isSet() ? QualType() : RTy;
704-
705706
bool MOUS;
706-
return SemaRef.LookupTemplateName(R, nullptr, SS, ObjectType, false, MOUS,
707+
return SemaRef.LookupTemplateName(R,
708+
/*S=*/nullptr,
709+
SS,
710+
ObjectType,
711+
/*EnteringContext=*/false,
712+
MOUS,
707713
TemplateKWLoc);
708714
}
709-
715+
#if 0
716+
SemaRef.LookupParsedName(R, /*S=*/nullptr, &SS, ObjectType);
717+
#else
710718
if (SS.isSet()) {
711719
// If the member name was a qualified-id, look into the
712720
// nested-name-specifier.
@@ -735,12 +743,18 @@ static bool LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R,
735743

736744
// The record definition is complete, now look up the member.
737745
SemaRef.LookupQualifiedName(R, DC, SS);
746+
#endif
738747

739748
if (!R.empty() || R.wasNotFoundInCurrentInstantiation())
740749
return false;
741750

742751
DeclarationName Typo = R.getLookupName();
743752
SourceLocation TypoLoc = R.getNameLoc();
753+
#if 0
754+
DeclContext *DC = SS.isSet()
755+
? SemaRef.computeDeclContext(SS)
756+
: SemaRef.computeDeclContext(RTy);
757+
#endif
744758

745759
struct QueryState {
746760
Sema &SemaRef;

clang/lib/Sema/SemaLookup.cpp

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,39 +2716,57 @@ bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
27162716
/// context of the scope-specifier SS (if present).
27172717
///
27182718
/// @returns True if any decls were found (but possibly ambiguous)
2719-
bool Sema::LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS,
2720-
bool AllowBuiltinCreation, bool EnteringContext) {
2719+
bool Sema::LookupParsedName(LookupResult &R,
2720+
Scope *S,
2721+
CXXScopeSpec *SS,
2722+
QualType ObjectType,
2723+
bool AllowBuiltinCreation,
2724+
bool EnteringContext) {
27212725
if (SS && SS->isInvalid()) {
27222726
// When the scope specifier is invalid, don't even look for
27232727
// anything.
27242728
return false;
27252729
}
27262730

2727-
if (SS && SS->isSet()) {
2728-
NestedNameSpecifier *NNS = SS->getScopeRep();
2729-
if (NNS->getKind() == NestedNameSpecifier::Super)
2731+
// Determine where to perform name lookup
2732+
DeclContext *DC = nullptr;
2733+
if (!ObjectType.isNull()) {
2734+
// This nested-name-specifier occurs in a member access expression, e.g.,
2735+
// x->B::f, and we are looking into the type of the object.
2736+
assert((!SS || SS->isEmpty()) && "ObjectType and scope specifier cannot coexist");
2737+
DC = computeDeclContext(ObjectType);
2738+
assert(((!DC && ObjectType->isDependentType()) ||
2739+
!ObjectType->isIncompleteType() ||
2740+
!ObjectType->getAs<TagType>() ||
2741+
ObjectType->castAs<TagType>()->isBeingDefined()) &&
2742+
"Caller should have completed object type");
2743+
} else if (SS && SS->isNotEmpty()) {
2744+
if (NestedNameSpecifier *NNS = SS->getScopeRep();
2745+
NNS->getKind() == NestedNameSpecifier::Super)
27302746
return LookupInSuper(R, NNS->getAsRecordDecl());
2731-
2732-
if (DeclContext *DC = computeDeclContext(*SS, EnteringContext)) {
2733-
// We have resolved the scope specifier to a particular declaration
2734-
// contex, and will perform name lookup in that context.
2747+
// This nested-name-specifier occurs after another nested-name-specifier,
2748+
// so long into the context associated with the prior nested-name-specifier.
2749+
if (DC = computeDeclContext(*SS, EnteringContext)) {
2750+
// The declaration context must be complete.
27352751
if (!DC->isDependentContext() && RequireCompleteDeclContext(*SS, DC))
27362752
return false;
2737-
27382753
R.setContextRange(SS->getRange());
2739-
return LookupQualifiedName(R, DC);
27402754
}
2741-
2742-
// We could not resolve the scope specified to a specific declaration
2743-
// context, which means that SS refers to an unknown specialization.
2744-
// Name lookup can't find anything in this case.
2745-
R.setNotFoundInCurrentInstantiation();
2746-
R.setContextRange(SS->getRange());
2747-
return false;
2755+
} else {
2756+
// Perform unqualified name lookup starting in the given scope.
2757+
return LookupName(R, S, AllowBuiltinCreation);
27482758
}
27492759

2750-
// Perform unqualified name lookup starting in the given scope.
2751-
return LookupName(R, S, AllowBuiltinCreation);
2760+
// If we were able to compute a declaration context, perform qualified name
2761+
// lookup in that context.
2762+
if (DC)
2763+
return LookupQualifiedName(R, DC);
2764+
2765+
// We could not resolve the scope specified to a specific declaration
2766+
// context, which means that SS refers to an unknown specialization.
2767+
// Name lookup can't find anything in this case.
2768+
R.setNotFoundInCurrentInstantiation();
2769+
return false;
27522770
}
27532771

27542772
/// Perform qualified name lookup into all base classes of the given
@@ -5011,7 +5029,9 @@ static void LookupPotentialTypoResult(Sema &SemaRef,
50115029
return;
50125030
}
50135031

5014-
SemaRef.LookupParsedName(Res, S, SS, /*AllowBuiltinCreation=*/false,
5032+
SemaRef.LookupParsedName(Res, S, SS,
5033+
/*ObjectType=*/QualType(),
5034+
/*AllowBuiltinCreation=*/false,
50155035
EnteringContext);
50165036

50175037
// Fake ivar lookup; this should really be part of

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3052,7 +3052,9 @@ ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope,
30523052
const DeclarationNameInfo &Id,
30533053
OpenMPDirectiveKind Kind) {
30543054
LookupResult Lookup(*this, Id, LookupOrdinaryName);
3055-
LookupParsedName(Lookup, CurScope, &ScopeSpec, true);
3055+
LookupParsedName(Lookup, CurScope, &ScopeSpec,
3056+
/*ObjectType=*/QualType(),
3057+
/*AllowBuiltinCreation=*/true);
30563058

30573059
if (Lookup.isAmbiguous())
30583060
return ExprError();
@@ -7303,7 +7305,7 @@ void Sema::ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(
73037305
IdentifierInfo *BaseII = D.getIdentifier();
73047306
LookupResult Lookup(*this, DeclarationName(BaseII), D.getIdentifierLoc(),
73057307
LookupOrdinaryName);
7306-
LookupParsedName(Lookup, S, &D.getCXXScopeSpec());
7308+
LookupParsedName(Lookup, S, &D.getCXXScopeSpec(), /*ObjectType=*/QualType());
73077309

73087310
TypeSourceInfo *TInfo = GetTypeForDeclarator(D);
73097311
QualType FType = TInfo->getType();
@@ -19157,7 +19159,7 @@ buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range,
1915719159
if (S) {
1915819160
LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName);
1915919161
Lookup.suppressDiagnostics();
19160-
while (S && SemaRef.LookupParsedName(Lookup, S, &ReductionIdScopeSpec)) {
19162+
while (S && SemaRef.LookupParsedName(Lookup, S, &ReductionIdScopeSpec, /*ObjectType=*/QualType())) {
1916119163
NamedDecl *D = Lookup.getRepresentativeDecl();
1916219164
do {
1916319165
S = S->getParent();
@@ -22010,7 +22012,7 @@ static ExprResult buildUserDefinedMapperRef(Sema &SemaRef, Scope *S,
2201022012
LookupResult Lookup(SemaRef, MapperId, Sema::LookupOMPMapperName);
2201122013
Lookup.suppressDiagnostics();
2201222014
if (S) {
22013-
while (S && SemaRef.LookupParsedName(Lookup, S, &MapperIdScopeSpec)) {
22015+
while (S && SemaRef.LookupParsedName(Lookup, S, &MapperIdScopeSpec, /*ObjectType=*/QualType())) {
2201422016
NamedDecl *D = Lookup.getRepresentativeDecl();
2201522017
while (S && !S->isDeclScope(D))
2201622018
S = S->getParent();
@@ -23317,7 +23319,9 @@ NamedDecl *Sema::lookupOpenMPDeclareTargetName(Scope *CurScope,
2331723319
CXXScopeSpec &ScopeSpec,
2331823320
const DeclarationNameInfo &Id) {
2331923321
LookupResult Lookup(*this, Id, LookupOrdinaryName);
23320-
LookupParsedName(Lookup, CurScope, &ScopeSpec, true);
23322+
LookupParsedName(Lookup, CurScope, &ScopeSpec,
23323+
/*ObjectType=*/QualType(),
23324+
/*AllowBuiltinCreation=*/true);
2332123325

2332223326
if (Lookup.isAmbiguous())
2332323327
return nullptr;

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5668,7 +5668,7 @@ bool Sema::CheckTemplateTypeArgument(
56685668

56695669
if (auto *II = NameInfo.getName().getAsIdentifierInfo()) {
56705670
LookupResult Result(*this, NameInfo, LookupOrdinaryName);
5671-
LookupParsedName(Result, CurScope, &SS);
5671+
LookupParsedName(Result, CurScope, &SS, /*ObjectType=*/QualType());
56725672

56735673
if (Result.getAsSingle<TypeDecl>() ||
56745674
Result.getResultKind() ==
@@ -11025,7 +11025,7 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
1102511025
: TSK_ExplicitInstantiationDeclaration;
1102611026

1102711027
LookupResult Previous(*this, NameInfo, LookupOrdinaryName);
11028-
LookupParsedName(Previous, S, &D.getCXXScopeSpec());
11028+
LookupParsedName(Previous, S, &D.getCXXScopeSpec(), /*ObjectType=*/QualType());
1102911029

1103011030
if (!R->isFunctionType()) {
1103111031
// C++ [temp.explicit]p1:

0 commit comments

Comments
 (0)