aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ParentMap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/AST/ParentMap.cpp')
-rw-r--r--clang/lib/AST/ParentMap.cpp33
1 files changed, 20 insertions, 13 deletions
diff --git a/clang/lib/AST/ParentMap.cpp b/clang/lib/AST/ParentMap.cpp
index fd749b0..e62e71b 100644
--- a/clang/lib/AST/ParentMap.cpp
+++ b/clang/lib/AST/ParentMap.cpp
@@ -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 = S;
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();
@@ -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: