[PATCH] D71450: Modification of bad code in Reassociate.cpp to avoid potential bug.
Alok Kumar Sharma via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 12 22:02:55 PST 2019
alok created this revision.
alok added reviewers: probinson, jmorse, dblaikie, aprantl, jini.susan.george, SouraVX, awpandey.
alok added a project: LLVM.
Herald added subscribers: llvm-commits, hiraditya.
It is evident in the code itself where variable's (type Instruction) user list is accessed without first checking whether it has at least one element.
Code is rearranged to bring check hasOneUse() before user_back().
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D71450
Files:
llvm/lib/Transforms/Scalar/Reassociate.cpp
Index: llvm/lib/Transforms/Scalar/Reassociate.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ llvm/lib/Transforms/Scalar/Reassociate.cpp
@@ -939,11 +939,12 @@
if (isReassociableOp(V1, Instruction::Add, Instruction::FAdd) ||
isReassociableOp(V1, Instruction::Sub, Instruction::FSub))
return true;
- Value *VB = Sub->user_back();
- if (Sub->hasOneUse() &&
- (isReassociableOp(VB, Instruction::Add, Instruction::FAdd) ||
- isReassociableOp(VB, Instruction::Sub, Instruction::FSub)))
- return true;
+ if (Sub->hasOneUse()) {
+ Value *VB = Sub->user_back();
+ if (isReassociableOp(VB, Instruction::Add, Instruction::FAdd) ||
+ isReassociableOp(VB, Instruction::Sub, Instruction::FSub))
+ return true;
+ }
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71450.233735.patch
Type: text/x-patch
Size: 848 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191213/333522b0/attachment.bin>
More information about the llvm-commits
mailing list