[Attributor] H2S fix.

Summary: Fixing issues that were noticed in D71521

Reviewers: jdoerfert, lebedev.ri, uenoku

Subscribers:

Differential Revision: https://reviews.llvm.org/D71564
This commit is contained in:
Stefan Stipanovic 2019-12-17 20:41:09 +01:00
parent d020e67575
commit fff8ec9813
2 changed files with 18 additions and 6 deletions

View File

@ -4335,7 +4335,7 @@ ChangeStatus AAHeapToStackImpl::updateImpl(Attributor &A) {
if (IsMalloc) { if (IsMalloc) {
if (auto *Size = dyn_cast<ConstantInt>(I.getOperand(0))) if (auto *Size = dyn_cast<ConstantInt>(I.getOperand(0)))
if (Size->getValue().sle(MaxHeapToStackSize)) if (Size->getValue().ule(MaxHeapToStackSize))
if (UsesCheck(I) || FreeCheck(I)) { if (UsesCheck(I) || FreeCheck(I)) {
MallocCalls.insert(&I); MallocCalls.insert(&I);
return true; return true;
@ -4345,7 +4345,7 @@ ChangeStatus AAHeapToStackImpl::updateImpl(Attributor &A) {
if (auto *Num = dyn_cast<ConstantInt>(I.getOperand(0))) if (auto *Num = dyn_cast<ConstantInt>(I.getOperand(0)))
if (auto *Size = dyn_cast<ConstantInt>(I.getOperand(1))) 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)) .ule(MaxHeapToStackSize))
if (!Overflow && (UsesCheck(I) || FreeCheck(I))) { if (!Overflow && (UsesCheck(I) || FreeCheck(I))) {
MallocCalls.insert(&I); MallocCalls.insert(&I);
return true; return true;

View File

@ -313,15 +313,27 @@ define i32 @test13() {
define i32 @test_sle() { define i32 @test_sle() {
%1 = tail call noalias i8* @malloc(i64 -1) %1 = tail call noalias i8* @malloc(i64 -1)
; FIXME: This should not be transformed ; CHECK: %1 = tail call noalias i8* @malloc(i64 -1)
; CHECK: %1 = alloca i8, i64 -1 ; CHECK-NEXT: @no_sync_func(i8* noalias nofree %1)
; CHECK-NEXT: @no_sync_func(i8* noalias nocapture nofree %1)
tail call void @no_sync_func(i8* %1) tail call void @no_sync_func(i8* %1)
%2 = bitcast i8* %1 to i32* %2 = bitcast i8* %1 to i32*
store i32 10, i32* %2 store i32 10, i32* %2
%3 = load i32, i32* %2 %3 = load i32, i32* %2
tail call void @free(i8* %1) tail call void @free(i8* %1)
; CHECK-NOT: tail call void @free(i8* noalias %1) ; CHECK: tail call void @free(i8* noalias %1)
ret i32 %3
}
define i32 @test_overflow() {
%1 = tail call noalias i8* @calloc(i64 65537, i64 65537)
; CHECK: %1 = tail call noalias i8* @calloc(i64 65537, i64 65537)
; CHECK-NEXT: @no_sync_func(i8* noalias nofree %1)
tail call void @no_sync_func(i8* %1)
%2 = bitcast i8* %1 to i32*
store i32 10, i32* %2
%3 = load i32, i32* %2
tail call void @free(i8* %1)
; CHECK: tail call void @free(i8* noalias %1)
ret i32 %3 ret i32 %3
} }