From f79f136cc64b0625b77c7b9008ed8c5b848b6b17 Mon Sep 17 00:00:00 2001 From: Hal Finkel Date: Sun, 17 Feb 2013 15:59:26 +0000 Subject: BBVectorize: Fix an invalid reference bug This fixes PR15289. This bug was introduced (recently) in r175215; collecting all std::vector references for candidate pairs to delete at once is invalid because subsequent lookups in the owning DenseMap could invalidate the references. bugpoint was able to reduce a useful test case. Unfortunately, because whether or not this asserts depends on memory layout, this test case will sometimes appear to produce valid output. Nevertheless, running under valgrind will reveal the error. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175397 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Vectorize/BBVectorize.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib/Transforms/Vectorize/BBVectorize.cpp') diff --git a/lib/Transforms/Vectorize/BBVectorize.cpp b/lib/Transforms/Vectorize/BBVectorize.cpp index 1773cff3bb..76365417aa 100644 --- a/lib/Transforms/Vectorize/BBVectorize.cpp +++ b/lib/Transforms/Vectorize/BBVectorize.cpp @@ -2164,10 +2164,7 @@ namespace { *S->second << "\n"); // Remove all candidate pairs that have values in the chosen dag. - std::vector &KK = CandidatePairs[S->first], - &LL = CandidatePairs2[S->second], - &MM = CandidatePairs[S->second], - &NN = CandidatePairs2[S->first]; + std::vector &KK = CandidatePairs[S->first]; for (std::vector::iterator K = KK.begin(), KE = KK.end(); K != KE; ++K) { if (*K == S->second) @@ -2175,6 +2172,8 @@ namespace { CandidatePairsSet.erase(ValuePair(S->first, *K)); } + + std::vector &LL = CandidatePairs2[S->second]; for (std::vector::iterator L = LL.begin(), LE = LL.end(); L != LE; ++L) { if (*L == S->first) @@ -2182,11 +2181,15 @@ namespace { CandidatePairsSet.erase(ValuePair(*L, S->second)); } + + std::vector &MM = CandidatePairs[S->second]; for (std::vector::iterator M = MM.begin(), ME = MM.end(); M != ME; ++M) { assert(*M != S->first && "Flipped pair in candidate list?"); CandidatePairsSet.erase(ValuePair(S->second, *M)); } + + std::vector &NN = CandidatePairs2[S->first]; for (std::vector::iterator N = NN.begin(), NE = NN.end(); N != NE; ++N) { assert(*N != S->second && "Flipped pair in candidate list?"); -- cgit v1.2.3