[llvm] dca4b71 - [Analysis] resolveAllCalls - fix use after std::move warning. NFCI.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 3 10:34:51 PDT 2020


Author: Simon Pilgrim
Date: 2020-10-03T17:52:20+01:00
New Revision: dca4b7130de547860925631295acfce33130a100

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

LOG: [Analysis] resolveAllCalls - fix use after std::move warning. NFCI.

We can't use Use.Calls after its std::move()'d to TmpCalls as it will be in an undefined state. Instead, swap with the known empty map in TmpCalls so we can then safely emplace_back into the now empty Use.Calls.

Fixes clang static analyzer warning.

Added: 
    

Modified: 
    llvm/lib/Analysis/StackSafetyAnalysis.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/StackSafetyAnalysis.cpp b/llvm/lib/Analysis/StackSafetyAnalysis.cpp
index 9947ddaf0071..8c9bce4ba67c 100644
--- a/llvm/lib/Analysis/StackSafetyAnalysis.cpp
+++ b/llvm/lib/Analysis/StackSafetyAnalysis.cpp
@@ -692,7 +692,10 @@ const ConstantRange *findParamAccess(const FunctionSummary &FS,
 void resolveAllCalls(UseInfo<GlobalValue> &Use,
                      const ModuleSummaryIndex *Index) {
   ConstantRange FullSet(Use.Range.getBitWidth(), true);
-  UseInfo<GlobalValue>::CallsTy TmpCalls = std::move(Use.Calls);
+  // Move Use.Calls to a temp storage and repopulate - don't use std::move as it
+  // leaves Use.Calls in an undefined state.
+  UseInfo<GlobalValue>::CallsTy TmpCalls;
+  std::swap(TmpCalls, Use.Calls);
   for (const auto &C : TmpCalls) {
     const Function *F = findCalleeInModule(C.first.Callee);
     if (F) {


        


More information about the llvm-commits mailing list