diff options
author | Justin Bogner <mail@justinbogner.com> | 2020-01-23 10:24:10 -0800 |
---|---|---|
committer | Justin Bogner <mail@justinbogner.com> | 2020-01-23 10:36:39 -0800 |
commit | b81a337be7bcc84b2ab052103ce918c9fbfc839a (patch) | |
tree | fda7652207ed65f115ee07343d10e96fa8f9b213 /llvm/lib/Transforms/Utils/LoopUnroll.cpp | |
parent | 3c545e4b7318c337bed43d5bc76aad040565f1ef (diff) | |
download | llvm-b81a337be7bcc84b2ab052103ce918c9fbfc839a.zip llvm-b81a337be7bcc84b2ab052103ce918c9fbfc839a.tar.gz llvm-b81a337be7bcc84b2ab052103ce918c9fbfc839a.tar.bz2 |
[LoopUnroll] Avoid UB when converting from WeakVH to `Value *`
Calling `operator*` on a WeakVH with a null value yields a null
reference, which is UB. Avoid this by implicitly converting the WeakVH
to a `Value *` rather than dereferencing and then taking the address
for the type conversion.
Differential Revision: https://reviews.llvm.org/D73280
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUnroll.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUnroll.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp index 4b94b37..bb0b6ed 100644 --- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp @@ -207,10 +207,11 @@ void llvm::simplifyLoopAfterUnroll(Loop *L, bool SimplifyIVs, LoopInfo *LI, // Aggressively clean up dead instructions that simplifyLoopIVs already // identified. Any remaining should be cleaned up below. - while (!DeadInsts.empty()) - if (Instruction *Inst = - dyn_cast_or_null<Instruction>(&*DeadInsts.pop_back_val())) + while (!DeadInsts.empty()) { + Value *V = DeadInsts.pop_back_val(); + if (Instruction *Inst = dyn_cast_or_null<Instruction>(V)) RecursivelyDeleteTriviallyDeadInstructions(Inst); + } } // At this point, the code is well formed. We now do a quick sweep over the |