Skip to content

Commit

Permalink
[Clang][AST][NFC] Move template argument dependence computations for …
Browse files Browse the repository at this point in the history
…MemberExpr to computeDependence (llvm#86682)

(This patch depends on llvm#86678)

Pretty straightforward change, addresses the FIXME's in
`computeDependence(MemberExpr*)` and `MemberExpr::Create` by moving the
template argument dependence computations to `computeDependence`.
  • Loading branch information
sdkrystian authored Apr 2, 2024
1 parent a6d932b commit 0cd44ff
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 39 deletions.
8 changes: 5 additions & 3 deletions clang/include/clang/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3209,9 +3209,11 @@ class MemberExpr final
}

MemberExpr(Expr *Base, bool IsArrow, SourceLocation OperatorLoc,
ValueDecl *MemberDecl, const DeclarationNameInfo &NameInfo,
QualType T, ExprValueKind VK, ExprObjectKind OK,
NonOdrUseReason NOUR);
NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
ValueDecl *MemberDecl, DeclAccessPair FoundDecl,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *TemplateArgs, QualType T,
ExprValueKind VK, ExprObjectKind OK, NonOdrUseReason NOUR);
MemberExpr(EmptyShell Empty)
: Expr(MemberExprClass, Empty), Base(), MemberDecl() {}

Expand Down
4 changes: 3 additions & 1 deletion clang/lib/AST/ComputeDependence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,9 @@ ExprDependence clang::computeDependence(MemberExpr *E) {
D |= toExprDependence(NNS->getDependence() &
~NestedNameSpecifierDependence::Dependent);

for (const auto &A : E->template_arguments())
D |= toExprDependence(A.getArgument().getDependence());

auto *MemberDecl = E->getMemberDecl();
if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) {
DeclContext *DC = MemberDecl->getDeclContext();
Expand All @@ -670,7 +673,6 @@ ExprDependence clang::computeDependence(MemberExpr *E) {
D |= ExprDependence::Type;
}
}
// FIXME: move remaining dependence computation from MemberExpr::Create()
return D;
}

Expand Down
64 changes: 29 additions & 35 deletions clang/lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1712,21 +1712,42 @@ UnaryExprOrTypeTraitExpr::UnaryExprOrTypeTraitExpr(
}

MemberExpr::MemberExpr(Expr *Base, bool IsArrow, SourceLocation OperatorLoc,
ValueDecl *MemberDecl,
const DeclarationNameInfo &NameInfo, QualType T,
NestedNameSpecifierLoc QualifierLoc,
SourceLocation TemplateKWLoc, ValueDecl *MemberDecl,
DeclAccessPair FoundDecl,
const DeclarationNameInfo &NameInfo,
const TemplateArgumentListInfo *TemplateArgs, QualType T,
ExprValueKind VK, ExprObjectKind OK,
NonOdrUseReason NOUR)
: Expr(MemberExprClass, T, VK, OK), Base(Base), MemberDecl(MemberDecl),
MemberDNLoc(NameInfo.getInfo()), MemberLoc(NameInfo.getLoc()) {
assert(!NameInfo.getName() ||
MemberDecl->getDeclName() == NameInfo.getName());
MemberExprBits.IsArrow = IsArrow;
MemberExprBits.HasQualifier = false;
MemberExprBits.HasFoundDecl = false;
MemberExprBits.HasTemplateKWAndArgsInfo = false;
MemberExprBits.HasQualifier = QualifierLoc.hasQualifier();
MemberExprBits.HasFoundDecl =
FoundDecl.getDecl() != MemberDecl ||
FoundDecl.getAccess() != MemberDecl->getAccess();
MemberExprBits.HasTemplateKWAndArgsInfo =
TemplateArgs || TemplateKWLoc.isValid();
MemberExprBits.HadMultipleCandidates = false;
MemberExprBits.NonOdrUseReason = NOUR;
MemberExprBits.OperatorLoc = OperatorLoc;

if (hasQualifier())
new (getTrailingObjects<NestedNameSpecifierLoc>())
NestedNameSpecifierLoc(QualifierLoc);
if (hasFoundDecl())
*getTrailingObjects<DeclAccessPair>() = FoundDecl;
if (TemplateArgs) {
auto Deps = TemplateArgumentDependence::None;
getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(),
Deps);
} else if (TemplateKWLoc.isValid()) {
getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
TemplateKWLoc);
}
setDependence(computeDependence(this));
}

Expand All @@ -1747,36 +1768,9 @@ MemberExpr *MemberExpr::Create(
TemplateArgs ? TemplateArgs->size() : 0);

void *Mem = C.Allocate(Size, alignof(MemberExpr));
MemberExpr *E = new (Mem) MemberExpr(Base, IsArrow, OperatorLoc, MemberDecl,
NameInfo, T, VK, OK, NOUR);

E->MemberExprBits.HasQualifier = HasQualifier;
E->MemberExprBits.HasFoundDecl = HasFoundDecl;
E->MemberExprBits.HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;

if (HasQualifier)
new (E->getTrailingObjects<NestedNameSpecifierLoc>())
NestedNameSpecifierLoc(QualifierLoc);
if (HasFoundDecl)
*E->getTrailingObjects<DeclAccessPair>() = FoundDecl;

// FIXME: remove remaining dependence computation to computeDependence().
auto Deps = E->getDependence();
if (TemplateArgs) {
auto TemplateArgDeps = TemplateArgumentDependence::None;
E->getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
TemplateKWLoc, *TemplateArgs,
E->getTrailingObjects<TemplateArgumentLoc>(), TemplateArgDeps);
for (const TemplateArgumentLoc &ArgLoc : TemplateArgs->arguments()) {
Deps |= toExprDependence(ArgLoc.getArgument().getDependence());
}
} else if (TemplateKWLoc.isValid()) {
E->getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
TemplateKWLoc);
}
E->setDependence(Deps);

return E;
return new (Mem) MemberExpr(Base, IsArrow, OperatorLoc, QualifierLoc,
TemplateKWLoc, MemberDecl, FoundDecl, NameInfo,
TemplateArgs, T, VK, OK, NOUR);
}

MemberExpr *MemberExpr::CreateEmpty(const ASTContext &Context,
Expand Down

0 comments on commit 0cd44ff

Please sign in to comment.