From bade86cedcba12c21677b2ccf0ed6ada2f3ef268 Mon Sep 17 00:00:00 2001 From: James Molloy Date: Mon, 1 Aug 2016 09:34:48 +0000 Subject: [SimplifyCFG] Fix nasty RAUW bug from r277325 Using RAUW was wrong here; if we have a switch transform such as: 18 -> 6 then 6 -> 0 If we use RAUW, while performing the second transform the *transformed* 6 from the first will be also replaced, so we end up with: 18 -> 0 6 -> 0 Found by clang stage2 bootstrap; testcase added. llvm-svn: 277332 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Transforms/Utils') diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index f4d7f5e38b9..8e821d9b9fa 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -5132,11 +5132,12 @@ static bool ReduceSwitchRange(SwitchInst *SI, IRBuilder<> &Builder, Builder.CreateShl(Sub, Ty->getBitWidth() - Shift)); SI->replaceUsesOfWith(SI->getCondition(), Rot); - for (auto &C : SI->cases()) { + for (SwitchInst::CaseIt C = SI->case_begin(), E = SI->case_end(); C != E; + ++C) { auto *Orig = C.getCaseValue(); auto Sub = Orig->getValue() - APInt(Ty->getBitWidth(), Base); - SI->replaceUsesOfWith(Orig, - ConstantInt::get(Ty, Sub.lshr(ShiftC->getValue()))); + C.setValue( + cast(ConstantInt::get(Ty, Sub.lshr(ShiftC->getValue())))); } return true; } -- cgit v1.2.3