diff options
author | Michael Ilseman <milseman@apple.com> | 2014-11-05 21:28:24 +0000 |
---|---|---|
committer | Michael Ilseman <milseman@apple.com> | 2014-11-05 21:28:24 +0000 |
commit | a7202bdbedae69cd5feade4631eb61914c79e5fa (patch) | |
tree | c3efc7be923b082b95ddaeff33ff3fd2c89b2ea7 | |
parent | 43270c34d5d917d798f360805b4030c07a949123 (diff) | |
download | bcm5719-llvm-a7202bdbedae69cd5feade4631eb61914c79e5fa.tar.gz bcm5719-llvm-a7202bdbedae69cd5feade4631eb61914c79e5fa.zip |
Fix heap-use-after-free bug in expandSDiv when the operands are
constants, as discovered by ASAN.
Patch by Mehdi Amini!
llvm-svn: 221401
-rw-r--r-- | llvm/lib/Transforms/Utils/IntegerDivision.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Utils/IntegerDivision.cpp b/llvm/lib/Transforms/Utils/IntegerDivision.cpp index 9f91eeb7953..0ae746cc83d 100644 --- a/llvm/lib/Transforms/Utils/IntegerDivision.cpp +++ b/llvm/lib/Transforms/Utils/IntegerDivision.cpp @@ -398,11 +398,13 @@ bool llvm::expandRemainder(BinaryOperator *Rem) { Rem->dropAllReferences(); Rem->eraseFromParent(); - // If we didn't actually generate a udiv instruction, we're done - BinaryOperator *BO = dyn_cast<BinaryOperator>(Builder.GetInsertPoint()); - if (!BO || BO->getOpcode() != Instruction::URem) + // If we didn't actually generate an urem instruction, we're done + // This happens for example if the input were constant. In this case the + // Builder insertion point was unchanged + if (Rem == Builder.GetInsertPoint()) return true; + BinaryOperator *BO = dyn_cast<BinaryOperator>(Builder.GetInsertPoint()); Rem = BO; } @@ -456,11 +458,13 @@ bool llvm::expandDivision(BinaryOperator *Div) { Div->dropAllReferences(); Div->eraseFromParent(); - // If we didn't actually generate a udiv instruction, we're done - BinaryOperator *BO = dyn_cast<BinaryOperator>(Builder.GetInsertPoint()); - if (!BO || BO->getOpcode() != Instruction::UDiv) + // If we didn't actually generate an udiv instruction, we're done + // This happens for example if the input were constant. In this case the + // Builder insertion point was unchanged + if (Div == Builder.GetInsertPoint()) return true; + BinaryOperator *BO = dyn_cast<BinaryOperator>(Builder.GetInsertPoint()); Div = BO; } |