aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2012-12-17 08:52:05 +0000
committerDmitry Vyukov <dvyukov@google.com>2012-12-17 08:52:05 +0000
commit728e2127e858611750d560ee7692c322a8570faa (patch)
treee894d764b45dc674c9dfff3232202bb3cdcc39ea
parentc092cbab26ee4e2875a5d99d7d9ad16b25e8f36d (diff)
tsan: add __has_feature(thread_sanitizer)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170314 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--docs/ThreadSanitizer.rst14
-rw-r--r--lib/Lex/PPMacroExpansion.cpp1
-rw-r--r--test/Lexer/has_feature_thread_sanitizer.cpp11
3 files changed, 26 insertions, 0 deletions
diff --git a/docs/ThreadSanitizer.rst b/docs/ThreadSanitizer.rst
index e434062bed..4cf0e37f83 100644
--- a/docs/ThreadSanitizer.rst
+++ b/docs/ThreadSanitizer.rst
@@ -68,6 +68,20 @@ Currently, ThreadSanitizer symbolizes its output using an external
#0 pthread_create tsan_interceptors.cc:705 (exe+0x00000000c790)
#1 main tiny_race.c:9 (exe+0x00000000a3a4)
+``__has_feature(thread_sanitizer)``
+------------------------------------
+
+In some cases one may need to execute different code depending on whether
+ThreadSanitizer is enabled.
+:ref:`\_\_has\_feature <langext-__has_feature-__has_extension>` can be used for
+this purpose.
+
+.. code-block:: c
+
+ #if defined(__has_feature) && __has_feature(thread_sanitizer)
+ // code that builds only under ThreadSanitizer
+ #endif
+
Limitations
-----------
diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp
index 5582100918..941c2d47d0 100644
--- a/lib/Lex/PPMacroExpansion.cpp
+++ b/lib/Lex/PPMacroExpansion.cpp
@@ -780,6 +780,7 @@ static bool HasFeature(const Preprocessor &PP, const IdentifierInfo *II) {
.Case("cxx_exceptions", LangOpts.Exceptions)
.Case("cxx_rtti", LangOpts.RTTI)
.Case("enumerator_attributes", true)
+ .Case("thread_sanitizer", LangOpts.SanitizeThread)
// Objective-C features
.Case("objc_arr", LangOpts.ObjCAutoRefCount) // FIXME: REMOVE?
.Case("objc_arc", LangOpts.ObjCAutoRefCount)
diff --git a/test/Lexer/has_feature_thread_sanitizer.cpp b/test/Lexer/has_feature_thread_sanitizer.cpp
new file mode 100644
index 0000000000..0a248100c8
--- /dev/null
+++ b/test/Lexer/has_feature_thread_sanitizer.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -E -fsanitize=thread %s -o - | FileCheck --check-prefix=CHECK-TSAN %s
+// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-TSAN %s
+
+#if __has_feature(thread_sanitizer)
+int ThreadSanitizerEnabled();
+#else
+int ThreadSanitizerDisabled();
+#endif
+
+// CHECK-TSAN: ThreadSanitizerEnabled
+// CHECK-NO-TSAN: ThreadSanitizerDisabled