[clang] 0d21ef4 - [clang][mutation analyzer][NFC] Simplify code in ExprMutationAnalyzer (#125283)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 31 23:20:50 PST 2025


Author: Balazs Benics
Date: 2025-02-01T08:20:47+01:00
New Revision: 0d21ef4e6c50c7d4d591adf7e6dbd6232e8a99c4

URL: https://github.com/llvm/llvm-project/commit/0d21ef4e6c50c7d4d591adf7e6dbd6232e8a99c4
DIFF: https://github.com/llvm/llvm-project/commit/0d21ef4e6c50c7d4d591adf7e6dbd6232e8a99c4.diff

LOG: [clang][mutation analyzer][NFC] Simplify code in ExprMutationAnalyzer (#125283)

Added: 
    

Modified: 
    clang/lib/Analysis/ExprMutationAnalyzer.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index d7b44149d0fc4b..8944343484e583 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -806,17 +806,15 @@ FunctionParmMutationAnalyzer::FunctionParmMutationAnalyzer(
 
 const Stmt *
 FunctionParmMutationAnalyzer::findMutation(const ParmVarDecl *Parm) {
-  const auto Memoized = Results.find(Parm);
-  if (Memoized != Results.end())
-    return Memoized->second;
+  auto [Place, Inserted] = Results.try_emplace(Parm);
+  if (!Inserted)
+    return Place->second;
+
   // To handle call A -> call B -> call A. Assume parameters of A is not mutated
   // before analyzing parameters of A. Then when analyzing the second "call A",
   // FunctionParmMutationAnalyzer can use this memoized value to avoid infinite
   // recursion.
-  Results[Parm] = nullptr;
-  if (const Stmt *S = BodyAnalyzer.findMutation(Parm))
-    return Results[Parm] = S;
-  return Results[Parm];
+  return Place->second = BodyAnalyzer.findMutation(Parm);
 }
 
 } // namespace clang


        


More information about the cfe-commits mailing list