Skip to content

Commit cc604a9

Browse files
committed
[FOLD] LookupParsedName takes ObjectType
1 parent b4ac4df commit cc604a9

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
@@ -7739,7 +7739,10 @@ class Sema final {
77397739
bool InUnqualifiedLookup = false);
77407740
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
77417741
CXXScopeSpec &SS);
7742-
bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS,
7742+
bool LookupParsedName(LookupResult &R,
7743+
Scope *S,
7744+
CXXScopeSpec *SS,
7745+
QualType ObjectType,
77437746
bool AllowBuiltinCreation = false,
77447747
bool EnteringContext = false);
77457748
ObjCProtocolDecl *

clang/lib/Parse/ParseDecl.cpp

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

3001-
if (Actions.LookupParsedName(R, getCurScope(), SS)) {
3001+
if (Actions.LookupParsedName(R, getCurScope(), SS, /*ObjectType=*/QualType())) {
30023002
for (LookupResult::iterator I = R.begin(), IEnd = R.end();
30033003
I != IEnd; ++I)
30043004
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
@@ -837,7 +837,10 @@ void Sema::ActOnPragmaUnused(const Token &IdTok, Scope *curScope,
837837

838838
IdentifierInfo *Name = IdTok.getIdentifierInfo();
839839
LookupResult Lookup(*this, Name, IdTok.getLocation(), LookupOrdinaryName);
840-
LookupParsedName(Lookup, curScope, nullptr, true);
840+
LookupParsedName(Lookup, curScope,
841+
/*SS=*/nullptr,
842+
/*ObjectType=*/QualType(),
843+
/*AllowBuiltinCreation*/true);
841844

842845
if (Lookup.empty()) {
843846
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) {
@@ -12225,7 +12225,7 @@ Decl *Sema::ActOnUsingDirective(Scope *S, SourceLocation UsingLoc,
1222512225

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

@@ -13684,7 +13684,7 @@ Decl *Sema::ActOnNamespaceAliasDef(Scope *S, SourceLocation NamespaceLoc,
1368413684

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

1368913689
if (R.isAmbiguous())
1369013690
return nullptr;

clang/lib/Sema/SemaExpr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,7 +2770,8 @@ Sema::ActOnIdExpression(Scope *S, CXXScopeSpec &SS,
27702770
// results until we get here but it's likely not worth it.
27712771
bool MemberOfUnknownSpecialization;
27722772
AssumedTemplateKind AssumedTemplate;
2773-
if (LookupTemplateName(R, S, SS, QualType(), /*EnteringContext=*/false,
2773+
if (LookupTemplateName(R, S, SS, /*ObjectType=*/QualType(),
2774+
/*EnteringContext=*/false,
27742775
MemberOfUnknownSpecialization, TemplateKWLoc,
27752776
&AssumedTemplate))
27762777
return ExprError();
@@ -2781,7 +2782,7 @@ Sema::ActOnIdExpression(Scope *S, CXXScopeSpec &SS,
27812782
IsAddressOfOperand, TemplateArgs);
27822783
} else {
27832784
bool IvarLookupFollowUp = II && !SS.isSet() && getCurMethodDecl();
2784-
LookupParsedName(R, S, &SS, !IvarLookupFollowUp);
2785+
LookupParsedName(R, S, &SS, /*ObjectType=*/QualType(), /*AllowBuiltinCreation=*/!IvarLookupFollowUp);
27852786

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

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9081,7 +9081,7 @@ Sema::CheckMicrosoftIfExistsSymbol(Scope *S,
90819081
// Do the redeclaration lookup in the current scope.
90829082
LookupResult R(*this, TargetNameInfo, Sema::LookupAnyName,
90839083
Sema::NotForRedeclaration);
9084-
LookupParsedName(R, S, &SS);
9084+
LookupParsedName(R, S, &SS, /*ObjectType=*/QualType());
90859085
R.suppressDiagnostics();
90869086

90879087
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
@@ -5015,7 +5033,9 @@ static void LookupPotentialTypoResult(Sema &SemaRef,
50155033
return;
50165034
}
50175035

5018-
SemaRef.LookupParsedName(Res, S, SS, /*AllowBuiltinCreation=*/false,
5036+
SemaRef.LookupParsedName(Res, S, SS,
5037+
/*ObjectType=*/QualType(),
5038+
/*AllowBuiltinCreation=*/false,
50195039
EnteringContext);
50205040

50215041
// 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
@@ -5696,7 +5696,7 @@ bool Sema::CheckTemplateTypeArgument(
56965696

56975697
if (auto *II = NameInfo.getName().getAsIdentifierInfo()) {
56985698
LookupResult Result(*this, NameInfo, LookupOrdinaryName);
5699-
LookupParsedName(Result, CurScope, &SS);
5699+
LookupParsedName(Result, CurScope, &SS, /*ObjectType=*/QualType());
57005700

57015701
if (Result.getAsSingle<TypeDecl>() ||
57025702
Result.getResultKind() ==
@@ -11058,7 +11058,7 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
1105811058
: TSK_ExplicitInstantiationDeclaration;
1105911059

1106011060
LookupResult Previous(*this, NameInfo, LookupOrdinaryName);
11061-
LookupParsedName(Previous, S, &D.getCXXScopeSpec());
11061+
LookupParsedName(Previous, S, &D.getCXXScopeSpec(), /*ObjectType=*/QualType());
1106211062

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

0 commit comments

Comments
 (0)