[llvm] r306371 - [TableGen] Fix bug in TableGen CodeGenPatterns when adding variants of the patterns.
Ayman Musa via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 27 00:10:20 PDT 2017
Author: aymanmus
Date: Tue Jun 27 00:10:20 2017
New Revision: 306371
URL: http://llvm.org/viewvc/llvm-project?rev=306371&view=rev
Log:
[TableGen] Fix bug in TableGen CodeGenPatterns when adding variants of the patterns.
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 that added many patterns and forced the reallocation of the vector which caused crashes in windows bots.
Differential Revision: https://reviews.llvm.org/D34341
Modified:
llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp?rev=306371&r1=306370&r2=306371&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp Tue Jun 27 00:10:20 2017
@@ -3837,11 +3837,11 @@ void CodeGenDAGPatterns::GenerateVariant
if (AlreadyExists) continue;
// Otherwise, add it to the list of patterns we have.
- PatternsToMatch.emplace_back(
+ PatternsToMatch.push_back(PatternToMatch(
PatternsToMatch[i].getSrcRecord(), PatternsToMatch[i].getPredicates(),
Variant, PatternsToMatch[i].getDstPattern(),
PatternsToMatch[i].getDstRegs(),
- PatternsToMatch[i].getAddedComplexity(), Record::getNewUID());
+ PatternsToMatch[i].getAddedComplexity(), Record::getNewUID()));
}
DEBUG(errs() << "\n");
More information about the llvm-commits
mailing list