Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp	(revision 154095)
+++ lib/CodeGen/CodeGenModule.cpp	(working copy)
@@ -102,8 +102,9 @@
   if (LangOpts.CUDA)
     createCUDARuntime();
 
-  // Enable TBAA unless it's suppressed.
-  if (!CodeGenOpts.RelaxedAliasing && CodeGenOpts.OptimizationLevel > 0)
+  // Enable TBAA unless it's suppressed. ThreadSanitizer needs TBAA even at O0.
+  if (!CodeGenOpts.RelaxedAliasing &&
+      (CodeGenOpts.OptimizationLevel > 0 || LangOpts.ThreadSanitizer))
     TBAA = new CodeGenTBAA(Context, VMContext, getLangOpts(),
                            ABI.getMangleContext());
 
Index: test/CodeGen/tbaa-for-vptr.cpp
===================================================================
--- test/CodeGen/tbaa-for-vptr.cpp	(revision 154095)
+++ test/CodeGen/tbaa-for-vptr.cpp	(working copy)
@@ -1,5 +1,8 @@
+// RUN: %clang_cc1 -emit-llvm -o - -O0 -fthread-sanitizer %s | FileCheck %s
 // RUN: %clang_cc1 -emit-llvm -o - -O1 %s | FileCheck %s
 // Check that we generate TBAA for vtable pointer loads and stores.
+// TBAA should be generated at -O1 (and higher) as well as at -O0
+// when -fthread-sanitizer is used.
 struct A {
   virtual int foo() const ;
   virtual ~A();
@@ -15,5 +18,4 @@
 
 // CHECK: %{{.*}} = load {{.*}} !tbaa !0
 // CHECK: store {{.*}} !tbaa !0
-// CHECK: !0 = metadata !{metadata !"vtable pointer", metadata !1}
-// CHECK: !1 = metadata !{metadata !"Simple C/C++ TBAA", null}
+// CHECK: !{{.*}} = metadata !{metadata !"vtable pointer", metadata !{{.*}}}
