On Thu, Oct 18, 2012 at 11:20 PM, Kostya Serebryany <span dir="ltr"><<a href="mailto:kcc@google.com" target="_blank" class="cremed">kcc@google.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: kcc<br>
Date: Fri Oct 19 01:20:53 2012<br>
New Revision: 166267<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=166267&view=rev" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project?rev=166267&view=rev</a><br>
Log:<br>
[asan] make sure asan erases old unused allocas after it created a new one. This became important after the recent move from ModulePass to FunctionPass because no cleanup is happening after asan pass any more.<br></blockquote>
<div><br></div><div>We should almost certainly run a few passes after asan. instcombine, gvn, instcombine, and simplifycfg would be my baseline to experiment with (and compare compile times of). GVN is likely the most expensive, and it might be acceptable to just do instcombine + simplifycfg.</div>
<div><br></div><div>Don't get me wrong, this change is still a good idea -- you can eliminate these allocas more cheaply than anything else.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
Modified:<br>
    llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp<br>
    llvm/trunk/test/Instrumentation/AddressSanitizer/basic.ll<br>
<br>
Modified: llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?rev=166267&r1=166266&r2=166267&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?rev=166267&r1=166266&r2=166267&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp Fri Oct 19 01:20:53 2012<br>
@@ -1148,6 +1148,10 @@<br>
     }<br>
   }<br>
<br>
+  // We are done. Remove the old unused alloca instructions.<br>
+  for (size_t i = 0, n = AllocaVec.size(); i < n; i++)<br>
+    AllocaVec[i]->eraseFromParent();<br>
+<br>
   if (ClDebugStack) {<br>
     DEBUG(dbgs() << F);<br>
   }<br>
<br>
Modified: llvm/trunk/test/Instrumentation/AddressSanitizer/basic.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/AddressSanitizer/basic.ll?rev=166267&r1=166266&r2=166267&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/AddressSanitizer/basic.ll?rev=166267&r1=166266&r2=166267&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/test/Instrumentation/AddressSanitizer/basic.ll (original)<br>
+++ llvm/trunk/test/Instrumentation/AddressSanitizer/basic.ll Fri Oct 19 01:20:53 2012<br>
@@ -69,3 +69,23 @@<br>
   store i32 42, i32* %a<br>
   ret void<br>
 }<br>
+<br>
+; Check that asan leaves just one alloca.<br>
+<br>
+declare void @alloca_test_use([10 x i8]*)<br>
+define void @alloca_test() address_safety {<br>
+entry:<br>
+  %x = alloca [10 x i8], align 1<br>
+  %y = alloca [10 x i8], align 1<br>
+  %z = alloca [10 x i8], align 1<br>
+  call void @alloca_test_use([10 x i8]* %x)<br>
+  call void @alloca_test_use([10 x i8]* %y)<br>
+  call void @alloca_test_use([10 x i8]* %z)<br>
+  ret void<br>
+}<br>
+<br>
+; CHECK: define void @alloca_test()<br>
+; CHECK: = alloca<br>
+; CHECK-NOT: = alloca<br>
+; CHECK: ret void<br>
+<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" class="cremed">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="cremed">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>