[asan] fix caller-calee instrumentation to emit new cache for every call site
authorKostya Serebryany <kcc@google.com>
Fri, 31 Oct 2014 17:11:27 +0000 (17:11 +0000)
committerKostya Serebryany <kcc@google.com>
Fri, 31 Oct 2014 17:11:27 +0000 (17:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220973 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 3f0db3630b983af2c631efcdd8647bb863a5f133..de7b83d02940c91c6dd84797ee4d878ac6011949 100644 (file)
@@ -1405,13 +1405,13 @@ void AddressSanitizer::InjectCoverageForIndirectCalls(
   const int kCacheSize = 16;
   const int kCacheAlignment = 64;  // Align for better performance.
   Type *Ty = ArrayType::get(IntptrTy, kCacheSize);
-  GlobalVariable *CalleeCache =
-      new GlobalVariable(*F.getParent(), Ty, false, GlobalValue::PrivateLinkage,
-                         Constant::getNullValue(Ty), "__asan_gen_callee_cache");
-  CalleeCache->setAlignment(kCacheAlignment);
   for (auto I : IndirCalls) {
     IRBuilder<> IRB(I);
     CallSite CS(I);
+    GlobalVariable *CalleeCache = new GlobalVariable(
+        *F.getParent(), Ty, false, GlobalValue::PrivateLinkage,
+        Constant::getNullValue(Ty), "__asan_gen_callee_cache");
+    CalleeCache->setAlignment(kCacheAlignment);
     IRB.CreateCall2(AsanCovIndirCallFunction,
                     IRB.CreatePointerCast(CS.getCalledValue(), IntptrTy),
                     IRB.CreatePointerCast(CalleeCache, IntptrTy));
index d666925d62200c738be88b3a7d0e11f98079d95e..707371ad33f3ebbffd5ae7dedd2626820c771549 100644 (file)
@@ -78,9 +78,13 @@ entry:
   %vtable = load void (%struct.StructWithVptr*)*** %0, align 8
   %1 = load void (%struct.StructWithVptr*)** %vtable, align 8
   tail call void %1(%struct.StructWithVptr* %foo)
+  tail call void %1(%struct.StructWithVptr* %foo)
   ret void
 }
 
+; We expect to see two calls to __sanitizer_cov_indir_call16
+; with different values of second argument.
 ; CHECK4-LABEL: define void @CallViaVptr
-; CHECK4: call void @__sanitizer_cov_indir_call16
+; CHECK4: call void @__sanitizer_cov_indir_call16({{.*}},[[CACHE:.*]])
+; CHECK4-NOT: call void @__sanitizer_cov_indir_call16({{.*}},[[CACHE]])
 ; CHECK4: ret void