[PATCH] D34341: [TableGen] Fix bug in TableGen CodeGenPatterns when adding variants of the patterns.

Ayman Musa via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 19 01:38:29 PDT 2017


aymanmus created this revision.

All patterns reside in a std::vector container, where new variants are added to it using the standard library's //emplace_back// function.
When calling this with a new element while there is no enough allocated space, a bigger space is allocated and all the old info in the small vector is copied to the newly allocated vector, then the old vector is freed.
The problem is that before doing this "copying", we take a reference of one of the elements in the old vector, and after the "copying" we add it to the new vector.
As the old vector is freed after the copying, the reference now does not point to a valid element.

Added new function to the API of //CodeGenDAGPatterns// class to return the same information as a copy in order to avoid this issue.

This was revealed in rL305465 <https://reviews.llvm.org/rL305465> that added many patterns and forced the reallocation of the vector which caused crashes in windows bots.


https://reviews.llvm.org/D34341

Files:
  utils/TableGen/CodeGenDAGPatterns.cpp
  utils/TableGen/CodeGenDAGPatterns.h


Index: utils/TableGen/CodeGenDAGPatterns.cpp
===================================================================
--- utils/TableGen/CodeGenDAGPatterns.cpp
+++ utils/TableGen/CodeGenDAGPatterns.cpp
@@ -3846,7 +3846,7 @@
       PatternsToMatch.emplace_back(
           PatternsToMatch[i].getSrcRecord(), PatternsToMatch[i].getPredicates(),
           Variant, PatternsToMatch[i].getDstPattern(),
-          PatternsToMatch[i].getDstRegs(),
+          PatternsToMatch[i].copyDstRegs(),
           PatternsToMatch[i].getAddedComplexity(), Record::getNewUID());
     }
 
Index: utils/TableGen/CodeGenDAGPatterns.h
===================================================================
--- utils/TableGen/CodeGenDAGPatterns.h
+++ utils/TableGen/CodeGenDAGPatterns.h
@@ -704,6 +704,7 @@
   TreePatternNode *getSrcPattern() const { return SrcPattern; }
   TreePatternNode *getDstPattern() const { return DstPattern; }
   const std::vector<Record*> &getDstRegs() const { return Dstregs; }
+  const std::vector<Record*> copyDstRegs() const { return Dstregs; }
   int         getAddedComplexity() const { return AddedComplexity; }
 
   std::string getPredicateCheck() const;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34341.102996.patch
Type: text/x-patch
Size: 1161 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170619/97fdda4a/attachment.bin>


More information about the llvm-commits mailing list