Skip to content

[clang] [NFC] explicitly check if ParentMap contains key #121736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions clang/lib/AST/ParentMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ static void BuildParentMap(MapTy& M, Stmt* S,
switch (S->getStmtClass()) {
case Stmt::PseudoObjectExprClass: {
PseudoObjectExpr *POE = cast<PseudoObjectExpr>(S);

if (OVMode == OV_Opaque && M[POE->getSyntacticForm()])
break;

// If we are rebuilding the map, clear out any existing state.
if (M[POE->getSyntacticForm()])
Expr *SF = POE->getSyntacticForm();

auto [Iter, Inserted] = M.try_emplace(SF, S);
if (!Inserted) {
// Nothing more to do in opaque mode if we are updating an existing map.
if (OVMode == OV_Opaque)
break;
// Update the entry in transparent mode, and clear existing state.
Iter->second = SF;
for (Stmt *SubStmt : S->children())
M[SubStmt] = nullptr;

M[POE->getSyntacticForm()] = S;
BuildParentMap(M, POE->getSyntacticForm(), OV_Transparent);
M.erase(SubStmt);
}
BuildParentMap(M, SF, OV_Transparent);

for (PseudoObjectExpr::semantics_iterator I = POE->semantics_begin(),
E = POE->semantics_end();
Expand Down Expand Up @@ -78,10 +80,15 @@ static void BuildParentMap(MapTy& M, Stmt* S,
// The right thing to do is to give the OpaqueValueExpr its syntactic
// parent, then not reassign that when traversing the semantic expressions.
OpaqueValueExpr *OVE = cast<OpaqueValueExpr>(S);
if (OVMode == OV_Transparent || !M[OVE->getSourceExpr()]) {
M[OVE->getSourceExpr()] = S;
BuildParentMap(M, OVE->getSourceExpr(), OV_Transparent);
Expr *SrcExpr = OVE->getSourceExpr();
auto [Iter, Inserted] = M.try_emplace(SrcExpr, S);
// Force update in transparent mode.
if (!Inserted && OVMode == OV_Transparent) {
Iter->second = S;
Inserted = true;
}
if (Inserted)
BuildParentMap(M, SrcExpr, OV_Transparent);
break;
}
case Stmt::CapturedStmtClass:
Expand Down
Loading