[llvm-commits] [llvm] r153448 - in /llvm/trunk: lib/Transforms/Instrumentation/ThreadSanitizer.cpp test/Instrumentation/ThreadSanitizer/lit.local.cfg test/Instrumentation/ThreadSanitizer/vptr_update.ll
Kostya Serebryany
kcc at google.com
Mon Mar 26 10:35:03 PDT 2012
Author: kcc
Date: Mon Mar 26 12:35:03 2012
New Revision: 153448
URL: http://llvm.org/viewvc/llvm-project?rev=153448&view=rev
Log:
[tsan] treat vtable pointer updates in a special way (requires tbaa); fix a bug (forgot to return true after instrumenting); make sure the tsan tests are run
Added:
llvm/trunk/test/Instrumentation/ThreadSanitizer/lit.local.cfg
llvm/trunk/test/Instrumentation/ThreadSanitizer/vptr_update.ll
Modified:
llvm/trunk/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
Modified: llvm/trunk/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/ThreadSanitizer.cpp?rev=153448&r1=153447&r2=153448&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/ThreadSanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/ThreadSanitizer.cpp Mon Mar 26 12:35:03 2012
@@ -27,11 +27,14 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/Intrinsics.h"
#include "llvm/Function.h"
+#include "llvm/LLVMContext.h"
+#include "llvm/Metadata.h"
#include "llvm/Module.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/IRBuilder.h"
#include "llvm/Support/MathExtras.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Transforms/Instrumentation.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -61,6 +64,7 @@
static const size_t kNumberOfAccessSizes = 5;
Value *TsanRead[kNumberOfAccessSizes];
Value *TsanWrite[kNumberOfAccessSizes];
+ Value *TsanVptrUpdate;
};
} // namespace
@@ -105,6 +109,9 @@
TsanWrite[i] = M.getOrInsertFunction(WriteName, IRB.getVoidTy(),
IRB.getInt8PtrTy(), NULL);
}
+ TsanVptrUpdate = M.getOrInsertFunction("__tsan_vptr_update", IRB.getVoidTy(),
+ IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
+ NULL);
return true;
}
@@ -151,10 +158,21 @@
IRBuilder<> IRBRet(RetVec[i]);
IRBRet.CreateCall(TsanFuncExit);
}
+ Res = true;
}
return Res;
}
+static bool isVtableAccess(Instruction *I) {
+ if (MDNode *Tag = I->getMetadata(LLVMContext::MD_tbaa)) {
+ if (Tag->getNumOperands() < 1) return false;
+ if (MDString *Tag1 = dyn_cast<MDString>(Tag->getOperand(0))) {
+ if (Tag1->getString() == "vtable pointer") return true;
+ }
+ }
+ return false;
+}
+
bool ThreadSanitizer::instrumentLoadOrStore(Instruction *I) {
IRBuilder<> IRB(I);
bool IsWrite = isa<StoreInst>(*I);
@@ -170,6 +188,13 @@
// Ignore all unusual sizes.
return false;
}
+ if (IsWrite && isVtableAccess(I)) {
+ Value *StoredValue = cast<StoreInst>(I)->getValueOperand();
+ IRB.CreateCall2(TsanVptrUpdate,
+ IRB.CreatePointerCast(Addr, IRB.getInt8PtrTy()),
+ IRB.CreatePointerCast(StoredValue, IRB.getInt8PtrTy()));
+ return true;
+ }
size_t Idx = CountTrailingZeros_32(TypeSize / 8);
assert(Idx < kNumberOfAccessSizes);
Value *OnAccessFunc = IsWrite ? TsanWrite[Idx] : TsanRead[Idx];
Added: llvm/trunk/test/Instrumentation/ThreadSanitizer/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/ThreadSanitizer/lit.local.cfg?rev=153448&view=auto
==============================================================================
--- llvm/trunk/test/Instrumentation/ThreadSanitizer/lit.local.cfg (added)
+++ llvm/trunk/test/Instrumentation/ThreadSanitizer/lit.local.cfg Mon Mar 26 12:35:03 2012
@@ -0,0 +1 @@
+config.suffixes = ['.ll', '.c', '.cpp']
Added: llvm/trunk/test/Instrumentation/ThreadSanitizer/vptr_update.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/ThreadSanitizer/vptr_update.ll?rev=153448&view=auto
==============================================================================
--- llvm/trunk/test/Instrumentation/ThreadSanitizer/vptr_update.ll (added)
+++ llvm/trunk/test/Instrumentation/ThreadSanitizer/vptr_update.ll Mon Mar 26 12:35:03 2012
@@ -0,0 +1,13 @@
+; RUN: opt < %s -tsan -S | FileCheck %s
+; Check that vtable pointer updates are treated in a special way.
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+
+define void @Foo(i8** nocapture %a, i8* %b) nounwind uwtable {
+entry:
+; CHECK: call void @__tsan_vptr_update
+ store i8* %b, i8** %a, align 8, !tbaa !0
+ ret void
+}
+!0 = metadata !{metadata !"vtable pointer", metadata !1}
+!1 = metadata !{metadata !"Simple C/C++ TBAA", null}
+
More information about the llvm-commits
mailing list