[PATCH] D96207: [FuzzMutate] Fix getWeight of InstDeleterIRStrategy
Loris Reiff via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 6 09:03:52 PST 2021
liblor created this revision.
liblor added a reviewer: bogner.
Herald added a subscriber: hiraditya.
liblor requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The comment states the following, for calculating the `Line` variable:
> Draw a line starting from when we only have 1k left and increasing linearly to double the current weight.
However, the value was not calculated as described. Instead, it would result in a negative value, which resulted in the function always returning 0 afterwards.
// Invariant: CurrentSize <= MaxSize - 200
// Invariant: CurrentWeight >= 0
int Line = (-2 * CurrentWeight) * (MaxSize - CurrentSize + 1000);
// {Line <= 0}
This commit fixes the issue and linearly interpolates as described.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D96207
Files:
llvm/lib/FuzzMutate/IRMutator.cpp
Index: llvm/lib/FuzzMutate/IRMutator.cpp
===================================================================
--- llvm/lib/FuzzMutate/IRMutator.cpp
+++ llvm/lib/FuzzMutate/IRMutator.cpp
@@ -143,7 +143,10 @@
return CurrentWeight ? CurrentWeight * 100 : 1;
// Draw a line starting from when we only have 1k left and increasing linearly
// to double the current weight.
- int Line = (-2 * CurrentWeight) * (MaxSize - CurrentSize + 1000);
+ int64_t Line = (-2 * static_cast<int64_t>(CurrentWeight)) *
+ (static_cast<int64_t>(MaxSize) -
+ static_cast<int64_t>(CurrentSize) - 1000) /
+ 1000;
// Clamp negative weights to zero.
if (Line < 0)
return 0;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96207.321942.patch
Type: text/x-patch
Size: 717 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210206/bfe55264/attachment.bin>
More information about the llvm-commits
mailing list