[asan] make sure asan erases old unused allocas after it created a new one. This...
authorKostya Serebryany <kcc@google.com>
Fri, 19 Oct 2012 06:20:53 +0000 (06:20 +0000)
committerKostya Serebryany <kcc@google.com>
Fri, 19 Oct 2012 06:20:53 +0000 (06:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166267 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/AddressSanitizer.cpp
test/Instrumentation/AddressSanitizer/basic.ll

index 75f42f30fab1036bf7f6232859e506f1c7f6bc75..d99bb87fd4c7800749915749334713392cfef1ab 100644 (file)
@@ -1148,6 +1148,10 @@ bool AddressSanitizer::poisonStackInFunction(Function &F) {
     }
   }
 
+  // We are done. Remove the old unused alloca instructions.
+  for (size_t i = 0, n = AllocaVec.size(); i < n; i++)
+    AllocaVec[i]->eraseFromParent();
+
   if (ClDebugStack) {
     DEBUG(dbgs() << F);
   }
index d1900018706008cd26495ec3021e29045304873e..655f69c16fdf307cc16d3f9cd26b8558b0892041 100644 (file)
@@ -69,3 +69,23 @@ entry:
   store i32 42, i32* %a
   ret void
 }
+
+; Check that asan leaves just one alloca.
+
+declare void @alloca_test_use([10 x i8]*)
+define void @alloca_test() address_safety {
+entry:
+  %x = alloca [10 x i8], align 1
+  %y = alloca [10 x i8], align 1
+  %z = alloca [10 x i8], align 1
+  call void @alloca_test_use([10 x i8]* %x)
+  call void @alloca_test_use([10 x i8]* %y)
+  call void @alloca_test_use([10 x i8]* %z)
+  ret void
+}
+
+; CHECK: define void @alloca_test()
+; CHECK: = alloca
+; CHECK-NOT: = alloca
+; CHECK: ret void
+