summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-07-27 02:39:16 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-07-27 02:39:16 +0000
commitbc36b15253b20026e62a180e8a38d0a89c1d7663 (patch)
treea5d2d079e08d833096d36554b1593c5b0bf39a64 /llvm/lib/Analysis/ConstantFolding.cpp
parent8c83382a954d249fbe33d4e120ec6c2947b3d55c (diff)
downloadbcm5719-llvm-bc36b15253b20026e62a180e8a38d0a89c1d7663.tar.gz
bcm5719-llvm-bc36b15253b20026e62a180e8a38d0a89c1d7663.zip
[ConstantFolding] Correctly handle failures in ConstantFoldConstantExpressionImpl
Failures in ConstantFoldConstantExpressionImpl were ignored causing crashes down the line. This fixes PR28725. llvm-svn: 276827
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index c9adaa7b111..8f67492971d 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1007,8 +1007,12 @@ Constant *llvm::ConstantFoldInstruction(Instruction *I, const DataLayout &DL,
for (const Use &OpU : I->operands()) {
auto *Op = cast<Constant>(&OpU);
// Fold the Instruction's operands.
- if (auto *NewCE = dyn_cast<ConstantExpr>(Op))
- Op = ConstantFoldConstantExpression(NewCE, DL, TLI);
+ if (auto *NewCE = dyn_cast<ConstantExpr>(Op)) {
+ auto *FoldedOp = ConstantFoldConstantExpression(NewCE, DL, TLI);
+ if (!FoldedOp)
+ return nullptr;
+ Op = FoldedOp;
+ }
Ops.push_back(Op);
}
@@ -1048,8 +1052,13 @@ ConstantFoldConstantExpressionImpl(const ConstantExpr *CE, const DataLayout &DL,
// Recursively fold the ConstantExpr's operands. If we have already folded
// a ConstantExpr, we don't have to process it again.
if (auto *NewCE = dyn_cast<ConstantExpr>(NewC)) {
- if (FoldedOps.insert(NewCE).second)
- NewC = ConstantFoldConstantExpressionImpl(NewCE, DL, TLI, FoldedOps);
+ if (FoldedOps.insert(NewCE).second){
+ auto *FoldedC =
+ ConstantFoldConstantExpressionImpl(NewCE, DL, TLI, FoldedOps);
+ if (!FoldedC)
+ return nullptr;
+ NewC = FoldedC;
+ }
}
Ops.push_back(NewC);
}
OpenPOWER on IntegriCloud