https://github.com/ssahasra created https://github.com/llvm/llvm-project/pull/121736
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()`. >From 2cae10eb0b1e94729c26299af018216e729607de Mon Sep 17 00:00:00 2001 From: Sameer Sahasrabuddhe <sameer.sahasrabud...@amd.com> Date: Thu, 2 Jan 2025 14:30:07 +0530 Subject: [PATCH] [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()`. --- clang/lib/AST/ParentMap.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/lib/AST/ParentMap.cpp b/clang/lib/AST/ParentMap.cpp index fd749b02b758c9..ada7b19487a782 100644 --- a/clang/lib/AST/ParentMap.cpp +++ b/clang/lib/AST/ParentMap.cpp @@ -34,13 +34,13 @@ static void BuildParentMap(MapTy& M, Stmt* S, case Stmt::PseudoObjectExprClass: { PseudoObjectExpr *POE = cast<PseudoObjectExpr>(S); - if (OVMode == OV_Opaque && M[POE->getSyntacticForm()]) + if (OVMode == OV_Opaque && M.contains(POE->getSyntacticForm())) break; // If we are rebuilding the map, clear out any existing state. - if (M[POE->getSyntacticForm()]) + if (M.contains(POE->getSyntacticForm())) for (Stmt *SubStmt : S->children()) - M[SubStmt] = nullptr; + M.erase(SubStmt); M[POE->getSyntacticForm()] = S; BuildParentMap(M, POE->getSyntacticForm(), OV_Transparent); @@ -78,7 +78,7 @@ 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()]) { + if (OVMode == OV_Transparent || !M.contains(OVE->getSourceExpr())) { M[OVE->getSourceExpr()] = S; BuildParentMap(M, OVE->getSourceExpr(), OV_Transparent); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits