]> granicus.if.org Git - llvm/commitdiff
hwasan: If we split the entry block, move static allocas back into the entry block.
authorPeter Collingbourne <peter@pcc.me.uk>
Fri, 25 Jan 2019 02:08:46 +0000 (02:08 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Fri, 25 Jan 2019 02:08:46 +0000 (02:08 +0000)
Otherwise they are treated as dynamic allocas, which ends up increasing
code size significantly. This reduces size of Chromium base_unittests
by 2MB (6.7%).

Differential Revision: https://reviews.llvm.org/D57205

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352152 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
test/Instrumentation/HWAddressSanitizer/lazy-thread-init.ll

index 6170b792a68999f0b0b707dc57a25f4354605909..a6ffff418db959bdbfb48db0625abf7262127e28 100644 (file)
@@ -1038,6 +1038,21 @@ bool HWAddressSanitizer::runOnFunction(Function &F) {
     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);
 
index b02d0f88a0f8c6c943a94aa1d4a4f19869c6d8ab..d5a2541eb7763505cdb66c51f62339ad707b5354 100644 (file)
@@ -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 @@ define void @alloca() sanitize_hwaddress "hwasan-abi"="interceptor" {
 
   ; 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
 }