summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/IPO/Attributor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/IPO/Attributor.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/Attributor.cpp38
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;
};
OpenPOWER on IntegriCloud