aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-04-30 22:38:40 +0200
committerNikita Popov <nikita.ppv@gmail.com>2021-04-30 23:04:49 +0200
commit2cd78686055f1badb9aa55cb95e189548ffc82f0 (patch)
treead3335bd55213a3f19f281154fb824b9d4b37a8e /llvm/lib/Analysis/ValueTracking.cpp
parentbf61690e92b210c8934918152bed2932cf665105 (diff)
downloadllvm-2cd78686055f1badb9aa55cb95e189548ffc82f0.zip
llvm-2cd78686055f1badb9aa55cb95e189548ffc82f0.tar.gz
llvm-2cd78686055f1badb9aa55cb95e189548ffc82f0.tar.bz2
[ValueTracking] Limit scan when checking poison UB (PR50155)
The current code can scan an unlimited number of instructions, if the containing basic block is very large. The test case from PR50155 contains a basic block with approximately 100k instructions. To avoid this, limit the number of instructions we inspect. At the same time, drop the limit on the number of basic blocks, as this will be implicitly limited by the number of instructions as well.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 3e46e11..e2c7253 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -5382,6 +5382,9 @@ static bool programUndefinedIfUndefOrPoison(const Value *V,
return false;
}
+ // Limit number of instructions we look at, to avoid scanning through large
+ // blocks. The current limit is chosen arbitrarily.
+ unsigned ScanLimit = 32;
BasicBlock::const_iterator End = BB->end();
if (!PoisonOnly) {
@@ -5390,6 +5393,11 @@ static bool programUndefinedIfUndefOrPoison(const Value *V,
// well-defined operands.
for (auto &I : make_range(Begin, End)) {
+ if (isa<DbgInfoIntrinsic>(I))
+ continue;
+ if (--ScanLimit == 0)
+ break;
+
SmallPtrSet<const Value *, 4> WellDefinedOps;
getGuaranteedWellDefinedOps(&I, WellDefinedOps);
for (auto *Op : WellDefinedOps) {
@@ -5415,9 +5423,12 @@ static bool programUndefinedIfUndefOrPoison(const Value *V,
for_each(V->users(), Propagate);
Visited.insert(BB);
- unsigned Iter = 0;
- while (Iter++ < MaxAnalysisRecursionDepth) {
+ while (true) {
for (auto &I : make_range(Begin, End)) {
+ if (isa<DbgInfoIntrinsic>(I))
+ continue;
+ if (--ScanLimit == 0)
+ return false;
if (mustTriggerUB(&I, YieldsPoison))
return true;
if (!isGuaranteedToTransferExecutionToSuccessor(&I))