[PATCH] D71564: [Attributor] H2S fix.

Stefan Stipanovic via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 16 12:36:44 PST 2019


sstefan1 created this revision.
sstefan1 added reviewers: jdoerfert, lebedev.ri, uenoku.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

Fixing issues that were noticed in D71521 <https://reviews.llvm.org/D71521>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71564

Files:
  llvm/lib/Transforms/IPO/Attributor.cpp
  llvm/test/Transforms/Attributor/heap_to_stack.ll


Index: llvm/test/Transforms/Attributor/heap_to_stack.ll
===================================================================
--- llvm/test/Transforms/Attributor/heap_to_stack.ll
+++ llvm/test/Transforms/Attributor/heap_to_stack.ll
@@ -311,6 +311,32 @@
   ret i32 %3
 }
 
+define i32 @test_sle() {
+  %1 = tail call noalias i8* @malloc(i64 -1)
+  ; CHECK: %1 = tail call noalias i8* @malloc(i64 -1)
+  ; 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
+}
+
+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
+}
+
 define void @test14() {
   %1 = tail call noalias i8* @calloc(i64 64, i64 4)
   ; CHECK: %1 = tail call noalias i8* @calloc(i64 64, i64 4)
Index: llvm/lib/Transforms/IPO/Attributor.cpp
===================================================================
--- llvm/lib/Transforms/IPO/Attributor.cpp
+++ llvm/lib/Transforms/IPO/Attributor.cpp
@@ -4335,7 +4335,7 @@
 
     if (IsMalloc) {
       if (auto *Size = dyn_cast<ConstantInt>(I.getOperand(0)))
-        if (Size->getValue().sle(MaxHeapToStackSize))
+        if (Size->getValue().ule(MaxHeapToStackSize))
           if (UsesCheck(I) || FreeCheck(I)) {
             MallocCalls.insert(&I);
             return true;
@@ -4345,7 +4345,7 @@
       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))
-                  .sle(MaxHeapToStackSize))
+                  .ule(MaxHeapToStackSize))
             if (!Overflow && (UsesCheck(I) || FreeCheck(I))) {
               MallocCalls.insert(&I);
               return true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71564.234119.patch
Type: text/x-patch
Size: 2219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191216/fd3a1a53/attachment.bin>


More information about the llvm-commits mailing list