diff options
| author | Johannes Doerfert <jdoerfert@anl.gov> | 2019-10-13 03:54:08 +0000 |
|---|---|---|
| committer | Johannes Doerfert <jdoerfert@anl.gov> | 2019-10-13 03:54:08 +0000 |
| commit | d20f80780e053dfa3664858c9ac8be15951a035d (patch) | |
| tree | 1813ee6127dcbd7a19089f92e583e3daa7b34517 /llvm/lib/Transforms | |
| parent | 9daf51910b11081a24674cc0822b898a5e19347d (diff) | |
| download | bcm5719-llvm-d20f80780e053dfa3664858c9ac8be15951a035d.tar.gz bcm5719-llvm-d20f80780e053dfa3664858c9ac8be15951a035d.zip | |
[Attributor][FIX] Do not apply h2s for arbitrary mallocs
H2S did apply to mallocs of non-constant sizes if the uses were OK. This
is now forbidden through reording of the "good" and "bad" cases in the
conditional.
llvm-svn: 374698
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/IPO/Attributor.cpp | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index eb6756c53e7..6db3f40b05f 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -3620,30 +3620,36 @@ ChangeStatus AAHeapToStackImpl::updateImpl(Attributor &A) { }; auto MallocCallocCheck = [&](Instruction &I) { - if (isMallocLikeFn(&I, TLI)) { + if (BadMallocCalls.count(&I)) + return true; + + bool IsMalloc = isMallocLikeFn(&I, TLI); + bool IsCalloc = !IsMalloc && isCallocLikeFn(&I, TLI); + if (!IsMalloc && !IsCalloc) { + BadMallocCalls.insert(&I); + return true; + } + + if (IsMalloc) { if (auto *Size = dyn_cast<ConstantInt>(I.getOperand(0))) - if (!Size->getValue().sle(MaxHeapToStackSize)) - return true; - } else if (isCallocLikeFn(&I, TLI)) { + if (Size->getValue().sle(MaxHeapToStackSize)) + if (UsesCheck(I)) { + MallocCalls.insert(&I); + return true; + } + } else if (IsCalloc) { bool Overflow = false; if (auto *Num = dyn_cast<ConstantInt>(I.getOperand(0))) if (auto *Size = dyn_cast<ConstantInt>(I.getOperand(1))) - if (!(Size->getValue().umul_ov(Num->getValue(), Overflow)) + if ((Size->getValue().umul_ov(Num->getValue(), Overflow)) .sle(MaxHeapToStackSize)) - if (!Overflow) + if (!Overflow && UsesCheck(I)) { + MallocCalls.insert(&I); return true; - } else { - BadMallocCalls.insert(&I); - return true; + } } - if (BadMallocCalls.count(&I)) - return true; - - if (UsesCheck(I)) - MallocCalls.insert(&I); - else - BadMallocCalls.insert(&I); + BadMallocCalls.insert(&I); return true; }; |

