[PATCH] D57205: hwasan: If we split the entry block, move static allocas back into the entry block.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 24 18:09:58 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL352152: hwasan: If we split the entry block, move static allocas back into the entry… (authored by pcc, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D57205?vs=183433&id=183466#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57205/new/

https://reviews.llvm.org/D57205

Files:
  llvm/trunk/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
  llvm/trunk/test/Instrumentation/HWAddressSanitizer/lazy-thread-init.ll


Index: llvm/trunk/test/Instrumentation/HWAddressSanitizer/lazy-thread-init.ll
===================================================================
--- llvm/trunk/test/Instrumentation/HWAddressSanitizer/lazy-thread-init.ll
+++ llvm/trunk/test/Instrumentation/HWAddressSanitizer/lazy-thread-init.ll
@@ -2,9 +2,10 @@
 
 target triple = "aarch64--linux-android"
 
-declare void @bar([16 x i32]* %p)
+declare i32 @bar([16 x i32]* %p)
 
 define void @alloca() sanitize_hwaddress "hwasan-abi"="interceptor" {
+  ; CHECK: alloca [16 x i32]
   ; CHECK: [[A:%[^ ]*]] = call i8* @llvm.thread.pointer()
   ; CHECK: [[B:%[^ ]*]] = getelementptr i8, i8* [[A]], i32 48
   ; CHECK: [[C:%[^ ]*]] = bitcast i8* [[B]] to i64*
@@ -19,9 +20,11 @@
 
   ; CHECK: [[CONT]]:
   ; CHECK: phi i64 [ [[LOAD]], %0 ], [ [[RELOAD]], %[[INIT]] ]
+  ; CHECK: alloca i8
 
   %p = alloca [16 x i32]
-  call void @bar([16 x i32]* %p)
+  %size = call i32 @bar([16 x i32]* %p)
+  %q = alloca i8, i32 %size
   ret void
 }
 
Index: llvm/trunk/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ llvm/trunk/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -1038,6 +1038,21 @@
     Changed |= instrumentStack(AllocasToInstrument, RetVec, StackTag);
   }
 
+  // If we split the entry block, move any allocas that were originally in the
+  // entry block back into the entry block so that they aren't treated as
+  // dynamic allocas.
+  if (EntryIRB.GetInsertBlock() != &F.getEntryBlock()) {
+    InsertPt = &*F.getEntryBlock().begin();
+    for (auto II = EntryIRB.GetInsertBlock()->begin(),
+              IE = EntryIRB.GetInsertBlock()->end();
+         II != IE;) {
+      Instruction *I = &*II++;
+      if (auto *AI = dyn_cast<AllocaInst>(I))
+        if (isa<ConstantInt>(AI->getArraySize()))
+          I->moveBefore(InsertPt);
+    }
+  }
+
   for (auto Inst : ToInstrument)
     Changed |= instrumentMemAccess(Inst);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57205.183466.patch
Type: text/x-patch
Size: 2037 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190125/c4aaf9cb/attachment.bin>


More information about the llvm-commits mailing list