[llvm] dde162d - [CSSPGO] Fix an access violation due to invalided std::vector pointer invalidation.

Hongtao Yu via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 1 10:24:25 PDT 2021


Author: Hongtao Yu
Date: 2021-09-01T10:24:17-07:00
New Revision: dde162d8a593973d2bf97d2dac962350a5896011

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

LOG: [CSSPGO] Fix an access violation due to invalided std::vector pointer invalidation.

std::vector pointers can be invalided while growing. Using std::list instead.

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/SampleContextTracker.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/SampleContextTracker.cpp b/llvm/lib/Transforms/IPO/SampleContextTracker.cpp
index ac62ca42a259..b644b0ce5d64 100644
--- a/llvm/lib/Transforms/IPO/SampleContextTracker.cpp
+++ b/llvm/lib/Transforms/IPO/SampleContextTracker.cpp
@@ -479,7 +479,7 @@ ContextTrieNode *SampleContextTracker::getContextFor(const DILocation *DIL) {
 
   // Convert real function names to MD5 names, if the input profile is
   // MD5-based.
-  std::vector<std::string> MD5Names;
+  std::list<std::string> MD5Names;
   if (FunctionSamples::UseMD5) {
     for (auto &Location : S) {
       MD5Names.emplace_back();
@@ -492,7 +492,7 @@ ContextTrieNode *SampleContextTracker::getContextFor(const DILocation *DIL) {
   int I = S.size();
   while (--I >= 0 && ContextNode) {
     LineLocation &CallSite = S[I].first;
-    StringRef &CalleeName = S[I].second;
+    StringRef CalleeName = S[I].second;
     ContextNode = ContextNode->getChildContext(CallSite, CalleeName);
   }
 


        


More information about the llvm-commits mailing list