@@ -33,17 +33,19 @@ static void BuildParentMap(MapTy& M, Stmt* S,
3333 switch (S->getStmtClass ()) {
3434 case Stmt::PseudoObjectExprClass: {
3535 PseudoObjectExpr *POE = cast<PseudoObjectExpr>(S);
36-
37- if (OVMode == OV_Opaque && M.contains (POE->getSyntacticForm ()))
38- break ;
39-
40- // If we are rebuilding the map, clear out any existing state.
41- if (M.contains (POE->getSyntacticForm ()))
36+ Expr *SF = POE->getSyntacticForm ();
37+
38+ auto [Iter, Inserted] = M.try_emplace (SF, S);
39+ if (!Inserted) {
40+ // Nothing more to do in opaque mode if we are updating an existing map.
41+ if (OVMode == OV_Opaque)
42+ break ;
43+ // Update the entry in transparent mode, and clear existing state.
44+ Iter->second = SF;
4245 for (Stmt *SubStmt : S->children ())
4346 M.erase (SubStmt);
44-
45- M[POE->getSyntacticForm ()] = S;
46- BuildParentMap (M, POE->getSyntacticForm (), OV_Transparent);
47+ }
48+ BuildParentMap (M, SF, OV_Transparent);
4749
4850 for (PseudoObjectExpr::semantics_iterator I = POE->semantics_begin (),
4951 E = POE->semantics_end ();
@@ -78,10 +80,15 @@ static void BuildParentMap(MapTy& M, Stmt* S,
7880 // The right thing to do is to give the OpaqueValueExpr its syntactic
7981 // parent, then not reassign that when traversing the semantic expressions.
8082 OpaqueValueExpr *OVE = cast<OpaqueValueExpr>(S);
81- if (OVMode == OV_Transparent || !M.contains (OVE->getSourceExpr ())) {
82- M[OVE->getSourceExpr ()] = S;
83- BuildParentMap (M, OVE->getSourceExpr (), OV_Transparent);
83+ Expr *SrcExpr = OVE->getSourceExpr ();
84+ auto [Iter, Inserted] = M.try_emplace (SrcExpr, S);
85+ // Force update in transparent mode.
86+ if (!Inserted && OVMode == OV_Transparent) {
87+ Iter->second = S;
88+ Inserted = true ;
8489 }
90+ if (Inserted)
91+ BuildParentMap (M, SrcExpr, OV_Transparent);
8592 break ;
8693 }
8794 case Stmt::CapturedStmtClass:
0 commit comments