Skip to content

Commit 2cae10e

Browse files
committed
[clang] explicitly check if ParentMap contains key
The implementation of ParentMap assumes that the key is absent if it is mapped to nullptr. This breaks when trying to store a tuple as the value type. Remove this assumption by explicit uses of `contains()` and `erase()`.
1 parent b51a082 commit 2cae10e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

clang/lib/AST/ParentMap.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ static void BuildParentMap(MapTy& M, Stmt* S,
3434
case Stmt::PseudoObjectExprClass: {
3535
PseudoObjectExpr *POE = cast<PseudoObjectExpr>(S);
3636

37-
if (OVMode == OV_Opaque && M[POE->getSyntacticForm()])
37+
if (OVMode == OV_Opaque && M.contains(POE->getSyntacticForm()))
3838
break;
3939

4040
// If we are rebuilding the map, clear out any existing state.
41-
if (M[POE->getSyntacticForm()])
41+
if (M.contains(POE->getSyntacticForm()))
4242
for (Stmt *SubStmt : S->children())
43-
M[SubStmt] = nullptr;
43+
M.erase(SubStmt);
4444

4545
M[POE->getSyntacticForm()] = S;
4646
BuildParentMap(M, POE->getSyntacticForm(), OV_Transparent);
@@ -78,7 +78,7 @@ static void BuildParentMap(MapTy& M, Stmt* S,
7878
// The right thing to do is to give the OpaqueValueExpr its syntactic
7979
// parent, then not reassign that when traversing the semantic expressions.
8080
OpaqueValueExpr *OVE = cast<OpaqueValueExpr>(S);
81-
if (OVMode == OV_Transparent || !M[OVE->getSourceExpr()]) {
81+
if (OVMode == OV_Transparent || !M.contains(OVE->getSourceExpr())) {
8282
M[OVE->getSourceExpr()] = S;
8383
BuildParentMap(M, OVE->getSourceExpr(), OV_Transparent);
8484
}

0 commit comments

Comments
 (0)