Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp	(revision 162259)
+++ lib/CodeGen/CodeGenModule.cpp	(working copy)
@@ -594,6 +594,16 @@
       F->addFnAttr(llvm::Attribute::AddressSafety);
   }
 
+  if (LangOpts.ThreadSanitizer) {
+    // For ThreadSanitizer we emit module-level metadata that lists
+    // all the functions we want to instrument.
+    // FIXME: stop using llvm::Attribute::AddressSafety for AddressSanitizer
+    // and use the same metadata approach instead.
+    llvm::Value *Fn[] = { F };
+    getModule().getOrInsertNamedMetadata("llvm.tsan.functions_to_instrument")->
+        addOperand(llvm::MDNode::get(VMContext, Fn));
+  }
+
   unsigned alignment = D->getMaxAlignment() / Context.getCharWidth();
   if (alignment)
     F->setAlignment(alignment);
