[asan] Fix the coverage.cc test broken by r196939
[oota-llvm.git] / lib / Transforms / Instrumentation / AddressSanitizer.cpp
index 0b3ee86114319c2187dace8c956899d1a0b88201..f683bfb16c73fac461d1a558eb512982381179d9 100644 (file)
@@ -1167,7 +1167,19 @@ bool AddressSanitizer::maybeInsertAsanInitAtFunctionEntry(Function &F) {
 //  b) collect usage statistics to help improve Clang coverage design.
 bool AddressSanitizer::InjectCoverage(Function &F) {
   if (!ClCoverage) return false;
-  IRBuilder<> IRB(F.getEntryBlock().getFirstInsertionPt());
+
+  // Skip static allocas at the top of the entry block so they don't become
+  // dynamic when we split the block.  If we used our optimized stack layout,
+  // then there will only be one alloca and it will come first.
+  BasicBlock &Entry = F.getEntryBlock();
+  BasicBlock::iterator IP = Entry.getFirstInsertionPt(), BE = Entry.end();
+  for (; IP != BE; ++IP) {
+    AllocaInst *AI = dyn_cast<AllocaInst>(IP);
+    if (!AI || !AI->isStaticAlloca())
+      break;
+  }
+
+  IRBuilder<> IRB(IP);
   Type *Int8Ty = IRB.getInt8Ty();
   GlobalVariable *Guard = new GlobalVariable(
       *F.getParent(), Int8Ty, false, GlobalValue::PrivateLinkage,