Skip to content
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