[cfe-commits] r170314 - in /cfe/trunk: docs/ThreadSanitizer.rst lib/Lex/PPMacroExpansion.cpp test/Lexer/has_feature_thread_sanitizer.cpp

Dmitry Vyukov dvyukov at google.com
Mon Dec 17 00:52:12 PST 2012


Author: dvyukov
Date: Mon Dec 17 02:52:05 2012
New Revision: 170314

URL: http://llvm.org/viewvc/llvm-project?rev=170314&view=rev
Log:
tsan: add __has_feature(thread_sanitizer)

Added:
    cfe/trunk/test/Lexer/has_feature_thread_sanitizer.cpp
Modified:
    cfe/trunk/docs/ThreadSanitizer.rst
    cfe/trunk/lib/Lex/PPMacroExpansion.cpp

Modified: cfe/trunk/docs/ThreadSanitizer.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ThreadSanitizer.rst?rev=170314&r1=170313&r2=170314&view=diff
==============================================================================
--- cfe/trunk/docs/ThreadSanitizer.rst (original)
+++ cfe/trunk/docs/ThreadSanitizer.rst Mon Dec 17 02:52:05 2012
@@ -68,6 +68,20 @@
       #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
 -----------
 

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=170314&r1=170313&r2=170314&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Mon Dec 17 02:52:05 2012
@@ -780,6 +780,7 @@
            .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)

Added: cfe/trunk/test/Lexer/has_feature_thread_sanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/has_feature_thread_sanitizer.cpp?rev=170314&view=auto
==============================================================================
--- cfe/trunk/test/Lexer/has_feature_thread_sanitizer.cpp (added)
+++ cfe/trunk/test/Lexer/has_feature_thread_sanitizer.cpp Mon Dec 17 02:52:05 2012
@@ -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





More information about the cfe-commits mailing list