[tsan] fix PR18146: sometimes a variable written into vptr could have an integer...
authorKostya Serebryany <kcc@google.com>
Thu, 5 Dec 2013 15:03:02 +0000 (15:03 +0000)
committerKostya Serebryany <kcc@google.com>
Thu, 5 Dec 2013 15:03:02 +0000 (15:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196507 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/ThreadSanitizer.cpp
test/Instrumentation/ThreadSanitizer/vptr_update.ll

index baec1534e00e9598a812b8d4db7a45ac6801e2b7..5c1881782008e33cd55ea03324efc5734003e855 100644 (file)
@@ -408,10 +408,12 @@ bool ThreadSanitizer::instrumentLoadOrStore(Instruction *I) {
     if (isa<VectorType>(StoredValue->getType()))
       StoredValue = IRB.CreateExtractElement(
           StoredValue, ConstantInt::get(IRB.getInt32Ty(), 0));
+    if (StoredValue->getType()->isIntegerTy())
+      StoredValue = IRB.CreateIntToPtr(StoredValue, IRB.getInt8PtrTy());
     // Call TsanVptrUpdate.
     IRB.CreateCall2(TsanVptrUpdate,
                     IRB.CreatePointerCast(Addr, IRB.getInt8PtrTy()),
-                    IRB.CreateBitCast(StoredValue, IRB.getInt8PtrTy()));
+                    IRB.CreatePointerCast(StoredValue, IRB.getInt8PtrTy()));
     NumInstrumentedVtableWrites++;
     return true;
   }
index 46650040540df3da0d0da3980923e387dd1043ae..83d28b6ee217920bb420bfc9902ba400a5d3a0c2 100644 (file)
@@ -11,6 +11,16 @@ entry:
   ret void
 }
 
+define void @FooInt(i64* nocapture %a, i64 %b) nounwind uwtable sanitize_thread {
+entry:
+; CHECK-LABEL: @FooInt
+; CHECK: call void @__tsan_vptr_update
+; CHECK: ret void
+  store i64 %b, i64* %a, align 8, !tbaa !0
+  ret void
+}
+
+
 declare i32 @Func1()
 declare i32 @Func2()