[PATCH] D24770: [libcxxabi] cleanup the use of LIBCXXABI_HAS_NO_THREADS macro (NFC)

2016-09-20 Thread Asiri Rathnayake via cfe-commits
rmaprath created this revision.
rmaprath added reviewers: mclow.lists, EricWF.
rmaprath added a subscriber: cfe-commits.
Herald added subscribers: mgorny, beanz.

Align the naming / use of the macro ``LIBCXXABI_HAS_NO_THREADS`` to follow what 
we have in `libcxx`.

This change is mostly NFC, thought of putting it up for review as it involves a 
change in naming, and sometimes that can cause disagreements.

Will commit if there isn't much interest.

https://reviews.llvm.org/D24770

Files:
  CMakeLists.txt
  src/config.h
  src/cxa_exception.cpp
  src/cxa_exception_storage.cpp
  src/cxa_guard.cpp
  src/fallback_malloc.ipp
  test/libcxxabi/test/config.py
  test/test_exception_storage.pass.cpp
  test/test_guard.pass.cpp

Index: test/test_guard.pass.cpp
===
--- test/test_guard.pass.cpp
+++ test/test_guard.pass.cpp
@@ -12,7 +12,7 @@
 
 #include 
 
-#if !LIBCXXABI_HAS_NO_THREADS
+#ifndef _LIBCXXABI_HAS_NO_THREADS
 #include 
 #endif
 
@@ -80,7 +80,7 @@
 }
 }
 
-#if !LIBCXXABI_HAS_NO_THREADS
+#ifndef _LIBCXXABI_HAS_NO_THREADS
 // A simple thread test of two threads racing to initialize a variable. This
 // isn't guaranteed to catch any particular threading problems.
 namespace test4 {
@@ -132,14 +132,14 @@
 assert(run_count == 1);
 }
 }
-#endif /* LIBCXXABI_HAS_NO_THREADS */
+#endif /* _LIBCXXABI_HAS_NO_THREADS */
 
 int main()
 {
 test1::test();
 test2::test();
 test3::test();
-#if !LIBCXXABI_HAS_NO_THREADS
+#ifndef _LIBCXXABI_HAS_NO_THREADS
 test4::test();
 test5::test();
 #endif
Index: test/test_exception_storage.pass.cpp
===
--- test/test_exception_storage.pass.cpp
+++ test/test_exception_storage.pass.cpp
@@ -12,7 +12,7 @@
 #include 
 #include 
 #include 
-#if !LIBCXXABI_HAS_NO_THREADS
+#ifndef _LIBCXXABI_HAS_NO_THREADS
 #  include 
 #endif
 #include 
@@ -38,29 +38,16 @@
 return parm;
 }
 
-#if !LIBCXXABI_HAS_NO_THREADS
+#ifndef _LIBCXXABI_HAS_NO_THREADS
 #define NUMTHREADS  10
 size_t  thread_globals [ NUMTHREADS ] = { 0 };
 pthread_t   threads[ NUMTHREADS ];
 #endif
 
-void print_sizes ( size_t *first, size_t *last ) {
-std::cout << "{ " << std::hex;
-for ( size_t *iter = first; iter != last; ++iter )
-std::cout << *iter << " ";
-std::cout << "}" << std::dec << std::endl;
-}
-
 int main ( int argc, char *argv [] ) {
 int retVal = 0;
 
-#if LIBCXXABI_HAS_NO_THREADS
-size_t thread_globals;
-// Check that __cxa_get_globals() is not NULL.
-if (thread_code(&thread_globals) == 0) {
-retVal = 1;
-}
-#else
+#ifndef _LIBCXXABI_HAS_NO_THREADS
 //  Make the threads, let them run, and wait for them to finish
 for ( int i = 0; i < NUMTHREADS; ++i )
 pthread_create( threads + i, NULL, thread_code, (void *) (thread_globals + i));
@@ -73,15 +60,18 @@
 retVal = 1;
 }
 
-//  print_sizes ( thread_globals, thread_globals + NUMTHREADS );
 std::sort ( thread_globals, thread_globals + NUMTHREADS );
 for ( int i = 1; i < NUMTHREADS; ++i )
 if ( thread_globals [ i - 1 ] == thread_globals [ i ] ) {
 std::cerr << "Duplicate thread globals (" << i-1 << " and " << i << ")" << std::endl;
 retVal = 2;
 }
-//  print_sizes ( thread_globals, thread_globals + NUMTHREADS );
-
-#endif
-return retVal;
+#else // _LIBCXXABI_HAS_NO_THREADS
+size_t thread_globals;
+// Check that __cxa_get_globals() is not NULL.
+if (thread_code(&thread_globals) == 0) {
+retVal = 1;
 }
+#endif // !_LIBCXXABI_HAS_NO_THREADS
+return retVal;
+}
Index: test/libcxxabi/test/config.py
===
--- test/libcxxabi/test/config.py
+++ test/libcxxabi/test/config.py
@@ -47,7 +47,7 @@
 else:
 self.cxx.compile_flags += ['-fno-exceptions', '-DLIBCXXABI_HAS_NO_EXCEPTIONS']
 if not self.get_lit_bool('enable_threads', True):
-self.cxx.compile_flags += ['-DLIBCXXABI_HAS_NO_THREADS=1']
+self.cxx.compile_flags += ['-D_LIBCXXABI_HAS_NO_THREADS']
 super(Configuration, self).configure_compile_flags()
 
 def configure_compile_flags_header_includes(self):
Index: src/fallback_malloc.ipp
===
--- src/fallback_malloc.ipp
+++ src/fallback_malloc.ipp
@@ -26,25 +26,25 @@
 namespace {
 
 // When POSIX threads are not available, make the mutex operations a nop
-#if LIBCXXABI_HAS_NO_THREADS
-static void * heap_mutex = 0;
-#else
+#ifndef _LIBCXXABI_HAS_NO_THREADS
 static pthread_mutex_t heap_mutex = PTHREAD_MUTEX_INITIALIZER;
+#else
+static void * heap_mutex = 0;
 #endif
 
 class mutexor {
 public:
-#if LIBCXXABI_HAS_NO_THREADS
-mutexor ( void * ) {}
-~mutexor () {}
-#else
+#ifndef _LIBCXXABI_HAS_NO_THREADS
 mutexor ( pthread_mutex_t *m ) : mtx_(

[libcxxabi] r282062 - [libcxxabi] cleanup the use of LIBCXXABI_HAS_NO_THREADS macro (NFC)

2016-09-21 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Wed Sep 21 04:09:32 2016
New Revision: 282062

URL: http://llvm.org/viewvc/llvm-project?rev=282062&view=rev
Log:
[libcxxabi] cleanup the use of LIBCXXABI_HAS_NO_THREADS macro (NFC)

Align the naming / use of the macro LIBCXXABI_HAS_NO_THREADS to follow what we
have in libcxx. NFC.

Modified:
libcxxabi/trunk/CMakeLists.txt
libcxxabi/trunk/src/config.h
libcxxabi/trunk/src/cxa_exception.cpp
libcxxabi/trunk/src/cxa_exception_storage.cpp
libcxxabi/trunk/src/cxa_guard.cpp
libcxxabi/trunk/src/fallback_malloc.ipp
libcxxabi/trunk/test/libcxxabi/test/config.py
libcxxabi/trunk/test/test_exception_storage.pass.cpp
libcxxabi/trunk/test/test_guard.pass.cpp

Modified: libcxxabi/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/CMakeLists.txt?rev=282062&r1=282061&r2=282062&view=diff
==
--- libcxxabi/trunk/CMakeLists.txt (original)
+++ libcxxabi/trunk/CMakeLists.txt Wed Sep 21 04:09:32 2016
@@ -326,7 +326,7 @@ if (NOT LIBCXXABI_ENABLE_THREADS)
 " be set to ON when LIBCXXABI_ENABLE_THREADS"
 " is also set to ON.")
   endif()
-  add_definitions(-DLIBCXXABI_HAS_NO_THREADS=1)
+  add_definitions(-D_LIBCXXABI_HAS_NO_THREADS)
 endif()
 
 if (LIBCXXABI_HAS_PTHREAD_API)

Modified: libcxxabi/trunk/src/config.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/config.h?rev=282062&r1=282061&r2=282062&view=diff
==
--- libcxxabi/trunk/src/config.h (original)
+++ libcxxabi/trunk/src/config.h Wed Sep 21 04:09:32 2016
@@ -16,11 +16,6 @@
 
 #include 
 
-// Set this in the CXXFLAGS when you need it
-#if !defined(LIBCXXABI_HAS_NO_THREADS)
-#  define LIBCXXABI_HAS_NO_THREADS 0
-#endif
-
 // Set this in the CXXFLAGS when you need it, because otherwise we'd have to
 // #if !defined(__linux__) && !defined(__APPLE__) && ...
 // and so-on for *every* platform.

Modified: libcxxabi/trunk/src/cxa_exception.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception.cpp?rev=282062&r1=282061&r2=282062&view=diff
==
--- libcxxabi/trunk/src/cxa_exception.cpp (original)
+++ libcxxabi/trunk/src/cxa_exception.cpp Wed Sep 21 04:09:32 2016
@@ -17,7 +17,7 @@
 #include // for std::terminate
 #include   // for malloc, free
 #include   // for memset
-#if !LIBCXXABI_HAS_NO_THREADS
+#ifndef _LIBCXXABI_HAS_NO_THREADS
 #  include   // for fallback_malloc.ipp's mutexes
 #endif
 #include "cxa_exception.hpp"

Modified: libcxxabi/trunk/src/cxa_exception_storage.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception_storage.cpp?rev=282062&r1=282061&r2=282062&view=diff
==
--- libcxxabi/trunk/src/cxa_exception_storage.cpp (original)
+++ libcxxabi/trunk/src/cxa_exception_storage.cpp Wed Sep 21 04:09:32 2016
@@ -15,7 +15,7 @@
 
 #include "config.h"
 
-#if LIBCXXABI_HAS_NO_THREADS
+#if defined(_LIBCXXABI_HAS_NO_THREADS)
 
 namespace __cxxabiv1 {
 extern "C" {

Modified: libcxxabi/trunk/src/cxa_guard.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_guard.cpp?rev=282062&r1=282061&r2=282062&view=diff
==
--- libcxxabi/trunk/src/cxa_guard.cpp (original)
+++ libcxxabi/trunk/src/cxa_guard.cpp Wed Sep 21 04:09:32 2016
@@ -12,7 +12,7 @@
 #include "abort_message.h"
 #include "config.h"
 
-#if !LIBCXXABI_HAS_NO_THREADS
+#ifndef _LIBCXXABI_HAS_NO_THREADS
 #  include 
 #endif
 #include 
@@ -50,7 +50,7 @@ void set_initialized(guard_type* guard_o
 }
 #endif
 
-#if LIBCXXABI_HAS_NO_THREADS || (defined(__APPLE__) && !defined(__arm__))
+#if defined(_LIBCXXABI_HAS_NO_THREADS) || (defined(__APPLE__) && 
!defined(__arm__))
 #ifdef __arm__
 
 // Test the lowest bit.
@@ -68,7 +68,7 @@ bool is_initialized(guard_type* guard_ob
 #endif
 #endif
 
-#if !LIBCXXABI_HAS_NO_THREADS
+#ifndef _LIBCXXABI_HAS_NO_THREADS
 pthread_mutex_t guard_mut = PTHREAD_MUTEX_INITIALIZER;
 pthread_cond_t  guard_cv  = PTHREAD_COND_INITIALIZER;
 #endif
@@ -172,22 +172,7 @@ set_lock(uint32_t& x, lock_type y)
 extern "C"
 {
 
-#if LIBCXXABI_HAS_NO_THREADS
-_LIBCXXABI_FUNC_VIS int __cxa_guard_acquire(guard_type *guard_object) {
-return !is_initialized(guard_object);
-}
-
-_LIBCXXABI_FUNC_VIS void __cxa_guard_release(guard_type *guard_object) {
-*guard_object = 0;
-set_initialized(guard_object);
-}
-
-_LIBCXXABI_FUNC_VIS void __cxa_guard_abort(guard_type *guard_object) {
-*guard_object = 0;
-}
-
-#else // !LIBCXXABI_HAS_NO_THREADS
-
+#ifndef _LIBCXXABI_HAS_NO_THREADS
 _LIBCXXABI_FUNC_VIS int __cxa_guard_acquire(guard_type *guard_object) {
 char* initialized = (char*)guard_object;
 if (pthread_mutex_loc

Re: [PATCH] D24770: [libcxxabi] cleanup the use of LIBCXXABI_HAS_NO_THREADS macro (NFC)

2016-09-21 Thread Asiri Rathnayake via cfe-commits
rmaprath closed this revision.
rmaprath added a comment.

In https://reviews.llvm.org/D24770#547701, @jroelofs wrote:

> LGTM


Thanks!

Committed as r282062.

/ Asiri


https://reviews.llvm.org/D24770



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24864: [libcxxabi] Refactor pthread usage into a separate API

2016-09-23 Thread Asiri Rathnayake via cfe-commits
rmaprath created this revision.
rmaprath added reviewers: EricWF, mclow.lists, jroelofs, compnerd.
rmaprath added a subscriber: cfe-commits.

This is simply a cleanup of D18482 (patch taken with permission) while adapting 
it to match what we have already implemented for libcxx.

Note that I haven't included the external-threading stuff yet, this is only 
refactoring pthread usage of libcxxabi. A follow-up patch will add the 
external-threading support.

https://reviews.llvm.org/D24864

Files:
  include/__cxxabi_config.h
  src/config.h
  src/cxa_exception.cpp
  src/cxa_exception_storage.cpp
  src/cxa_guard.cpp
  src/fallback_malloc.ipp
  src/threading_support.h
  test/test_fallback_malloc.pass.cpp

Index: test/test_fallback_malloc.pass.cpp
===
--- test/test_fallback_malloc.pass.cpp
+++ test/test_fallback_malloc.pass.cpp
@@ -10,7 +10,7 @@
 #include 
 #include 
 
-#include 
+#include "../src/threading_support.h"
 
 typedef std::deque container;
 
Index: src/threading_support.h
===
--- /dev/null
+++ src/threading_support.h
@@ -0,0 +1,82 @@
+//=== threading_support.h -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef _LIBCXXABI_THREADING_SUPPORT_H
+#define _LIBCXXABI_THREADING_SUPPORT_H
+
+#include "__cxxabi_config.h"
+#include "config.h"
+
+#ifndef _LIBCXXABI_HAS_NO_THREADS
+
+#if defined(_LIBCXXABI_HAS_THREAD_API_PTHREAD)
+#include 
+
+#define _LIBCXXABI_THREAD_ABI_VISIBILITY inline _LIBCXXABI_INLINE_VISIBILITY
+
+// Mutex
+typedef pthread_mutex_t __libcxxabi_mutex_t;
+#define _LIBCXXABI_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_mutex_lock(__libcxxabi_mutex_t *mutex) {
+  return pthread_mutex_lock(mutex);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_mutex_unlock(__libcxxabi_mutex_t *mutex) {
+  return pthread_mutex_unlock(mutex);
+}
+
+// Condition variable
+typedef pthread_cond_t __libcxxabi_condvar_t;
+#define _LIBCXXABI_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_condvar_wait(__libcxxabi_condvar_t *cv,
+ __libcxxabi_mutex_t *mutex) {
+  return pthread_cond_wait(cv, mutex);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_condvar_broadcast(__libcxxabi_condvar_t *cv) {
+  return pthread_cond_broadcast(cv);
+}
+
+// Execute once
+typedef pthread_once_t __libcxxabi_exec_once_flag;
+#define _LIBCXXABI_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_execute_once(__libcxxabi_exec_once_flag *flag,
+ void (*init_routine)(void)) {
+  return pthread_once(flag, init_routine);
+}
+
+// TLS
+typedef pthread_key_t __libcxxabi_tls_key;
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_tls_create(__libcxxabi_tls_key *key,
+   void (*destructor)(void *)) {
+  return pthread_key_create(key, destructor);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+void *__libcxxabi_tls_get(__libcxxabi_tls_key key) {
+  return pthread_getspecific(key);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_tls_set(__libcxxabi_tls_key key, void *value) {
+  return pthread_setspecific(key, value);
+}
+#endif // _LIBCXXABI_HAS_THREAD_API_PTHREAD
+#endif // !_LIBCXXABI_HAS_NO_THREADS
+#endif // _LIBCXXABI_THREADING_SUPPORT_H
Index: src/fallback_malloc.ipp
===
--- src/fallback_malloc.ipp
+++ src/fallback_malloc.ipp
@@ -27,25 +27,25 @@
 
 // When POSIX threads are not available, make the mutex operations a nop
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-static pthread_mutex_t heap_mutex = PTHREAD_MUTEX_INITIALIZER;
+static __libcxxabi_mutex_t heap_mutex = PTHREAD_MUTEX_INITIALIZER;
 #else
 static void * heap_mutex = 0;
 #endif
 
 class mutexor {
 public:
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-mutexor ( pthread_mutex_t *m ) : mtx_(m) { pthread_mutex_lock ( mtx_ ); }
-~mutexor () { pthread_mutex_unlock ( mtx_ ); }
+mutexor ( __libcxxabi_mutex_t *m ) : mtx_(m) { __libcxxabi_mutex_lock ( mtx_ ); }
+~mutexor () { __libcxxabi_mutex_unlock ( mtx_ ); }
 #else
 mutexor ( void * ) {}
 ~mutexor () {}
 #endif
 private:
 mutexor ( const mutexor &rhs );
 mutexor & operator = ( const mutexor &rhs );
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-pthread_mutex_t *mtx_;
+__libcxxabi_mutex_t *mtx_;
 #endif
 };
 
Index: src/cxa_guard.cpp
===
--- src/cxa_guard.cpp
+++ src/cxa_guard.cpp
@@ -11,20 +11,18 @@
 
 #include "abort_message.h"
 #include "config.h"
+

Re: [PATCH] D24903: [libcxx] [include] Declare __STDC_*_MACROS for C++11 compat in old libc

2016-09-25 Thread Asiri Rathnayake via cfe-commits
rmaprath added a subscriber: rmaprath.
rmaprath added a comment.

When the `` headers where split into `` and `` headers in 
https://reviews.llvm.org/D12747, we have left out `` and ``. I 
was going to put up a patch to fix this but couldn't get to it. It's good that 
you are adding ``, perhaps you can follow what was done in 
https://reviews.llvm.org/D12747 and repeat the same for ``?

You will also need a test for the new header, https://reviews.llvm.org/D12747 
has examples.

Hope this helps!

/ Asiri


https://reviews.llvm.org/D24903



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24903: [libcxx] [include] Declare __STDC_*_MACROS for C++11 compat in old libc

2016-09-26 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

In https://reviews.llvm.org/D24903#551926, @mgorny wrote:

> I'm sorry but could you be a little more specific, please? I've looked into 
> that diff, and it seems that the cstdint resembles e.g. cinttypes already -- 
> i.e. there's only the include, and 'using' lines there. Or do you mean that I 
> should copy/update the synopsis over to stdint.h?


My bad, I hadn't actually looked at the current status of ``, it 
doesn't seem to need any more work.

/ Asiri


https://reviews.llvm.org/D24903



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24903: [libcxx] [include] Declare __STDC_*_MACROS for C++11 compat in old libc

2016-09-26 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

In https://reviews.llvm.org/D24903#551938, @mgorny wrote:

> I see that libcxx already has a pretty complete test for stdint.h.


Hmm, now I see that too :)

Thanks for the patch.

/ Asiri


https://reviews.llvm.org/D24903



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24864: [libcxxabi] Refactor pthread usage into a separate API

2016-09-26 Thread Asiri Rathnayake via cfe-commits
rmaprath updated this revision to Diff 72478.
rmaprath added a comment.

Use `__internal_linkage__` attribute to control visibility following 
https://reviews.llvm.org/D24642.


https://reviews.llvm.org/D24864

Files:
  include/__cxxabi_config.h
  src/config.h
  src/cxa_exception.cpp
  src/cxa_exception_storage.cpp
  src/cxa_guard.cpp
  src/fallback_malloc.ipp
  src/threading_support.h
  test/test_fallback_malloc.pass.cpp

Index: test/test_fallback_malloc.pass.cpp
===
--- test/test_fallback_malloc.pass.cpp
+++ test/test_fallback_malloc.pass.cpp
@@ -10,7 +10,7 @@
 #include 
 #include 
 
-#include 
+#include "../src/threading_support.h"
 
 typedef std::deque container;
 
Index: src/threading_support.h
===
--- /dev/null
+++ src/threading_support.h
@@ -0,0 +1,82 @@
+//=== threading_support.h -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef _LIBCXXABI_THREADING_SUPPORT_H
+#define _LIBCXXABI_THREADING_SUPPORT_H
+
+#include "__cxxabi_config.h"
+#include "config.h"
+
+#ifndef _LIBCXXABI_HAS_NO_THREADS
+
+#if defined(_LIBCXXABI_HAS_THREAD_API_PTHREAD)
+#include 
+
+#define _LIBCXXABI_THREAD_ABI_VISIBILITY inline _LIBCXXABI_INLINE_VISIBILITY
+
+// Mutex
+typedef pthread_mutex_t __libcxxabi_mutex_t;
+#define _LIBCXXABI_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_mutex_lock(__libcxxabi_mutex_t *mutex) {
+  return pthread_mutex_lock(mutex);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_mutex_unlock(__libcxxabi_mutex_t *mutex) {
+  return pthread_mutex_unlock(mutex);
+}
+
+// Condition variable
+typedef pthread_cond_t __libcxxabi_condvar_t;
+#define _LIBCXXABI_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_condvar_wait(__libcxxabi_condvar_t *cv,
+ __libcxxabi_mutex_t *mutex) {
+  return pthread_cond_wait(cv, mutex);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_condvar_broadcast(__libcxxabi_condvar_t *cv) {
+  return pthread_cond_broadcast(cv);
+}
+
+// Execute once
+typedef pthread_once_t __libcxxabi_exec_once_flag;
+#define _LIBCXXABI_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_execute_once(__libcxxabi_exec_once_flag *flag,
+ void (*init_routine)(void)) {
+  return pthread_once(flag, init_routine);
+}
+
+// TLS
+typedef pthread_key_t __libcxxabi_tls_key;
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_tls_create(__libcxxabi_tls_key *key,
+   void (*destructor)(void *)) {
+  return pthread_key_create(key, destructor);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+void *__libcxxabi_tls_get(__libcxxabi_tls_key key) {
+  return pthread_getspecific(key);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_tls_set(__libcxxabi_tls_key key, void *value) {
+  return pthread_setspecific(key, value);
+}
+#endif // _LIBCXXABI_HAS_THREAD_API_PTHREAD
+#endif // !_LIBCXXABI_HAS_NO_THREADS
+#endif // _LIBCXXABI_THREADING_SUPPORT_H
Index: src/fallback_malloc.ipp
===
--- src/fallback_malloc.ipp
+++ src/fallback_malloc.ipp
@@ -27,25 +27,25 @@
 
 // When POSIX threads are not available, make the mutex operations a nop
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-static pthread_mutex_t heap_mutex = PTHREAD_MUTEX_INITIALIZER;
+static __libcxxabi_mutex_t heap_mutex = PTHREAD_MUTEX_INITIALIZER;
 #else
 static void * heap_mutex = 0;
 #endif
 
 class mutexor {
 public:
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-mutexor ( pthread_mutex_t *m ) : mtx_(m) { pthread_mutex_lock ( mtx_ ); }
-~mutexor () { pthread_mutex_unlock ( mtx_ ); }
+mutexor ( __libcxxabi_mutex_t *m ) : mtx_(m) { __libcxxabi_mutex_lock ( mtx_ ); }
+~mutexor () { __libcxxabi_mutex_unlock ( mtx_ ); }
 #else
 mutexor ( void * ) {}
 ~mutexor () {}
 #endif
 private:
 mutexor ( const mutexor &rhs );
 mutexor & operator = ( const mutexor &rhs );
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-pthread_mutex_t *mtx_;
+__libcxxabi_mutex_t *mtx_;
 #endif
 };
 
Index: src/cxa_guard.cpp
===
--- src/cxa_guard.cpp
+++ src/cxa_guard.cpp
@@ -11,20 +11,18 @@
 
 #include "abort_message.h"
 #include "config.h"
+#include "threading_support.h"
 
-#ifndef _LIBCXXABI_HAS_NO_THREADS
-#  include 
-#endif
 #include 
 
 /*
 This implementation must be careful to not call code external to this file
 which will turn around and try to call __cxa_guard_acquire reentrantly.
 For this reas

Re: [PATCH] D24119: [libc++] add linker option "-Wl, -z, defs" in standalone build

2016-09-27 Thread Asiri Rathnayake via cfe-commits
rmaprath added a subscriber: rmaprath.


Comment at: libcxx/trunk/CMakeLists.txt:329
@@ +328,3 @@
+  ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") AND
+ NOT LLVM_USE_SANITIZER)
+set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")

Perhaps we should exclude `LIBCXX_HAS_EXTERNAL_THREAD_API` as well? Because 
there we explicitly strip off these flags.


Repository:
  rL LLVM

https://reviews.llvm.org/D24119



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24864: [libcxxabi] Refactor pthread usage into a separate API

2016-09-27 Thread Asiri Rathnayake via cfe-commits
rmaprath added inline comments.


Comment at: src/config.h:22
@@ +21,3 @@
+
+#if defined(__GNUC__) || defined(__clang__)
+#define _LIBCXXABI_PRAGMA(_parameter_) _Pragma(#_parameter_)

EricWF wrote:
> What's the point of defining `_LIBCXXABI_WARNING`? It's unused and seems 
> unneeded.
Good catch. I have copy-pasted this lot without checking.


Comment at: src/config.h:41
@@ +40,3 @@
+defined(__CloudABI__) || \
+defined(__sun__)
+#  define _LIBCXXABI_HAS_THREAD_API_PTHREAD

compnerd wrote:
> Can you change this to `defined(__sun__) && defined(_POSIX_THREADS)` at the 
> very least?  There is no reason to assume pthreads on Solaris.  Solaris 
> Threads are a valid threading model.
Not sure if I understand completely, `libcxxabi` currently either supports 
`pthread` or no-threads, either of which can be explicitly configured through a 
cmake option. So I don't see the point in checking for `_POSIX_THREADS` here as 
the only current threading option is `pthread`. When we add another threading 
system into the mix (like external threading), that too will be configurable 
with a cmake option, the defaulting to `pthread` is only when no particular 
threading system is selected.

Or is it that `pthread.h` et. al can be provided by Solaris Threads as well? 
So, the pthread API has two implementations on Solaris?


Comment at: src/config.h:42
@@ +41,3 @@
+defined(__sun__)
+#  define _LIBCXXABI_HAS_THREAD_API_PTHREAD
+# else

compnerd wrote:
> Can we use `_LIBCXXABI_USE_THREAD_API_PTHREAD` instead?  You can have more 
> than one threading API on a platform, and wish to use a specific one.
Makes sense. Need to change the convention used in `libcxx` too, but that can 
be done later.


Comment at: src/config.h:46
@@ +45,3 @@
+# endif
+#endif
+

compnerd wrote:
> I really think that we should use `_POSIX_THREADS` macro rather than this 
> enumeration approach.
`_LIBCXXABI_USE_THREAD_API_` allows us to be consistent with naming of the 
different threading variants (e.g. I'm going to add 
`_LIBCXXABI_USE_THREAD_API_EXTENRAL` soon). Is there some functional benefit to 
using `_POSIX_THREADS` for the pthread variant?


Comment at: src/fallback_malloc.ipp:30
@@ -29,3 +29,3 @@
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-static pthread_mutex_t heap_mutex = PTHREAD_MUTEX_INITIALIZER;
+static __libcxxabi_mutex_t heap_mutex = _LIBCXXABI_MUTEX_INITIALIZER;
 #else

Thanks for the catch.


https://reviews.llvm.org/D24864



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24119: [libc++] add linker option "-Wl, -z, defs" in standalone build

2016-09-27 Thread Asiri Rathnayake via cfe-commits
rmaprath added inline comments.


Comment at: libcxx/trunk/CMakeLists.txt:329
@@ +328,3 @@
+  ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") AND
+ NOT LLVM_USE_SANITIZER)
+set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")

zlei wrote:
> rmaprath wrote:
> > Perhaps we should exclude `LIBCXX_HAS_EXTERNAL_THREAD_API` as well? Because 
> > there we explicitly strip off these flags.
> I agree. Could you prepare a patch for it?
> 
> BTW, I really don't like duplicating code snippet from llvm. Is there any 
> better solution for that?
Sure, I'll do a patch.

Btw, I think this configuration is better placed in `HandleOutOfTreeLLVM.cmake` 
module.

I'll see if I can find a better way to do this.


Repository:
  rL LLVM

https://reviews.llvm.org/D24119



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24864: [libcxxabi] Refactor pthread usage into a separate API

2016-09-27 Thread Asiri Rathnayake via cfe-commits
rmaprath updated this revision to Diff 72653.
rmaprath added a comment.
Herald added subscribers: mgorny, beanz.

Address review comments from @compnerd and @EricWF.


https://reviews.llvm.org/D24864

Files:
  CMakeLists.txt
  src/config.h
  src/cxa_exception.cpp
  src/cxa_exception_storage.cpp
  src/cxa_guard.cpp
  src/fallback_malloc.ipp
  src/threading_support.h
  test/test_fallback_malloc.pass.cpp

Index: test/test_fallback_malloc.pass.cpp
===
--- test/test_fallback_malloc.pass.cpp
+++ test/test_fallback_malloc.pass.cpp
@@ -10,7 +10,7 @@
 #include 
 #include 
 
-#include 
+#include "../src/threading_support.h"
 
 typedef std::deque container;
 
Index: src/threading_support.h
===
--- /dev/null
+++ src/threading_support.h
@@ -0,0 +1,82 @@
+//=== threading_support.h -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef _LIBCXXABI_THREADING_SUPPORT_H
+#define _LIBCXXABI_THREADING_SUPPORT_H
+
+#include "__cxxabi_config.h"
+#include "config.h"
+
+#ifndef _LIBCXXABI_HAS_NO_THREADS
+
+#if defined(_LIBCXXABI_USE_THREAD_API_PTHREAD)
+#include 
+
+#define _LIBCXXABI_THREAD_ABI_VISIBILITY inline _LIBCXXABI_INLINE_VISIBILITY
+
+// Mutex
+typedef pthread_mutex_t __libcxxabi_mutex_t;
+#define _LIBCXXABI_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_mutex_lock(__libcxxabi_mutex_t *mutex) {
+  return pthread_mutex_lock(mutex);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_mutex_unlock(__libcxxabi_mutex_t *mutex) {
+  return pthread_mutex_unlock(mutex);
+}
+
+// Condition variable
+typedef pthread_cond_t __libcxxabi_condvar_t;
+#define _LIBCXXABI_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_condvar_wait(__libcxxabi_condvar_t *cv,
+ __libcxxabi_mutex_t *mutex) {
+  return pthread_cond_wait(cv, mutex);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_condvar_broadcast(__libcxxabi_condvar_t *cv) {
+  return pthread_cond_broadcast(cv);
+}
+
+// Execute once
+typedef pthread_once_t __libcxxabi_exec_once_flag;
+#define _LIBCXXABI_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_execute_once(__libcxxabi_exec_once_flag *flag,
+ void (*init_routine)(void)) {
+  return pthread_once(flag, init_routine);
+}
+
+// TLS
+typedef pthread_key_t __libcxxabi_tls_key;
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_tls_create(__libcxxabi_tls_key *key,
+   void (*destructor)(void *)) {
+  return pthread_key_create(key, destructor);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+void *__libcxxabi_tls_get(__libcxxabi_tls_key key) {
+  return pthread_getspecific(key);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_tls_set(__libcxxabi_tls_key key, void *value) {
+  return pthread_setspecific(key, value);
+}
+#endif // _LIBCXXABI_USE_THREAD_API_PTHREAD
+#endif // !_LIBCXXABI_HAS_NO_THREADS
+#endif // _LIBCXXABI_THREADING_SUPPORT_H
Index: src/fallback_malloc.ipp
===
--- src/fallback_malloc.ipp
+++ src/fallback_malloc.ipp
@@ -27,25 +27,25 @@
 
 // When POSIX threads are not available, make the mutex operations a nop
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-static pthread_mutex_t heap_mutex = PTHREAD_MUTEX_INITIALIZER;
+static __libcxxabi_mutex_t heap_mutex = _LIBCXXABI_MUTEX_INITIALIZER;
 #else
 static void * heap_mutex = 0;
 #endif
 
 class mutexor {
 public:
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-mutexor ( pthread_mutex_t *m ) : mtx_(m) { pthread_mutex_lock ( mtx_ ); }
-~mutexor () { pthread_mutex_unlock ( mtx_ ); }
+mutexor ( __libcxxabi_mutex_t *m ) : mtx_(m) { __libcxxabi_mutex_lock ( mtx_ ); }
+~mutexor () { __libcxxabi_mutex_unlock ( mtx_ ); }
 #else
 mutexor ( void * ) {}
 ~mutexor () {}
 #endif
 private:
 mutexor ( const mutexor &rhs );
 mutexor & operator = ( const mutexor &rhs );
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-pthread_mutex_t *mtx_;
+__libcxxabi_mutex_t *mtx_;
 #endif
 };
 
Index: src/cxa_guard.cpp
===
--- src/cxa_guard.cpp
+++ src/cxa_guard.cpp
@@ -11,20 +11,18 @@
 
 #include "abort_message.h"
 #include "config.h"
+#include "threading_support.h"
 
-#ifndef _LIBCXXABI_HAS_NO_THREADS
-#  include 
-#endif
 #include 
 
 /*
 This implementation must be careful to not call code external to this file
 which will turn around and try to call __cxa_guard_acquire reentrantly.
 For this reason, the headers of

Re: [PATCH] D24119: [libc++] add linker option "-Wl, -z, defs" in standalone build

2016-09-27 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

In https://reviews.llvm.org/D24119#554234, @mgorny wrote:

> I'm starting to regret that I've committed this. It breaks horribly any 
> pure-LLVM build, i.e. without linking to libgcc_s. It seems that the build 
> system is completely unprepared to link to compiler-rt or libunwind when 
> linking the shared library, and with -DLIBCXX_HAS_GCC_S_LIB=OFF, it fails due 
> to a lot of missing symbols. I am going to revert this until we get the build 
> system working completely.


Doesn't `-DLIBCXXABI_USE_LLVM_UNWINDER=ON` make it possible to build without 
`libgcc_s`? Or is this something else?


Repository:
  rL LLVM

https://reviews.llvm.org/D24119



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24984: [libunwind] Add support for a single-threaded libunwind build

2016-09-27 Thread Asiri Rathnayake via cfe-commits
rmaprath created this revision.
rmaprath added reviewers: jroelofs, compnerd, logan.
rmaprath added a subscriber: cfe-commits.
Herald added subscribers: mgorny, beanz.

The EHABI unwinder is thread-agnostic, SJLJ unwinder and the DWARF unwinder 
have a couple of `pthread` dependencies.

This patch makes it possible to build the whole of `libunwind` for a 
single-threaded environment.

https://reviews.llvm.org/D24984

Files:
  CMakeLists.txt
  src/CMakeLists.txt
  src/UnwindCursor.hpp
  src/Unwind_AppleExtras.cpp
  src/config.h

Index: src/config.h
===
--- src/config.h
+++ src/config.h
@@ -85,13 +85,20 @@
   } while (0)
 #define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libunwind: " msg "\n", __VA_ARGS__)
 
+#if defined(_LIBUNWIND_HAS_NO_THREADS)
+  // only used with pthread calls, not needed for the single-threaded builds
+  #define _LIBUNWIND_LOG_NON_ZERO(x)
+#endif
+
 // Macros that define away in non-Debug builds
 #ifdef NDEBUG
   #define _LIBUNWIND_DEBUG_LOG(msg, ...)
   #define _LIBUNWIND_TRACE_API(msg, ...)
   #define _LIBUNWIND_TRACING_UNWINDING 0
   #define _LIBUNWIND_TRACE_UNWINDING(msg, ...)
-  #define _LIBUNWIND_LOG_NON_ZERO(x) x
+  #ifndef _LIBUNWIND_LOG_NON_ZERO
+#define _LIBUNWIND_LOG_NON_ZERO(x) x
+  #endif
 #else
   #ifdef __cplusplus
 extern "C" {
@@ -102,12 +109,14 @@
 }
   #endif
   #define _LIBUNWIND_DEBUG_LOG(msg, ...)  _LIBUNWIND_LOG(msg, __VA_ARGS__)
-  #define _LIBUNWIND_LOG_NON_ZERO(x) \
-do { \
-  int _err = x; \
-  if ( _err != 0 ) \
-_LIBUNWIND_LOG("" #x "=%d in %s", _err, __FUNCTION__); \
- } while (0)
+  #ifndef _LIBUNWIND_LOG_NON_ZERO
+#define _LIBUNWIND_LOG_NON_ZERO(x) \
+  do { \
+int _err = x; \
+if ( _err != 0 ) \
+  _LIBUNWIND_LOG("" #x "=%d in %s", _err, __FUNCTION__); \
+   } while (0)
+  #endif
   #define _LIBUNWIND_TRACE_API(msg, ...) \
 do { \
   if ( logAPIs() ) _LIBUNWIND_LOG(msg, __VA_ARGS__); \
Index: src/Unwind_AppleExtras.cpp
===
--- src/Unwind_AppleExtras.cpp
+++ src/Unwind_AppleExtras.cpp
@@ -185,21 +185,29 @@
 
 #if !defined(FOR_DYLD) && _LIBUNWIND_BUILD_SJLJ_APIS
 
-#include 
+#ifndef _LIBUNWIND_HAS_NO_THREADS
+  #include 
+#else
+  _Unwind_FunctionContext *fc_ = nullptr;
+#endif
 
 // Accessors to get get/set linked list of frames for sjlj based execeptions.
 _LIBUNWIND_HIDDEN
 struct _Unwind_FunctionContext *__Unwind_SjLj_GetTopOfFunctionStack() {
+#ifndef _LIBUNWIND_HAS_NO_THREADS
   return (struct _Unwind_FunctionContext *)
 _pthread_getspecific_direct(__PTK_LIBC_DYLD_Unwind_SjLj_Key);
+#else
+  return fc_;
+#endif
 }
 
 _LIBUNWIND_HIDDEN
 void __Unwind_SjLj_SetTopOfFunctionStack(struct _Unwind_FunctionContext *fc) {
+#ifndef _LIBUNWIND_HAS_NO_THREADS
   _pthread_setspecific_direct(__PTK_LIBC_DYLD_Unwind_SjLj_Key, fc);
+#else
+  fc_ = fc;
+#endif
 }
 #endif
-
-
-
-
Index: src/UnwindCursor.hpp
===
--- src/UnwindCursor.hpp
+++ src/UnwindCursor.hpp
@@ -16,7 +16,9 @@
 #include 
 #include 
 #include 
-#include 
+#ifndef _LIBUNWIND_HAS_NO_THREADS
+  #include 
+#endif
 #include 
 
 #ifdef __APPLE__
@@ -60,7 +62,9 @@
 
   // These fields are all static to avoid needing an initializer.
   // There is only one instance of this class per process.
+#ifndef _LIBUNWIND_HAS_NO_THREADS
   static pthread_rwlock_t _lock;
+#endif
 #ifdef __APPLE__
   static void dyldUnloadHook(const struct mach_header *mh, intptr_t slide);
   static bool _registeredForDyldUnloads;
@@ -87,8 +91,10 @@
 template 
 typename DwarfFDECache::entry DwarfFDECache::_initialBuffer[64];
 
+#ifndef _LIBUNWIND_HAS_NO_THREADS
 template 
 pthread_rwlock_t DwarfFDECache::_lock = PTHREAD_RWLOCK_INITIALIZER;
+#endif
 
 #ifdef __APPLE__
 template 
Index: src/CMakeLists.txt
===
--- src/CMakeLists.txt
+++ src/CMakeLists.txt
@@ -53,7 +53,9 @@
 set(libraries ${LIBUNWINDCXX_ABI_LIBRARIES})
 append_if(libraries LIBUNWIND_HAS_C_LIB c)
 append_if(libraries LIBUNWIND_HAS_DL_LIB dl)
-append_if(libraries LIBUNWIND_HAS_PTHREAD_LIB pthread)
+if (LIBUNWIND_ENABLE_THREADS)
+  append_if(libraries LIBUNWIND_HAS_PTHREAD_LIB pthread)
+endif()
 
 # Setup flags.
 append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_FPIC_FLAG -fPIC)
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -107,6 +107,7 @@
 option(LIBUNWIND_ENABLE_STATIC "Build libunwind as a static library." ON)
 option(LIBUNWIND_ENABLE_CROSS_UNWINDING "Enable cross-platform unwinding support." OFF)
 option(LIBUNWIND_ENABLE_ARM_WMMX "Enable unwinding support for ARM WMMX registers." OFF)
+option(LIBUNWIND_ENABLE_THREADS "Build libunwind with threading support." ON)
 

Re: [PATCH] D25008: [libcxx] Include unwinder library in the linker script

2016-09-28 Thread Asiri Rathnayake via cfe-commits
rmaprath added a subscriber: rmaprath.
rmaprath added a comment.

The patch generally makes sense to me.

I wonder if the test configuration can also benefit from this; 
`test/libcxx/test/target_info.py` manually updates the link line to use 
`-lgcc_s` or `-lunwind` depending on how the build is configured. Presumably, 
this workaround will no longer be needed if the linker script does that for us?

(Note:- `-lgcc_s` is linked twice there to satisfy some weird dependency, it's 
not a mistake)


https://reviews.llvm.org/D25008



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] r282575 - [libunwind] Add support for a single-threaded libunwind build

2016-09-28 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Wed Sep 28 05:57:15 2016
New Revision: 282575

URL: http://llvm.org/viewvc/llvm-project?rev=282575&view=rev
Log:
[libunwind] Add support for a single-threaded libunwind build

The EHABI unwinder is thread-agnostic, SJLJ unwinder and the DWARF unwinder have
a couple of pthread dependencies.

This patch makes it possible to build the whole of libunwind for a
single-threaded environment.

Reviewers: compnerd

Differential revision: https://reviews.llvm.org/D24984

Modified:
libunwind/trunk/CMakeLists.txt
libunwind/trunk/src/CMakeLists.txt
libunwind/trunk/src/UnwindCursor.hpp
libunwind/trunk/src/Unwind_AppleExtras.cpp
libunwind/trunk/src/config.h

Modified: libunwind/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/CMakeLists.txt?rev=282575&r1=282574&r2=282575&view=diff
==
--- libunwind/trunk/CMakeLists.txt (original)
+++ libunwind/trunk/CMakeLists.txt Wed Sep 28 05:57:15 2016
@@ -107,6 +107,7 @@ option(LIBUNWIND_ENABLE_SHARED "Build li
 option(LIBUNWIND_ENABLE_STATIC "Build libunwind as a static library." ON)
 option(LIBUNWIND_ENABLE_CROSS_UNWINDING "Enable cross-platform unwinding 
support." OFF)
 option(LIBUNWIND_ENABLE_ARM_WMMX "Enable unwinding support for ARM WMMX 
registers." OFF)
+option(LIBUNWIND_ENABLE_THREADS "Build libunwind with threading support." ON)
 
 set(LIBUNWIND_TARGET_TRIPLE "" CACHE STRING "Target triple for cross 
compiling.")
 set(LIBUNWIND_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
@@ -242,6 +243,11 @@ if (NOT LIBUNWIND_ENABLE_CROSS_UNWINDING
   list(APPEND LIBUNWIND_COMPILE_FLAGS -D_LIBUNWIND_IS_NATIVE_ONLY)
 endif()
 
+# Threading-support
+if (NOT LIBUNWIND_ENABLE_THREADS)
+  list(APPEND LIBUNWIND_COMPILE_FLAGS -D_LIBUNWIND_HAS_NO_THREADS)
+endif()
+
 # ARM WMMX register support
 if (LIBUNWIND_ENABLE_ARM_WMMX)
   # __ARM_WMMX is a compiler pre-define (as per the ACLE 2.0). Clang does not

Modified: libunwind/trunk/src/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/CMakeLists.txt?rev=282575&r1=282574&r2=282575&view=diff
==
--- libunwind/trunk/src/CMakeLists.txt (original)
+++ libunwind/trunk/src/CMakeLists.txt Wed Sep 28 05:57:15 2016
@@ -53,7 +53,9 @@ set(LIBUNWIND_SOURCES
 set(libraries ${LIBUNWINDCXX_ABI_LIBRARIES})
 append_if(libraries LIBUNWIND_HAS_C_LIB c)
 append_if(libraries LIBUNWIND_HAS_DL_LIB dl)
-append_if(libraries LIBUNWIND_HAS_PTHREAD_LIB pthread)
+if (LIBUNWIND_ENABLE_THREADS)
+  append_if(libraries LIBUNWIND_HAS_PTHREAD_LIB pthread)
+endif()
 
 # Setup flags.
 append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_FPIC_FLAG -fPIC)

Modified: libunwind/trunk/src/UnwindCursor.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/UnwindCursor.hpp?rev=282575&r1=282574&r2=282575&view=diff
==
--- libunwind/trunk/src/UnwindCursor.hpp (original)
+++ libunwind/trunk/src/UnwindCursor.hpp Wed Sep 28 05:57:15 2016
@@ -16,7 +16,9 @@
 #include 
 #include 
 #include 
-#include 
+#ifndef _LIBUNWIND_HAS_NO_THREADS
+  #include 
+#endif
 #include 
 
 #ifdef __APPLE__
@@ -60,7 +62,9 @@ private:
 
   // These fields are all static to avoid needing an initializer.
   // There is only one instance of this class per process.
+#ifndef _LIBUNWIND_HAS_NO_THREADS
   static pthread_rwlock_t _lock;
+#endif
 #ifdef __APPLE__
   static void dyldUnloadHook(const struct mach_header *mh, intptr_t slide);
   static bool _registeredForDyldUnloads;
@@ -87,8 +91,10 @@ DwarfFDECache::_bufferEnd = &_initial
 template 
 typename DwarfFDECache::entry DwarfFDECache::_initialBuffer[64];
 
+#ifndef _LIBUNWIND_HAS_NO_THREADS
 template 
 pthread_rwlock_t DwarfFDECache::_lock = PTHREAD_RWLOCK_INITIALIZER;
+#endif
 
 #ifdef __APPLE__
 template 

Modified: libunwind/trunk/src/Unwind_AppleExtras.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/Unwind_AppleExtras.cpp?rev=282575&r1=282574&r2=282575&view=diff
==
--- libunwind/trunk/src/Unwind_AppleExtras.cpp (original)
+++ libunwind/trunk/src/Unwind_AppleExtras.cpp Wed Sep 28 05:57:15 2016
@@ -185,21 +185,29 @@ bool checkKeyMgrRegisteredFDEs(uintptr_t
 
 #if !defined(FOR_DYLD) && _LIBUNWIND_BUILD_SJLJ_APIS
 
-#include 
+#ifndef _LIBUNWIND_HAS_NO_THREADS
+  #include 
+#else
+  _Unwind_FunctionContext *fc_ = nullptr;
+#endif
 
 // Accessors to get get/set linked list of frames for sjlj based execeptions.
 _LIBUNWIND_HIDDEN
 struct _Unwind_FunctionContext *__Unwind_SjLj_GetTopOfFunctionStack() {
+#ifndef _LIBUNWIND_HAS_NO_THREADS
   return (struct _Unwind_FunctionContext *)
 _pthread_getspecific_direct(__PTK_LIBC_DYLD_Unwind_SjLj_Key);
+#else
+  return fc_;
+#endif
 }
 
 _LIBUNWIND_HIDDEN
 void __Unwind_SjLj_SetTopOfFunctionStack(

Re: [PATCH] D24864: [libcxxabi] Refactor pthread usage into a separate API

2016-09-28 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

@EricWF: Gentle ping.


https://reviews.llvm.org/D24864



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] [Updated, 225 lines] D24864: [libcxxabi] Refactor pthread usage into a separate API

2016-09-30 Thread Asiri Rathnayake via cfe-commits
rmaprath updated this revision to Diff 73007.
rmaprath added a comment.

Updated with the following changes:

- Address review comments from @EricWF and @compnerd regarding using 
`_POSIX_THREADS` for detecting pthread availability. Now the patch is checking 
for `defined(_POSIX_THREADS) && _POSIX_THREADS >= 0` instead of enumerating the 
platforms.
- Fix a missed pthread dependency in `cxa_guard.cpp`. The call to 
`pthread_mach_thread_np` is now replaced with 
`__libcxxabi_thread_get_current_id()`.
- Fix a couple of missing pthread dependencies in `test_exception_storage.cpp` 
(see patch below).

@EricWF: Hope the new changes look OK? I'm going to test this on a Mac before 
committing.

I will also ping https://reviews.llvm.org/D21803 and 
https://reviews.llvm.org/D17815, as they'll be affected by this patch (those 
patches add more pthread calls).


https://reviews.llvm.org/D24864

Files:
  CMakeLists.txt
  src/config.h
  src/cxa_exception.cpp
  src/cxa_exception_storage.cpp
  src/cxa_guard.cpp
  src/fallback_malloc.ipp
  src/threading_support.h
  test/test_exception_storage.pass.cpp
  test/test_fallback_malloc.pass.cpp

Index: test/test_fallback_malloc.pass.cpp
===
--- test/test_fallback_malloc.pass.cpp
+++ test/test_fallback_malloc.pass.cpp
@@ -10,7 +10,7 @@
 #include 
 #include 
 
-#include 
+#include "../src/threading_support.h"
 
 typedef std::deque container;
 
Index: test/test_exception_storage.pass.cpp
===
--- test/test_exception_storage.pass.cpp
+++ test/test_exception_storage.pass.cpp
@@ -12,9 +12,7 @@
 #include 
 #include 
 #include 
-#ifndef _LIBCXXABI_HAS_NO_THREADS
-#  include 
-#endif
+#include "../src/threading_support.h"
 #include 
 
 #include "../src/cxa_exception.hpp"
@@ -40,19 +38,19 @@
 
 #ifndef _LIBCXXABI_HAS_NO_THREADS
 #define NUMTHREADS  10
-size_t  thread_globals [ NUMTHREADS ] = { 0 };
-pthread_t   threads[ NUMTHREADS ];
+size_t thread_globals [ NUMTHREADS ] = { 0 };
+__libcxxabi_thread_t   threads[ NUMTHREADS ];
 #endif
 
 int main ( int argc, char *argv [] ) {
 int retVal = 0;
 
 #ifndef _LIBCXXABI_HAS_NO_THREADS
 //  Make the threads, let them run, and wait for them to finish
 for ( int i = 0; i < NUMTHREADS; ++i )
-pthread_create( threads + i, NULL, thread_code, (void *) (thread_globals + i));
+__libcxxabi_thread_create ( threads + i, thread_code, (void *) (thread_globals + i));
 for ( int i = 0; i < NUMTHREADS; ++i )
-pthread_join ( threads [ i ], NULL );
+__libcxxabi_thread_join ( &threads [ i ] );
 
 for ( int i = 0; i < NUMTHREADS; ++i )
 if ( 0 == thread_globals [ i ] ) {
Index: src/threading_support.h
===
--- /dev/null
+++ src/threading_support.h
@@ -0,0 +1,109 @@
+//=== threading_support.h -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef _LIBCXXABI_THREADING_SUPPORT_H
+#define _LIBCXXABI_THREADING_SUPPORT_H
+
+#include "__cxxabi_config.h"
+#include "config.h"
+
+#ifndef _LIBCXXABI_HAS_NO_THREADS
+
+#if defined(_LIBCXXABI_USE_THREAD_API_PTHREAD)
+#include 
+
+#define _LIBCXXABI_THREAD_ABI_VISIBILITY inline _LIBCXXABI_INLINE_VISIBILITY
+
+// Mutex
+typedef pthread_mutex_t __libcxxabi_mutex_t;
+#define _LIBCXXABI_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_mutex_lock(__libcxxabi_mutex_t *mutex) {
+  return pthread_mutex_lock(mutex);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_mutex_unlock(__libcxxabi_mutex_t *mutex) {
+  return pthread_mutex_unlock(mutex);
+}
+
+// Condition variable
+typedef pthread_cond_t __libcxxabi_condvar_t;
+#define _LIBCXXABI_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_condvar_wait(__libcxxabi_condvar_t *cv,
+ __libcxxabi_mutex_t *mutex) {
+  return pthread_cond_wait(cv, mutex);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_condvar_broadcast(__libcxxabi_condvar_t *cv) {
+  return pthread_cond_broadcast(cv);
+}
+
+// Execute once
+typedef pthread_once_t __libcxxabi_exec_once_flag;
+#define _LIBCXXABI_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_execute_once(__libcxxabi_exec_once_flag *flag,
+ void (*init_routine)(void)) {
+  return pthread_once(flag, init_routine);
+}
+
+// Thread
+typedef pthread_t __libcxxabi_thread_id;
+typedef pthread_t __libcxxabi_thread_t;
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+__libcxxabi_thread_id __libcxxabi_thread_get_cur

[PATCH] [Updated] D21803: [libcxxabi] Provide a fallback __cxa_thread_atexit() implementation

2016-09-30 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

@tavianator: I'm about to commit https://reviews.llvm.org/D24864, which will 
affect this patch (indirectly). https://reviews.llvm.org/D24864 basically 
refactors all pthread dependencies behind a separate API. It would be pretty 
straightforward for you to update this patch though, just replacing pthread 
calls with ones in `thread_support.h` (perhaps adding anything missing).

Hope you don't mind me going first? If you are going to commit this soon, I can 
hold off https://reviews.llvm.org/D24864. Let me know.

Cheers,

/ Asiri


https://reviews.llvm.org/D21803



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] [Updated] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-09-30 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

@ikudrin: Looks like you've reverted this soon after. I'm just about to commit 
https://reviews.llvm.org/D24864, which will affect this slightly. 
https://reviews.llvm.org/D24864 basically refactors all pthread dependencies 
behind a separate API. It would be pretty straightforward for you to update 
this patch though, just replacing pthread calls with ones in thread_support.h 
(perhaps adding anything missing).

Hope you don't mind me going first? If you are going to commit this soon, I can 
hold off https://reviews.llvm.org/D24864. Let me know.

Cheers,

/ Asiri


Repository:
  rL LLVM

https://reviews.llvm.org/D17815



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] [Commented On] D24864: [libcxxabi] Refactor pthread usage into a separate API

2016-09-30 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

In https://reviews.llvm.org/D24864#556845, @rmaprath wrote:

> I'm going to test this on a Mac before committing.


Good call that was, wouldn't have compiled there. Attaching updated patch soon.


https://reviews.llvm.org/D24864



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] [Updated, 223 lines] D24864: [libcxxabi] Refactor pthread usage into a separate API

2016-09-30 Thread Asiri Rathnayake via cfe-commits
rmaprath updated this revision to Diff 73033.
rmaprath added a comment.

`pthread_mach_thread_np` is Mac specific. I've introduced a Mac-only 
`__libcxxabi_thread_get_port()` API call to sort this out (didn't think it 
would be nice to leave a pthread call even if it is Mac specific).

I can revisit this if there is a better approach. Will commit now.


https://reviews.llvm.org/D24864

Files:
  CMakeLists.txt
  src/config.h
  src/cxa_exception.cpp
  src/cxa_exception_storage.cpp
  src/cxa_guard.cpp
  src/fallback_malloc.ipp
  src/threading_support.h
  test/test_exception_storage.pass.cpp
  test/test_fallback_malloc.pass.cpp

Index: test/test_fallback_malloc.pass.cpp
===
--- test/test_fallback_malloc.pass.cpp
+++ test/test_fallback_malloc.pass.cpp
@@ -10,7 +10,7 @@
 #include 
 #include 
 
-#include 
+#include "../src/threading_support.h"
 
 typedef std::deque container;
 
Index: test/test_exception_storage.pass.cpp
===
--- test/test_exception_storage.pass.cpp
+++ test/test_exception_storage.pass.cpp
@@ -12,9 +12,7 @@
 #include 
 #include 
 #include 
-#ifndef _LIBCXXABI_HAS_NO_THREADS
-#  include 
-#endif
+#include "../src/threading_support.h"
 #include 
 
 #include "../src/cxa_exception.hpp"
@@ -40,19 +38,19 @@
 
 #ifndef _LIBCXXABI_HAS_NO_THREADS
 #define NUMTHREADS  10
-size_t  thread_globals [ NUMTHREADS ] = { 0 };
-pthread_t   threads[ NUMTHREADS ];
+size_t thread_globals [ NUMTHREADS ] = { 0 };
+__libcxxabi_thread_t   threads[ NUMTHREADS ];
 #endif
 
 int main ( int argc, char *argv [] ) {
 int retVal = 0;
 
 #ifndef _LIBCXXABI_HAS_NO_THREADS
 //  Make the threads, let them run, and wait for them to finish
 for ( int i = 0; i < NUMTHREADS; ++i )
-pthread_create( threads + i, NULL, thread_code, (void *) (thread_globals + i));
+__libcxxabi_thread_create ( threads + i, thread_code, (void *) (thread_globals + i));
 for ( int i = 0; i < NUMTHREADS; ++i )
-pthread_join ( threads [ i ], NULL );
+__libcxxabi_thread_join ( &threads [ i ] );
 
 for ( int i = 0; i < NUMTHREADS; ++i )
 if ( 0 == thread_globals [ i ] ) {
Index: src/threading_support.h
===
--- /dev/null
+++ src/threading_support.h
@@ -0,0 +1,107 @@
+//=== threading_support.h -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef _LIBCXXABI_THREADING_SUPPORT_H
+#define _LIBCXXABI_THREADING_SUPPORT_H
+
+#include "__cxxabi_config.h"
+#include "config.h"
+
+#ifndef _LIBCXXABI_HAS_NO_THREADS
+
+#if defined(_LIBCXXABI_USE_THREAD_API_PTHREAD)
+#include 
+
+#define _LIBCXXABI_THREAD_ABI_VISIBILITY inline _LIBCXXABI_INLINE_VISIBILITY
+
+// Mutex
+typedef pthread_mutex_t __libcxxabi_mutex_t;
+#define _LIBCXXABI_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_mutex_lock(__libcxxabi_mutex_t *mutex) {
+  return pthread_mutex_lock(mutex);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_mutex_unlock(__libcxxabi_mutex_t *mutex) {
+  return pthread_mutex_unlock(mutex);
+}
+
+// Condition variable
+typedef pthread_cond_t __libcxxabi_condvar_t;
+#define _LIBCXXABI_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_condvar_wait(__libcxxabi_condvar_t *cv,
+ __libcxxabi_mutex_t *mutex) {
+  return pthread_cond_wait(cv, mutex);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_condvar_broadcast(__libcxxabi_condvar_t *cv) {
+  return pthread_cond_broadcast(cv);
+}
+
+// Execute once
+typedef pthread_once_t __libcxxabi_exec_once_flag;
+#define _LIBCXXABI_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_execute_once(__libcxxabi_exec_once_flag *flag,
+ void (*init_routine)(void)) {
+  return pthread_once(flag, init_routine);
+}
+
+// Thread id
+#if defined(__APPLE__) && !defined(__arm__)
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+mach_port_t __libcxxabi_thread_get_port()
+{
+return pthread_mach_thread_np(pthread_self());
+}
+#endif
+
+// Thread
+typedef pthread_t __libcxxabi_thread_t;
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_thread_create(__libcxxabi_thread_t* __t,
+   void* (*__func)(void*), void* __arg)
+{
+return pthread_create(__t, 0, __func, __arg);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_thread_join(__libcxxabi_thread_t* __t)
+{
+return pthread_join(*__t, 0);
+}
+
+// TLS
+typedef pthread_key_t __libcxxabi_tls_key;
+
+_LIBCXXABI_THREAD_ABI_VIS

[PATCH] D24864: [libcxxabi] Refactor pthread usage into a separate API

2016-09-30 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

Sigh. I've bumped into some downstream problems. Will commit as soon as I've 
verified these problems are not related to the patch.


https://reviews.llvm.org/D24864



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24082: [CMake] Fix libc++abi arm build w/o libunwind.

2016-10-04 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

LGTM too.

@EricWF or @mclow.lists need to approve.


https://reviews.llvm.org/D24082



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24562: [libcxx] Recover no-exceptions XFAILs

2016-10-04 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

In https://reviews.llvm.org/D24562#561442, @Eugene.Zelenko wrote:

> Looks like patch was not committed.


Need to replicate this to as many tests as possible (~150). I was hoping to do 
all that and upload another diff for a final review, couldn't get to it I'm 
afraid. Hope to do this very very soon.

Sorry for the delay.

/ Asiri


https://reviews.llvm.org/D24562



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24562: [libcxx] Recover no-exceptions XFAILs

2016-10-05 Thread Asiri Rathnayake via cfe-commits
rmaprath updated this revision to Diff 73661.
rmaprath added a comment.

First batch of XFAIL fixes.

I've changed some XFAILs to UNSUPPORTED where the test is all about exception 
handling. In other cases, I've used the test macro TEST_HAS_NO_EXCEPTIONS to 
conditionally exclude those parts that test
exception handling behaviour.

@EricWF: I can create a separate review if necessary, thought I'll re-use this 
review for the first batch, will be opening new reviews for the follow-ups.

/ Asiri


https://reviews.llvm.org/D24562

Files:
  test/std/re/re.alg/re.alg.search/grep.pass.cpp
  test/std/re/re.regex/re.regex.assign/assign.pass.cpp
  test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
  test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp
  test/std/thread/futures/futures.async/async.pass.cpp
  test/std/thread/futures/futures.promise/dtor.pass.cpp
  test/std/thread/futures/futures.promise/get_future.pass.cpp
  test/std/thread/futures/futures.promise/move_ctor.pass.cpp
  test/std/thread/futures/futures.promise/set_exception.pass.cpp
  test/std/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp
  test/std/thread/futures/futures.promise/set_lvalue.pass.cpp
  test/std/thread/futures/futures.promise/set_value_const.pass.cpp
  test/std/thread/futures/futures.promise/set_value_void.pass.cpp
  test/std/thread/futures/futures.shared_future/get.pass.cpp
  test/std/thread/futures/futures.task/futures.task.members/dtor.pass.cpp
  test/std/thread/futures/futures.task/futures.task.members/get_future.pass.cpp
  
test/std/thread/futures/futures.task/futures.task.members/make_ready_at_thread_exit.pass.cpp
  test/std/thread/futures/futures.task/futures.task.members/operator.pass.cpp
  test/std/thread/futures/futures.task/futures.task.members/reset.pass.cpp
  test/std/thread/futures/futures.unique_future/get.pass.cpp
  
test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp

Index: test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
===
--- test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
+++ test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 //
-// XFAIL: libcpp-no-exceptions
 // UNSUPPORTED: libcpp-has-no-threads
 
 // 
@@ -32,9 +31,11 @@
 
 void* operator new(std::size_t s) throw(std::bad_alloc)
 {
+#ifndef TEST_HAS_NO_EXCEPTIONS
 if (throw_one == 0)
 throw std::bad_alloc();
 --throw_one;
+#endif
 ++outstanding_new;
 void* ret = std::malloc(s);
 if (!ret) std::abort(); // placate MSVC's unchecked malloc warning
@@ -118,6 +119,7 @@
 //  3 Finally check that a thread runs successfully if we throw after 'N+1'
 //allocations.
 void test_throwing_new_during_thread_creation() {
+#ifndef TEST_HAS_NO_EXCEPTIONS
 throw_one = 0xFFF;
 {
 std::thread t(f);
@@ -142,6 +144,7 @@
 }
 f_run = false;
 throw_one = 0xFFF;
+#endif
 }
 
 int main()
@@ -162,6 +165,7 @@
 assert(G::op_run);
 }
 G::op_run = false;
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 try
 {
@@ -178,6 +182,7 @@
 assert(!G::op_run);
 }
 }
+#endif
 #if TEST_STD_VER >= 11
 {
 assert(G::n_alive == 0);
Index: test/std/thread/futures/futures.unique_future/get.pass.cpp
===
--- test/std/thread/futures/futures.unique_future/get.pass.cpp
+++ test/std/thread/futures/futures.unique_future/get.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 //
-// XFAIL: libcpp-no-exceptions
 // UNSUPPORTED: libcpp-has-no-threads
 // UNSUPPORTED: c++98, c++03
 
@@ -22,6 +21,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 void func1(std::promise p)
 {
 std::this_thread::sleep_for(std::chrono::milliseconds(500));
@@ -73,6 +74,7 @@
 assert(f.get() == 3);
 assert(!f.valid());
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 std::promise p;
 std::future f = p.get_future();
@@ -89,6 +91,7 @@
 }
 assert(!f.valid());
 }
+#endif
 }
 {
 typedef int& T;
@@ -100,6 +103,7 @@
 assert(f.get() == 5);
 assert(!f.valid());
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 std::promise p;
 std::future f = p.get_future();
@@ -116,6 +120,7 @@
 }
 assert(!f.valid());
 }
+#endif
 }
 {
 typedef void T;
@@ -127,6 +132,7 @@
 f.get();
 assert(!f.valid());
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 std::promise p;
 std::future f = p.get_future();
@@ -143,5 +149,6 @@
 }

[PATCH] D24562: [libcxx] Recover no-exceptions XFAILs

2016-10-06 Thread Asiri Rathnayake via cfe-commits
rmaprath updated this revision to Diff 73759.
rmaprath added a comment.

Final patch to be committed, with all the remaining comments addressed.


https://reviews.llvm.org/D24562

Files:
  test/std/re/re.alg/re.alg.search/grep.pass.cpp
  test/std/re/re.regex/re.regex.assign/assign.pass.cpp
  test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
  test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp
  test/std/thread/futures/futures.async/async.pass.cpp
  test/std/thread/futures/futures.promise/dtor.pass.cpp
  test/std/thread/futures/futures.promise/get_future.pass.cpp
  test/std/thread/futures/futures.promise/move_ctor.pass.cpp
  test/std/thread/futures/futures.promise/set_exception.pass.cpp
  test/std/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp
  test/std/thread/futures/futures.promise/set_lvalue.pass.cpp
  test/std/thread/futures/futures.promise/set_value_const.pass.cpp
  test/std/thread/futures/futures.promise/set_value_void.pass.cpp
  test/std/thread/futures/futures.shared_future/get.pass.cpp
  test/std/thread/futures/futures.task/futures.task.members/dtor.pass.cpp
  test/std/thread/futures/futures.task/futures.task.members/get_future.pass.cpp
  
test/std/thread/futures/futures.task/futures.task.members/make_ready_at_thread_exit.pass.cpp
  test/std/thread/futures/futures.task/futures.task.members/operator.pass.cpp
  test/std/thread/futures/futures.task/futures.task.members/reset.pass.cpp
  test/std/thread/futures/futures.unique_future/get.pass.cpp
  
test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp

Index: test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
===
--- test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
+++ test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 //
-// XFAIL: libcpp-no-exceptions
 // UNSUPPORTED: libcpp-has-no-threads
 
 // 
@@ -33,7 +32,7 @@
 void* operator new(std::size_t s) throw(std::bad_alloc)
 {
 if (throw_one == 0)
-throw std::bad_alloc();
+TEST_THROW(std::bad_alloc());
 --throw_one;
 ++outstanding_new;
 void* ret = std::malloc(s);
@@ -118,6 +117,7 @@
 //  3 Finally check that a thread runs successfully if we throw after 'N+1'
 //allocations.
 void test_throwing_new_during_thread_creation() {
+#ifndef TEST_HAS_NO_EXCEPTIONS
 throw_one = 0xFFF;
 {
 std::thread t(f);
@@ -142,6 +142,7 @@
 }
 f_run = false;
 throw_one = 0xFFF;
+#endif
 }
 
 int main()
@@ -162,6 +163,7 @@
 assert(G::op_run);
 }
 G::op_run = false;
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 try
 {
@@ -178,6 +180,7 @@
 assert(!G::op_run);
 }
 }
+#endif
 #if TEST_STD_VER >= 11
 {
 assert(G::n_alive == 0);
Index: test/std/thread/futures/futures.unique_future/get.pass.cpp
===
--- test/std/thread/futures/futures.unique_future/get.pass.cpp
+++ test/std/thread/futures/futures.unique_future/get.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 //
-// XFAIL: libcpp-no-exceptions
 // UNSUPPORTED: libcpp-has-no-threads
 // UNSUPPORTED: c++98, c++03
 
@@ -22,6 +21,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 void func1(std::promise p)
 {
 std::this_thread::sleep_for(std::chrono::milliseconds(500));
@@ -73,6 +74,7 @@
 assert(f.get() == 3);
 assert(!f.valid());
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 std::promise p;
 std::future f = p.get_future();
@@ -89,6 +91,7 @@
 }
 assert(!f.valid());
 }
+#endif
 }
 {
 typedef int& T;
@@ -100,6 +103,7 @@
 assert(f.get() == 5);
 assert(!f.valid());
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 std::promise p;
 std::future f = p.get_future();
@@ -116,6 +120,7 @@
 }
 assert(!f.valid());
 }
+#endif
 }
 {
 typedef void T;
@@ -127,6 +132,7 @@
 f.get();
 assert(!f.valid());
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 std::promise p;
 std::future f = p.get_future();
@@ -143,5 +149,6 @@
 }
 assert(!f.valid());
 }
+#endif
 }
 }
Index: test/std/thread/futures/futures.task/futures.task.members/reset.pass.cpp
===
--- test/std/thread/futures/futures.task/futures.task.members/reset.pass.cpp
+++ test/std/thread/futures/futures.task/futures.task.members/reset.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===

[libcxx] r283441 - [libcxx] Recover no-exceptions XFAILs - I

2016-10-06 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Thu Oct  6 06:15:41 2016
New Revision: 283441

URL: http://llvm.org/viewvc/llvm-project?rev=283441&view=rev
Log:
[libcxx] Recover no-exceptions XFAILs - I

First batch of changes to get some of these XFAILs working in the
no-exceptions libc++ variant.

Changed some XFAILs to UNSUPPORTED where the test is all about exception
handling. In other cases, used the test macros TEST_THROW and
TEST_HAS_NO_EXCEPTIONS to conditionally exclude those parts of the test
that concerns exception handling behaviour.

Reviewers: EricWF, mclow.lists

Differential revision: https://reviews.llvm.org/D24562

Modified:
libcxx/trunk/test/std/re/re.alg/re.alg.search/grep.pass.cpp
libcxx/trunk/test/std/re/re.regex/re.regex.assign/assign.pass.cpp
libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp
libcxx/trunk/test/std/thread/futures/futures.async/async.pass.cpp
libcxx/trunk/test/std/thread/futures/futures.promise/dtor.pass.cpp
libcxx/trunk/test/std/thread/futures/futures.promise/get_future.pass.cpp
libcxx/trunk/test/std/thread/futures/futures.promise/move_ctor.pass.cpp
libcxx/trunk/test/std/thread/futures/futures.promise/set_exception.pass.cpp

libcxx/trunk/test/std/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp
libcxx/trunk/test/std/thread/futures/futures.promise/set_lvalue.pass.cpp

libcxx/trunk/test/std/thread/futures/futures.promise/set_value_const.pass.cpp
libcxx/trunk/test/std/thread/futures/futures.promise/set_value_void.pass.cpp
libcxx/trunk/test/std/thread/futures/futures.shared_future/get.pass.cpp

libcxx/trunk/test/std/thread/futures/futures.task/futures.task.members/dtor.pass.cpp

libcxx/trunk/test/std/thread/futures/futures.task/futures.task.members/get_future.pass.cpp

libcxx/trunk/test/std/thread/futures/futures.task/futures.task.members/make_ready_at_thread_exit.pass.cpp

libcxx/trunk/test/std/thread/futures/futures.task/futures.task.members/operator.pass.cpp

libcxx/trunk/test/std/thread/futures/futures.task/futures.task.members/reset.pass.cpp
libcxx/trunk/test/std/thread/futures/futures.unique_future/get.pass.cpp

libcxx/trunk/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp

Modified: libcxx/trunk/test/std/re/re.alg/re.alg.search/grep.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.alg/re.alg.search/grep.pass.cpp?rev=283441&r1=283440&r2=283441&view=diff
==
--- libcxx/trunk/test/std/re/re.alg/re.alg.search/grep.pass.cpp (original)
+++ libcxx/trunk/test/std/re/re.alg/re.alg.search/grep.pass.cpp Thu Oct  6 
06:15:41 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // template 
@@ -25,6 +24,7 @@
 
 extern "C" void LLVMFuzzerTestOneInput(const char *data)
 {
+#ifndef TEST_HAS_NO_EXCEPTIONS
 size_t size = strlen(data);
 if (size > 0)
 {
@@ -37,6 +37,7 @@ extern "C" void LLVMFuzzerTestOneInput(c
 }
 catch (std::regex_error &) {}
 }
+#endif
 }
 
 

Modified: libcxx/trunk/test/std/re/re.regex/re.regex.assign/assign.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.regex/re.regex.assign/assign.pass.cpp?rev=283441&r1=283440&r2=283441&view=diff
==
--- libcxx/trunk/test/std/re/re.regex/re.regex.assign/assign.pass.cpp (original)
+++ libcxx/trunk/test/std/re/re.regex/re.regex.assign/assign.pass.cpp Thu Oct  
6 06:15:41 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // template > class 
basic_regex;
@@ -27,6 +26,7 @@ int main()
 assert(r2.mark_count() == 2);
 assert(std::regex_search("ab", r2));
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 bool caught = false;
 try { r2.assign("(def", std::regex::extended); }
 catch(std::regex_error &) { caught = true; }
@@ -34,4 +34,5 @@ int main()
 assert(r2.flags() == std::regex::ECMAScript);
 assert(r2.mark_count() == 2);
 assert(std::regex_search("ab", r2));
+#endif
 }

Modified: 
libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp?rev=283441&r1=283440&r2=283441&view=diff
==
--- libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp 
(original)
+++ libcxx/trunk/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp 
Thu Oct  6 06:15:41 2016
@@ -7,7 +7,7 @@
 //
 
//===--===//
 
-// XFA

[PATCH] D24562: [libcxx] Recover no-exceptions XFAILs

2016-10-06 Thread Asiri Rathnayake via cfe-commits
rmaprath closed this revision.
rmaprath added a comment.

Committed as r283441.

Thanks!


https://reviews.llvm.org/D24562



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25361: [libcxx] Add the missing limits.h header

2016-10-07 Thread Asiri Rathnayake via cfe-commits
rmaprath created this revision.
rmaprath added reviewers: EricWF, mclow.lists, rsmith.
rmaprath added a subscriber: cfe-commits.

The implementation of [depr.c.headers] in https://reviews.llvm.org/D12747 
introduced the necessary
C headers into libc++. This patch adds one more missing headers: limits.h

We spotted this due to a failing C++03 test [limits_h.pass.cpp] in our libc++
configuration; when the limits.h header is included from a C++ program, it now
bypassed the __config header and went directly into the underlying C library's
limits.h header, which is problematic for us because we use __config header to
configure the underlying C library's behaviour when used from a C++ context.


https://reviews.llvm.org/D25361

Files:
  include/limits.h


Index: include/limits.h
===
--- /dev/null
+++ include/limits.h
@@ -0,0 +1,49 @@
+// -*- C++ -*-
+//===--- limits.h 
-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef _LIBCPP_LIMITS_H
+#define _LIBCPP_LIMITS_H
+
+/*
+limits.h synopsis
+
+Macros:
+
+CHAR_BIT
+SCHAR_MIN
+SCHAR_MAX
+UCHAR_MAX
+CHAR_MIN
+CHAR_MAX
+MB_LEN_MAX
+SHRT_MIN
+SHRT_MAX
+USHRT_MAX
+INT_MIN
+INT_MAX
+UINT_MAX
+LONG_MIN
+LONG_MAX
+ULONG_MAX
+LLONG_MIN   // C99
+LLONG_MAX   // C99
+ULLONG_MAX  // C99
+
+*/
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+#include_next 
+
+#endif  // _LIBCPP_LIMITS_H


Index: include/limits.h
===
--- /dev/null
+++ include/limits.h
@@ -0,0 +1,49 @@
+// -*- C++ -*-
+//===--- limits.h -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef _LIBCPP_LIMITS_H
+#define _LIBCPP_LIMITS_H
+
+/*
+limits.h synopsis
+
+Macros:
+
+CHAR_BIT
+SCHAR_MIN
+SCHAR_MAX
+UCHAR_MAX
+CHAR_MIN
+CHAR_MAX
+MB_LEN_MAX
+SHRT_MIN
+SHRT_MAX
+USHRT_MAX
+INT_MIN
+INT_MAX
+UINT_MAX
+LONG_MIN
+LONG_MAX
+ULONG_MAX
+LLONG_MIN   // C99
+LLONG_MAX   // C99
+ULLONG_MAX  // C99
+
+*/
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+#include_next 
+
+#endif  // _LIBCPP_LIMITS_H
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r283726 - [libcxx] Add the missing limits.h header

2016-10-10 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Mon Oct 10 03:38:51 2016
New Revision: 283726

URL: http://llvm.org/viewvc/llvm-project?rev=283726&view=rev
Log:
[libcxx] Add the missing limits.h header

The implementation of [depr.c.headers] in D12747 introduced the necessary
C headers into libc++. This patch adds one more missing headers: limits.h

We spotted this due to a failing C++03 test [limits_h.pass.cpp] in our libc++
configuration; when the limits.h header is included from a C++ program, it now
bypassed the __config header and went directly into the underlying C library's
limits.h header, which is problematic for us because we use __config header to
configure the underlying C library's behaviour when used from a C++ context.

Reviewers: mclow.lists, rsmith

Differential revision: https://reviews.llvm.org/D25361

Added:
libcxx/trunk/include/limits.h

Added: libcxx/trunk/include/limits.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/limits.h?rev=283726&view=auto
==
--- libcxx/trunk/include/limits.h (added)
+++ libcxx/trunk/include/limits.h Mon Oct 10 03:38:51 2016
@@ -0,0 +1,49 @@
+// -*- C++ -*-
+//===--- limits.h 
-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef _LIBCPP_LIMITS_H
+#define _LIBCPP_LIMITS_H
+
+/*
+limits.h synopsis
+
+Macros:
+
+CHAR_BIT
+SCHAR_MIN
+SCHAR_MAX
+UCHAR_MAX
+CHAR_MIN
+CHAR_MAX
+MB_LEN_MAX
+SHRT_MIN
+SHRT_MAX
+USHRT_MAX
+INT_MIN
+INT_MAX
+UINT_MAX
+LONG_MIN
+LONG_MAX
+ULONG_MAX
+LLONG_MIN   // C99
+LLONG_MAX   // C99
+ULLONG_MAX  // C99
+
+*/
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+#include_next 
+
+#endif  // _LIBCPP_LIMITS_H


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25361: [libcxx] Add the missing limits.h header

2016-10-10 Thread Asiri Rathnayake via cfe-commits
rmaprath closed this revision.
rmaprath added a comment.

Thanks.

Committed as r283726.


https://reviews.llvm.org/D25361



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r283762 - [libcxx] Fix gcc build.

2016-10-10 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Mon Oct 10 10:56:01 2016
New Revision: 283762

URL: http://llvm.org/viewvc/llvm-project?rev=283762&view=rev
Log:
[libcxx] Fix gcc build.

Attempt to fix a horrible gcc include order problem.

Modified:
libcxx/trunk/include/limits.h

Modified: libcxx/trunk/include/limits.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/limits.h?rev=283762&r1=283761&r2=283762&view=diff
==
--- libcxx/trunk/include/limits.h (original)
+++ libcxx/trunk/include/limits.h Mon Oct 10 10:56:01 2016
@@ -44,6 +44,22 @@ Macros:
 #pragma GCC system_header
 #endif
 
+#ifndef __GNUC__
 #include_next 
+#else
+// GCC header limits.h recursively includes itself through another header 
called
+// syslimits.h for some reason. This setup breaks down if we directly
+// #include_next GCC's limits.h (reasons not entirely clear to me). Therefore,
+// we manually re-create the necessary include sequence below:
+
+// Get the system limits.h defines (force recurse into the next level)
+#define _GCC_LIMITS_H_
+#define _GCC_NEXT_LIMITS_H
+#include_next 
+
+// Get the ISO C defines
+#undef _GCC_LIMITS_H_
+#include_next 
+#endif // __GNUC__
 
 #endif  // _LIBCPP_LIMITS_H


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25468: [libcxx] Do not declare the thread api when __external_threading is present

2016-10-11 Thread Asiri Rathnayake via cfe-commits
rmaprath created this revision.
rmaprath added a reviewer: EricWF.
rmaprath added a subscriber: cfe-commits.

This fixes a small omission where even when `__external_threading` is provided, 
we attempt to declare a pthread based threading API. Instead, we should leave 
out everything for the `__external_threading` header to take care of.

The `__threading_support` header provides a proof-of-concept externally 
threaded `libc++` variant when `_LIBCPP_HAS_THREAD_API_EXTERNAL` is defined. 
But if the `__external_threading` header is present, we should exclude all of 
that POC stuff.


https://reviews.llvm.org/D25468

Files:
  include/__threading_support


Index: include/__threading_support
===
--- include/__threading_support
+++ include/__threading_support
@@ -25,17 +25,16 @@
 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 #if !defined(__clang__) && (_GNUC_VER < 500)
 #include <__external_threading>
-#define _LIBCPP_EXTERNAL_THREADING
+#define _LIBCPP_HAS_EXTERNAL_THREADING_HEADER
 #elif !defined(__has_include) || __has_include(<__external_threading>)
 #include <__external_threading>
-#define _LIBCPP_EXTERNAL_THREADING
+#define _LIBCPP_HAS_EXTERNAL_THREADING_HEADER
 #endif
 #endif
 
-#if !defined(_LIBCPP_EXTERNAL_THREADING)
+#if !defined(_LIBCPP_HAS_EXTERNAL_THREADING_HEADER)
 #include 
 #include 
-#endif
 
 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 #define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_FUNC_VIS
@@ -242,6 +241,8 @@
 
 _LIBCPP_END_NAMESPACE_STD
 
+#endif // !_LIBCPP_HAS_EXTERNAL_THREADING_HEADER
+
 #endif // _LIBCPP_HAS_NO_THREADS
 
 #endif // _LIBCPP_THREADING_SUPPORT


Index: include/__threading_support
===
--- include/__threading_support
+++ include/__threading_support
@@ -25,17 +25,16 @@
 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 #if !defined(__clang__) && (_GNUC_VER < 500)
 #include <__external_threading>
-#define _LIBCPP_EXTERNAL_THREADING
+#define _LIBCPP_HAS_EXTERNAL_THREADING_HEADER
 #elif !defined(__has_include) || __has_include(<__external_threading>)
 #include <__external_threading>
-#define _LIBCPP_EXTERNAL_THREADING
+#define _LIBCPP_HAS_EXTERNAL_THREADING_HEADER
 #endif
 #endif
 
-#if !defined(_LIBCPP_EXTERNAL_THREADING)
+#if !defined(_LIBCPP_HAS_EXTERNAL_THREADING_HEADER)
 #include 
 #include 
-#endif
 
 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 #define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_FUNC_VIS
@@ -242,6 +241,8 @@
 
 _LIBCPP_END_NAMESPACE_STD
 
+#endif // !_LIBCPP_HAS_EXTERNAL_THREADING_HEADER
+
 #endif // _LIBCPP_HAS_NO_THREADS
 
 #endif // _LIBCPP_THREADING_SUPPORT
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25468: [libcxx] Do not declare the thread api when __external_threading is present

2016-10-11 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

Added some comments to @EricWF's feedback. Will check back tomorrow (falling 
asleep...)

/ Asiri




Comment at: include/__threading_support:25
 // redundancy is intentional.
 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 #if !defined(__clang__) && (_GNUC_VER < 500)

EricWF wrote:
> If `_LIBCPP_HAS_THREAD_API_EXTERNAL` is defined can't we just assume that 
> `<__external_threading> is present?
So, `_LIBCPP_HAS_THREAD_API_EXTERNAL` is set from the cmake option for building 
the externally threaded variant. For the proof-of-concept implementation (that 
we use for running the test suite), we embed a pthread-based external API 
within `__threading_support` itself and provide its implementation in 
`test/support/external_threads.cpp` (which is built into a separate library 
when running the test suite).

That means, in the default externally-threaded variant (POC), we don't have a 
`__external_threading` header; the idea is to allow library vendors to drop-in 
a `__external_threading` header without conflicting with upstream sources, and 
it will be picked up automatically by `__threading_support` header. Moreover, 
this way we avoid the cost of shipping an additional header which is not 
necessary for the most common use case (direct pthread dependency).

This is why we need this contraption to detect if the externally threaded 
library is built with a `__external_threading` header (i.e. for production) or 
not (the default - vanilla upstream setup, the POC). 

Hope that makes sense? Perhaps I should explain all this in a comment as well?



Comment at: include/__threading_support:35
 
-#if !defined(_LIBCPP_EXTERNAL_THREADING)
+#if !defined(_LIBCPP_HAS_EXTERNAL_THREADING_HEADER)
 #include 

EricWF wrote:
> Instead of using a new macro couldn't this just be 
> `_LIBCPP_HAS_THREAD_API_EXTERNAL`?
I think my comment above covers this point as well.


https://reviews.llvm.org/D25468



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D21803: [libcxxabi] Provide a fallback __cxa_thread_atexit() implementation

2016-10-12 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

In https://reviews.llvm.org/D21803#567774, @tavianator wrote:

> In https://reviews.llvm.org/D21803#556857, @EricWF wrote:
>
> > @rmaprath I'll merge this if needed. Feel free to commit your patch first.
>
>
> Yeah, @rmaprath I'm happy to rebase this over your patch.


My patch got a bit stuck downstream :(

So you / @EricWF can go ahead with this patch, I'll rebase mine over yours when 
I'm ready to commit.

/ Asiri


https://reviews.llvm.org/D21803



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [libcxx] r284005 - Remove incorrect XFAILS

2016-10-12 Thread Asiri Rathnayake via cfe-commits
Thanks!

I still have that no-exception cleanup in my TODO list. Just pressed on
time, hope to get to it soon.

/ Asiri

On Wed, Oct 12, 2016 at 12:29 PM, Eric Fiselier via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: ericwf
> Date: Wed Oct 12 06:29:18 2016
> New Revision: 284005
>
> URL: http://llvm.org/viewvc/llvm-project?rev=284005&view=rev
> Log:
> Remove incorrect XFAILS
>
> Modified:
> libcxx/trunk/test/libcxx/utilities/optional/optional.
> object/optional.object.assign/copy.pass.cpp
> libcxx/trunk/test/libcxx/utilities/optional/optional.
> object/optional.object.assign/move.pass.cpp
> libcxx/trunk/test/libcxx/utilities/optional/optional.
> object/optional.object.ctor/copy.pass.cpp
> libcxx/trunk/test/libcxx/utilities/optional/optional.
> object/optional.object.ctor/move.pass.cpp
>
> Modified: libcxx/trunk/test/libcxx/utilities/optional/optional.
> object/optional.object.assign/copy.pass.cpp
> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/
> libcxx/utilities/optional/optional.object/optional.
> object.assign/copy.pass.cpp?rev=284005&r1=284004&r2=284005&view=diff
> 
> ==
> --- libcxx/trunk/test/libcxx/utilities/optional/optional.
> object/optional.object.assign/copy.pass.cpp (original)
> +++ libcxx/trunk/test/libcxx/utilities/optional/optional.
> object/optional.object.assign/copy.pass.cpp Wed Oct 12 06:29:18 2016
> @@ -8,7 +8,6 @@
>  //===---
> ---===//
>
>  // UNSUPPORTED: c++98, c++03, c++11, c++14
> -// XFAIL: libcpp-no-exceptions
>  // 
>
>  // optional& operator=(const optional& rhs);
> @@ -45,7 +44,6 @@ struct Z2
>  Z2& operator=(const Z2&) = default;
>  };
>
> -#if __cplusplus >= 201402
>  template 
>  constexpr bool
>  test()
> @@ -55,23 +53,18 @@ test()
>  opt = opt2;
>  return true;
>  }
> -#endif
>
>  int main()
>  {
>  {
>  using T = int;
>  
> static_assert((std::is_trivially_copy_assignable>::value),
> "");
> -#if __cplusplus >= 201402
>  static_assert(test(), "");
> -#endif
>  }
>  {
>  using T = X;
>  
> static_assert((std::is_trivially_copy_assignable>::value),
> "");
> -#if __cplusplus >= 201402
>  static_assert(test(), "");
> -#endif
>  }
>  static_assert(!(std::is_trivially_copy_assignable>::value),
> "");
>  static_assert(!(std::is_trivially_copy_assignable<
> optional>::value), "");
>
> Modified: libcxx/trunk/test/libcxx/utilities/optional/optional.
> object/optional.object.assign/move.pass.cpp
> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/
> libcxx/utilities/optional/optional.object/optional.
> object.assign/move.pass.cpp?rev=284005&r1=284004&r2=284005&view=diff
> 
> ==
> --- libcxx/trunk/test/libcxx/utilities/optional/optional.
> object/optional.object.assign/move.pass.cpp (original)
> +++ libcxx/trunk/test/libcxx/utilities/optional/optional.
> object/optional.object.assign/move.pass.cpp Wed Oct 12 06:29:18 2016
> @@ -8,7 +8,6 @@
>  //===---
> ---===//
>
>  // UNSUPPORTED: c++98, c++03, c++11, c++14
> -// XFAIL: libcpp-no-exceptions
>  // 
>
>  // optional& operator=(optional&& rhs);
> @@ -42,7 +41,6 @@ struct Z2
>  Z2& operator=(Z2&&) = default;
>  };
>
> -#if __cplusplus >= 201402
>  template 
>  constexpr bool
>  test()
> @@ -52,23 +50,18 @@ test()
>  opt = std::move(opt2);
>  return true;
>  }
> -#endif
>
>  int main()
>  {
>  {
>  using T = int;
>  
> static_assert((std::is_trivially_copy_constructible>::value),
> "");
> -#if __cplusplus >= 201402
>  static_assert(test(), "");
> -#endif
>  }
>  {
>  using T = X;
>  
> static_assert((std::is_trivially_copy_constructible>::value),
> "");
> -#if __cplusplus >= 201402
>  static_assert(test(), "");
> -#endif
>  }
>  static_assert(!(std::is_trivially_move_assignable>::value),
> "");
>  static_assert(!(std::is_trivially_move_assignable<
> optional>::value), "");
>
> Modified: libcxx/trunk/test/libcxx/utilities/optional/optional.
> object/optional.object.ctor/copy.pass.cpp
> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/
> libcxx/utilities/optional/optional.object/optional.
> object.ctor/copy.pass.cpp?rev=284005&r1=284004&r2=284005&view=diff
> 
> ==
> --- libcxx/trunk/test/libcxx/utilities/optional/optional.
> object/optional.object.ctor/copy.pass.cpp (original)
> +++ libcxx/trunk/test/libcxx/utilities/optional/optional.
> object/optional.object.ctor/copy.pass.cpp Wed Oct 12 06:29:18 2016
> @@ -8,7 +8,7 @@
>  //===---
> ---===//
>
>  // UNSUPPORTED: c++98, c++03, c++11, c++14
> -// 

Re: [libcxx] r284005 - Remove incorrect XFAILS

2016-10-12 Thread Asiri Rathnayake via cfe-commits
More love for no-exceptions in any case ;)

Cheers!

On Wed, Oct 12, 2016 at 12:52 PM, Eric Fiselier  wrote:

> I just committed those tests, so I kinda had to fix them :-P
>
> On Wed, Oct 12, 2016 at 5:40 AM, Asiri Rathnayake <
> asiri.rathnay...@gmail.com> wrote:
>
>> Thanks!
>>
>> I still have that no-exception cleanup in my TODO list. Just pressed on
>> time, hope to get to it soon.
>>
>> / Asiri
>>
>> On Wed, Oct 12, 2016 at 12:29 PM, Eric Fiselier via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: ericwf
>>> Date: Wed Oct 12 06:29:18 2016
>>> New Revision: 284005
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=284005&view=rev
>>> Log:
>>> Remove incorrect XFAILS
>>>
>>> Modified:
>>> libcxx/trunk/test/libcxx/utilities/optional/optional.object/
>>> optional.object.assign/copy.pass.cpp
>>> libcxx/trunk/test/libcxx/utilities/optional/optional.object/
>>> optional.object.assign/move.pass.cpp
>>> libcxx/trunk/test/libcxx/utilities/optional/optional.object/
>>> optional.object.ctor/copy.pass.cpp
>>> libcxx/trunk/test/libcxx/utilities/optional/optional.object/
>>> optional.object.ctor/move.pass.cpp
>>>
>>> Modified: libcxx/trunk/test/libcxx/utilities/optional/optional.object/
>>> optional.object.assign/copy.pass.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx
>>> /utilities/optional/optional.object/optional.object.assign/c
>>> opy.pass.cpp?rev=284005&r1=284004&r2=284005&view=diff
>>> 
>>> ==
>>> --- libcxx/trunk/test/libcxx/utilities/optional/optional.object/
>>> optional.object.assign/copy.pass.cpp (original)
>>> +++ libcxx/trunk/test/libcxx/utilities/optional/optional.object/
>>> optional.object.assign/copy.pass.cpp Wed Oct 12 06:29:18 2016
>>> @@ -8,7 +8,6 @@
>>>  //===--
>>> ===//
>>>
>>>  // UNSUPPORTED: c++98, c++03, c++11, c++14
>>> -// XFAIL: libcpp-no-exceptions
>>>  // 
>>>
>>>  // optional& operator=(const optional& rhs);
>>> @@ -45,7 +44,6 @@ struct Z2
>>>  Z2& operator=(const Z2&) = default;
>>>  };
>>>
>>> -#if __cplusplus >= 201402
>>>  template 
>>>  constexpr bool
>>>  test()
>>> @@ -55,23 +53,18 @@ test()
>>>  opt = opt2;
>>>  return true;
>>>  }
>>> -#endif
>>>
>>>  int main()
>>>  {
>>>  {
>>>  using T = int;
>>>  
>>> static_assert((std::is_trivially_copy_assignable>::value),
>>> "");
>>> -#if __cplusplus >= 201402
>>>  static_assert(test(), "");
>>> -#endif
>>>  }
>>>  {
>>>  using T = X;
>>>  
>>> static_assert((std::is_trivially_copy_assignable>::value),
>>> "");
>>> -#if __cplusplus >= 201402
>>>  static_assert(test(), "");
>>> -#endif
>>>  }
>>>  static_assert(!(std::is_trivially_copy_assignable>::value),
>>> "");
>>>  
>>> static_assert(!(std::is_trivially_copy_assignable>::value),
>>> "");
>>>
>>> Modified: libcxx/trunk/test/libcxx/utilities/optional/optional.object/
>>> optional.object.assign/move.pass.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx
>>> /utilities/optional/optional.object/optional.object.assign/m
>>> ove.pass.cpp?rev=284005&r1=284004&r2=284005&view=diff
>>> 
>>> ==
>>> --- libcxx/trunk/test/libcxx/utilities/optional/optional.object/
>>> optional.object.assign/move.pass.cpp (original)
>>> +++ libcxx/trunk/test/libcxx/utilities/optional/optional.object/
>>> optional.object.assign/move.pass.cpp Wed Oct 12 06:29:18 2016
>>> @@ -8,7 +8,6 @@
>>>  //===--
>>> ===//
>>>
>>>  // UNSUPPORTED: c++98, c++03, c++11, c++14
>>> -// XFAIL: libcpp-no-exceptions
>>>  // 
>>>
>>>  // optional& operator=(optional&& rhs);
>>> @@ -42,7 +41,6 @@ struct Z2
>>>  Z2& operator=(Z2&&) = default;
>>>  };
>>>
>>> -#if __cplusplus >= 201402
>>>  template 
>>>  constexpr bool
>>>  test()
>>> @@ -52,23 +50,18 @@ test()
>>>  opt = std::move(opt2);
>>>  return true;
>>>  }
>>> -#endif
>>>
>>>  int main()
>>>  {
>>>  {
>>>  using T = int;
>>>  
>>> static_assert((std::is_trivially_copy_constructible>::value),
>>> "");
>>> -#if __cplusplus >= 201402
>>>  static_assert(test(), "");
>>> -#endif
>>>  }
>>>  {
>>>  using T = X;
>>>  
>>> static_assert((std::is_trivially_copy_constructible>::value),
>>> "");
>>> -#if __cplusplus >= 201402
>>>  static_assert(test(), "");
>>> -#endif
>>>  }
>>>  static_assert(!(std::is_trivially_move_assignable>::value),
>>> "");
>>>  
>>> static_assert(!(std::is_trivially_move_assignable>::value),
>>> "");
>>>
>>> Modified: libcxx/trunk/test/libcxx/utilities/optional/optional.object/
>>> optional.object.ctor/copy.pass.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx
>>> /utilities/optional/optional.object/op

[libunwind] r284125 - [libunwind] Add missing include. NFC.

2016-10-13 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Thu Oct 13 09:32:24 2016
New Revision: 284125

URL: http://llvm.org/viewvc/llvm-project?rev=284125&view=rev
Log:
[libunwind] Add missing  include. NFC.

This missing include seems to cause compilation failures on older MacOS
versions (< 10.9). This is because r270692 has introduced uint64_t into
config.h without including this header.

Patch from: Jeremy Huddleston Sequoia (jerem...@apple.com)

Modified:
libunwind/trunk/src/config.h

Modified: libunwind/trunk/src/config.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/config.h?rev=284125&r1=284124&r2=284125&view=diff
==
--- libunwind/trunk/src/config.h (original)
+++ libunwind/trunk/src/config.h Thu Oct 13 09:32:24 2016
@@ -16,6 +16,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 // Define static_assert() unless already defined by compiler.


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: libunwind build regression fix

2016-10-13 Thread Asiri Rathnayake via cfe-commits
Hi Jeremy,

Thanks for the patch, committed as r284125.

Cheers,

/ Asiri


From: jerem...@apple.com  on behalf of Jeremy Huddleston 
Sequoia 
Sent: 13 October 2016 06:57
To: Asiri Rathnayake
Subject: libunwind build regression fix

Hi Asiri,

Could you please push this build fix to libunwind.  Your 
LIBUNWIND_ENABLE_CROSS_UNWINDING change a few months ago introduced a build 
failure because uint64_t is used in config.h without an include of  
(failure noticed on macOS versions older than 10.9).

Thanks,
Jeremy


From 59508d1029580fe2f95eb4b8a002175c6f87710d Mon Sep 17 00:00:00 2001
From: Jeremy Huddleston Sequoia 
Date: Wed, 12 Oct 2016 22:52:51 -0700
Subject: [PATCH] config.h: Add missing include of stdint.h for uint64_t usage

Regressed-in: trunk r270692
Regressed-in: d2d1ea9d75dfc4f55540f7e3cf940c6a1d6674cc
Signed-off-by: Jeremy Huddleston Sequoia 
CC: Asiri Rathnayake 
---
 src/config.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/config.h b/src/config.h
index cfe7706..4e4dd99 100644
--- a/src/config.h
+++ b/src/config.h
@@ -16,6 +16,7 @@

 #include 
 #include 
+#include 
 #include 

 // Define static_assert() unless already defined by compiler.
--
2.9.3

IMPORTANT NOTICE: The contents of this email and any attachments are 
confidential and may also be privileged. If you are not the intended recipient, 
please notify the sender immediately and do not disclose the contents to any 
other person, use it for any purpose, or store or copy the information in any 
medium. Thank you.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: libunwind build regression fix

2016-10-13 Thread Asiri Rathnayake via cfe-commits
And... apologies for that disclaimer notice.

Cheers,

/ Asiri


From: cfe-commits  on behalf of Asiri 
Rathnayake via cfe-commits 
Sent: 13 October 2016 15:42
To: Jeremy Huddleston Sequoia
Cc: cfe-commits@lists.llvm.org
Subject: Re: libunwind build regression fix

Hi Jeremy,

Thanks for the patch, committed as r284125.

Cheers,

/ Asiri


From: jerem...@apple.com  on behalf of Jeremy Huddleston 
Sequoia 
Sent: 13 October 2016 06:57
To: Asiri Rathnayake
Subject: libunwind build regression fix

Hi Asiri,

Could you please push this build fix to libunwind.  Your 
LIBUNWIND_ENABLE_CROSS_UNWINDING change a few months ago introduced a build 
failure because uint64_t is used in config.h without an include of  
(failure noticed on macOS versions older than 10.9).

Thanks,
Jeremy


From 59508d1029580fe2f95eb4b8a002175c6f87710d Mon Sep 17 00:00:00 2001
From: Jeremy Huddleston Sequoia 
Date: Wed, 12 Oct 2016 22:52:51 -0700
Subject: [PATCH] config.h: Add missing include of stdint.h for uint64_t usage

Regressed-in: trunk r270692
Regressed-in: d2d1ea9d75dfc4f55540f7e3cf940c6a1d6674cc
Signed-off-by: Jeremy Huddleston Sequoia 
CC: Asiri Rathnayake 
---
 src/config.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/config.h b/src/config.h
index cfe7706..4e4dd99 100644
--- a/src/config.h
+++ b/src/config.h
@@ -16,6 +16,7 @@

 #include 
 #include 
+#include 
 #include 

 // Define static_assert() unless already defined by compiler.
--
2.9.3

IMPORTANT NOTICE: The contents of this email and any attachments are 
confidential and may also be privileged. If you are not the intended recipient, 
please notify the sender immediately and do not disclose the contents to any 
other person, use it for any purpose, or store or copy the information in any 
medium. Thank you.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24864: [libcxxabi] Refactor pthread usage into a separate API

2016-10-13 Thread Asiri Rathnayake via cfe-commits
rmaprath updated this revision to Diff 74519.
rmaprath added a comment.
Herald added a subscriber: modocache.

Patch re-based on the latest trunk.

I've resolved my downstream issues, will be committing soon.

/ Asiri


https://reviews.llvm.org/D24864

Files:
  CMakeLists.txt
  src/config.h
  src/cxa_exception.cpp
  src/cxa_exception_storage.cpp
  src/cxa_guard.cpp
  src/cxa_thread_atexit.cpp
  src/fallback_malloc.cpp
  src/threading_support.h
  test/test_exception_storage.pass.cpp
  test/test_fallback_malloc.pass.cpp

Index: test/test_fallback_malloc.pass.cpp
===
--- test/test_fallback_malloc.pass.cpp
+++ test/test_fallback_malloc.pass.cpp
@@ -10,7 +10,7 @@
 #include 
 #include 
 
-#include 
+#include "../src/threading_support.h"
 
 typedef std::deque container;
 
Index: test/test_exception_storage.pass.cpp
===
--- test/test_exception_storage.pass.cpp
+++ test/test_exception_storage.pass.cpp
@@ -12,9 +12,7 @@
 #include 
 #include 
 #include 
-#ifndef _LIBCXXABI_HAS_NO_THREADS
-#  include 
-#endif
+#include "../src/threading_support.h"
 #include 
 
 #include "../src/cxa_exception.hpp"
@@ -40,19 +38,19 @@
 
 #ifndef _LIBCXXABI_HAS_NO_THREADS
 #define NUMTHREADS  10
-size_t  thread_globals [ NUMTHREADS ] = { 0 };
-pthread_t   threads[ NUMTHREADS ];
+size_t thread_globals [ NUMTHREADS ] = { 0 };
+__libcxxabi_thread_t   threads[ NUMTHREADS ];
 #endif
 
 int main ( int argc, char *argv [] ) {
 int retVal = 0;
 
 #ifndef _LIBCXXABI_HAS_NO_THREADS
 //  Make the threads, let them run, and wait for them to finish
 for ( int i = 0; i < NUMTHREADS; ++i )
-pthread_create( threads + i, NULL, thread_code, (void *) (thread_globals + i));
+__libcxxabi_thread_create ( threads + i, thread_code, (void *) (thread_globals + i));
 for ( int i = 0; i < NUMTHREADS; ++i )
-pthread_join ( threads [ i ], NULL );
+__libcxxabi_thread_join ( &threads [ i ] );
 
 for ( int i = 0; i < NUMTHREADS; ++i )
 if ( 0 == thread_globals [ i ] ) {
Index: src/threading_support.h
===
--- /dev/null
+++ src/threading_support.h
@@ -0,0 +1,107 @@
+//=== threading_support.h -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef _LIBCXXABI_THREADING_SUPPORT_H
+#define _LIBCXXABI_THREADING_SUPPORT_H
+
+#include "__cxxabi_config.h"
+#include "config.h"
+
+#ifndef _LIBCXXABI_HAS_NO_THREADS
+
+#if defined(_LIBCXXABI_USE_THREAD_API_PTHREAD)
+#include 
+
+#define _LIBCXXABI_THREAD_ABI_VISIBILITY inline _LIBCXXABI_INLINE_VISIBILITY
+
+// Mutex
+typedef pthread_mutex_t __libcxxabi_mutex_t;
+#define _LIBCXXABI_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_mutex_lock(__libcxxabi_mutex_t *mutex) {
+  return pthread_mutex_lock(mutex);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_mutex_unlock(__libcxxabi_mutex_t *mutex) {
+  return pthread_mutex_unlock(mutex);
+}
+
+// Condition variable
+typedef pthread_cond_t __libcxxabi_condvar_t;
+#define _LIBCXXABI_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_condvar_wait(__libcxxabi_condvar_t *cv,
+ __libcxxabi_mutex_t *mutex) {
+  return pthread_cond_wait(cv, mutex);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_condvar_broadcast(__libcxxabi_condvar_t *cv) {
+  return pthread_cond_broadcast(cv);
+}
+
+// Execute once
+typedef pthread_once_t __libcxxabi_exec_once_flag;
+#define _LIBCXXABI_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_execute_once(__libcxxabi_exec_once_flag *flag,
+ void (*init_routine)(void)) {
+  return pthread_once(flag, init_routine);
+}
+
+// Thread id
+#if defined(__APPLE__) && !defined(__arm__)
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+mach_port_t __libcxxabi_thread_get_port()
+{
+return pthread_mach_thread_np(pthread_self());
+}
+#endif
+
+// Thread
+typedef pthread_t __libcxxabi_thread_t;
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_thread_create(__libcxxabi_thread_t* __t,
+   void* (*__func)(void*), void* __arg)
+{
+return pthread_create(__t, 0, __func, __arg);
+}
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_thread_join(__libcxxabi_thread_t* __t)
+{
+return pthread_join(*__t, 0);
+}
+
+// TLS
+typedef pthread_key_t __libcxxabi_tls_key;
+
+_LIBCXXABI_THREAD_ABI_VISIBILITY
+int __libcxxabi_tls_create(__libcxxabi_tls_key *key,
+   void (*destructor)

[libcxxabi] r284128 - [libcxxabi] Refactor pthread usage into a separate API

2016-10-13 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Thu Oct 13 10:05:19 2016
New Revision: 284128

URL: http://llvm.org/viewvc/llvm-project?rev=284128&view=rev
Log:
[libcxxabi] Refactor pthread usage into a separate API

This patch refactors all pthread uses of libc++abi into a separate API. This
is the first step towards supporting an externlly-threaded libc++abi library.

I've followed the conventions already used in the libc++ library for the same
purpose.

Patch from: Saleem Abdulrasool and Asiri Rathnayake

Reviewed by: compnerd, EricWF

Differential revisions:
  https://reviews.llvm.org/D18482 (original)
  https://reviews.llvm.org/D24864 (final)

Added:
libcxxabi/trunk/src/threading_support.h
Modified:
libcxxabi/trunk/CMakeLists.txt
libcxxabi/trunk/src/config.h
libcxxabi/trunk/src/cxa_exception.cpp
libcxxabi/trunk/src/cxa_exception_storage.cpp
libcxxabi/trunk/src/cxa_guard.cpp
libcxxabi/trunk/src/cxa_thread_atexit.cpp
libcxxabi/trunk/src/fallback_malloc.cpp
libcxxabi/trunk/test/test_exception_storage.pass.cpp
libcxxabi/trunk/test/test_fallback_malloc.pass.cpp

Modified: libcxxabi/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/CMakeLists.txt?rev=284128&r1=284127&r2=284128&view=diff
==
--- libcxxabi/trunk/CMakeLists.txt (original)
+++ libcxxabi/trunk/CMakeLists.txt Thu Oct 13 10:05:19 2016
@@ -340,6 +340,7 @@ endif()
 
 if (LIBCXXABI_HAS_PTHREAD_API)
   add_definitions(-D_LIBCPP_HAS_THREAD_API_PTHREAD)
+  add_definitions(-D_LIBCXXABI_USE_THREAD_API_PTHREAD)
 endif()
 
 if (MSVC)

Modified: libcxxabi/trunk/src/config.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/config.h?rev=284128&r1=284127&r2=284128&view=diff
==
--- libcxxabi/trunk/src/config.h (original)
+++ libcxxabi/trunk/src/config.h Thu Oct 13 10:05:19 2016
@@ -16,6 +16,36 @@
 
 #include 
 
+// Configure inline visibility attributes
+#if defined(_WIN32)
+ #if defined(_MSC_VER) && !defined(__clang__)
+  // Using Microsoft Visual C++ compiler
+  #define _LIBCXXABI_INLINE_VISIBILITY __forceinline
+ #else
+  #if __has_attribute(__internal_linkage__)
+   #define _LIBCXXABI_INLINE_VISIBILITY __attribute__ ((__internal_linkage__, 
__always_inline__))
+  #else
+   #define _LIBCXXABI_INLINE_VISIBILITY __attribute__ ((__always_inline__))
+  #endif
+ #endif
+#else
+ #if __has_attribute(__internal_linkage__)
+  #define _LIBCXXABI_INLINE_VISIBILITY __attribute__ ((__internal_linkage__, 
__always_inline__))
+ #else
+  #define _LIBCXXABI_INLINE_VISIBILITY __attribute__ 
((__visibility__("hidden"), __always_inline__))
+ #endif
+#endif
+
+// Try and deduce a threading api if one has not been explicitly set.
+#if !defined(_LIBCXXABI_HAS_NO_THREADS) && \
+!defined(_LIBCXXABI_USE_THREAD_API_PTHREAD)
+  #if defined(_POSIX_THREADS) && _POSIX_THREADS >= 0
+#define _LIBCXXABI_USE_THREAD_API_PTHREAD
+  #else
+#error "No thread API"
+  #endif
+#endif
+
 // Set this in the CXXFLAGS when you need it, because otherwise we'd have to
 // #if !defined(__linux__) && !defined(__APPLE__) && ...
 // and so-on for *every* platform.

Modified: libcxxabi/trunk/src/cxa_exception.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception.cpp?rev=284128&r1=284127&r2=284128&view=diff
==
--- libcxxabi/trunk/src/cxa_exception.cpp (original)
+++ libcxxabi/trunk/src/cxa_exception.cpp Thu Oct 13 10:05:19 2016
@@ -12,6 +12,7 @@
 
//===--===//
 
 #include "config.h"
+#include "threading_support.h"
 #include "cxxabi.h"
 
 #include // for std::terminate

Modified: libcxxabi/trunk/src/cxa_exception_storage.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception_storage.cpp?rev=284128&r1=284127&r2=284128&view=diff
==
--- libcxxabi/trunk/src/cxa_exception_storage.cpp (original)
+++ libcxxabi/trunk/src/cxa_exception_storage.cpp Thu Oct 13 10:05:19 2016
@@ -14,6 +14,7 @@
 #include "cxa_exception.hpp"
 
 #include "config.h"
+#include "threading_support.h"
 
 #if defined(_LIBCXXABI_HAS_NO_THREADS)
 
@@ -44,28 +45,27 @@ extern "C" {
 
 #else
 
-#include 
 #include "abort_message.h"
 #include "fallback_malloc.h"
 
-//  In general, we treat all pthread errors as fatal.
+//  In general, we treat all threading errors as fatal.
 //  We cannot call std::terminate() because that will in turn
 //  call __cxa_get_globals() and cause infinite recursion.
 
 namespace __cxxabiv1 {
 namespace {
-pthread_key_t  key_;
-pthread_once_t flag_ = PTHREAD_ONCE_INIT;
+__libcxxabi_tls_key key_;
+__libcxxabi_exec_once_flag flag_ = _LIBCXXABI_EXEC_ONCE_INITIALIZER;
 
 void destruct_ (void *p) {
 __free_with_fallback 

Re: [libcxxabi] r284128 - [libcxxabi] Refactor pthread usage into a separate API

2016-10-13 Thread Asiri Rathnayake via cfe-commits
Looks like this broke the gcc builder:
http://lab.llvm.org:8011/builders/libcxx-libcxxabi-x86_64-linux-ubuntu-gcc49-cxx11/builds/573/steps/build.libcxxabi/logs/stdio

I'll have a look soon, might not be able to do so before tomorrow. Please
feel free to revert if this is blocking.

Sorry for the trouble.

/ Asiri

On Thu, Oct 13, 2016 at 4:05 PM, Asiri Rathnayake via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: asiri
> Date: Thu Oct 13 10:05:19 2016
> New Revision: 284128
>
> URL: http://llvm.org/viewvc/llvm-project?rev=284128&view=rev
> Log:
> [libcxxabi] Refactor pthread usage into a separate API
>
> This patch refactors all pthread uses of libc++abi into a separate API.
> This
> is the first step towards supporting an externlly-threaded libc++abi
> library.
>
> I've followed the conventions already used in the libc++ library for the
> same
> purpose.
>
> Patch from: Saleem Abdulrasool and Asiri Rathnayake
>
> Reviewed by: compnerd, EricWF
>
> Differential revisions:
>   https://reviews.llvm.org/D18482 (original)
>   https://reviews.llvm.org/D24864 (final)
>
> Added:
> libcxxabi/trunk/src/threading_support.h
> Modified:
> libcxxabi/trunk/CMakeLists.txt
> libcxxabi/trunk/src/config.h
> libcxxabi/trunk/src/cxa_exception.cpp
> libcxxabi/trunk/src/cxa_exception_storage.cpp
> libcxxabi/trunk/src/cxa_guard.cpp
> libcxxabi/trunk/src/cxa_thread_atexit.cpp
> libcxxabi/trunk/src/fallback_malloc.cpp
> libcxxabi/trunk/test/test_exception_storage.pass.cpp
> libcxxabi/trunk/test/test_fallback_malloc.pass.cpp
>
> Modified: libcxxabi/trunk/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/
> CMakeLists.txt?rev=284128&r1=284127&r2=284128&view=diff
> 
> ==
> --- libcxxabi/trunk/CMakeLists.txt (original)
> +++ libcxxabi/trunk/CMakeLists.txt Thu Oct 13 10:05:19 2016
> @@ -340,6 +340,7 @@ endif()
>
>  if (LIBCXXABI_HAS_PTHREAD_API)
>add_definitions(-D_LIBCPP_HAS_THREAD_API_PTHREAD)
> +  add_definitions(-D_LIBCXXABI_USE_THREAD_API_PTHREAD)
>  endif()
>
>  if (MSVC)
>
> Modified: libcxxabi/trunk/src/config.h
> URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/
> config.h?rev=284128&r1=284127&r2=284128&view=diff
> 
> ==
> --- libcxxabi/trunk/src/config.h (original)
> +++ libcxxabi/trunk/src/config.h Thu Oct 13 10:05:19 2016
> @@ -16,6 +16,36 @@
>
>  #include 
>
> +// Configure inline visibility attributes
> +#if defined(_WIN32)
> + #if defined(_MSC_VER) && !defined(__clang__)
> +  // Using Microsoft Visual C++ compiler
> +  #define _LIBCXXABI_INLINE_VISIBILITY __forceinline
> + #else
> +  #if __has_attribute(__internal_linkage__)
> +   #define _LIBCXXABI_INLINE_VISIBILITY __attribute__
> ((__internal_linkage__, __always_inline__))
> +  #else
> +   #define _LIBCXXABI_INLINE_VISIBILITY __attribute__
> ((__always_inline__))
> +  #endif
> + #endif
> +#else
> + #if __has_attribute(__internal_linkage__)
> +  #define _LIBCXXABI_INLINE_VISIBILITY __attribute__
> ((__internal_linkage__, __always_inline__))
> + #else
> +  #define _LIBCXXABI_INLINE_VISIBILITY __attribute__
> ((__visibility__("hidden"), __always_inline__))
> + #endif
> +#endif
> +
> +// Try and deduce a threading api if one has not been explicitly set.
> +#if !defined(_LIBCXXABI_HAS_NO_THREADS) && \
> +!defined(_LIBCXXABI_USE_THREAD_API_PTHREAD)
> +  #if defined(_POSIX_THREADS) && _POSIX_THREADS >= 0
> +#define _LIBCXXABI_USE_THREAD_API_PTHREAD
> +  #else
> +#error "No thread API"
> +  #endif
> +#endif
> +
>  // Set this in the CXXFLAGS when you need it, because otherwise we'd have
> to
>  // #if !defined(__linux__) && !defined(__APPLE__) && ...
>  // and so-on for *every* platform.
>
> Modified: libcxxabi/trunk/src/cxa_exception.cpp
> URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/
> cxa_exception.cpp?rev=284128&r1=284127&r2=284128&view=diff
> 
> ==
> --- libcxxabi/trunk/src/cxa_exception.cpp (original)
> +++ libcxxabi/trunk/src/cxa_exception.cpp Thu Oct 13 10:05:19 2016
> @@ -12,6 +12,7 @@
>  //===---
> ---===//
>
>  #include "config.h"
> +#include "threading_support.h"
>  #include "cxxabi.h"
>
>  #include // for std::terminate
>
> Modified: li

[libcxxabi] r284141 - [libcxxabi] Fix gcc build after r284128

2016-10-13 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Thu Oct 13 13:40:57 2016
New Revision: 284141

URL: http://llvm.org/viewvc/llvm-project?rev=284141&view=rev
Log:
[libcxxabi] Fix gcc build after r284128

NFC.

Modified:
libcxxabi/trunk/src/config.h

Modified: libcxxabi/trunk/src/config.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/config.h?rev=284141&r1=284140&r2=284141&view=diff
==
--- libcxxabi/trunk/src/config.h (original)
+++ libcxxabi/trunk/src/config.h Thu Oct 13 13:40:57 2016
@@ -16,6 +16,10 @@
 
 #include 
 
+#ifndef __has_attribute
+  #define __has_attribute(x) 0
+#endif
+
 // Configure inline visibility attributes
 #if defined(_WIN32)
  #if defined(_MSC_VER) && !defined(__clang__)


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [libcxxabi] r284128 - [libcxxabi] Refactor pthread usage into a separate API

2016-10-13 Thread Asiri Rathnayake via cfe-commits
Should be fixed in r284141.

/ Asiri

On Thu, Oct 13, 2016 at 7:20 PM, Asiri Rathnayake <
asiri.rathnay...@gmail.com> wrote:

> Looks like this broke the gcc builder: http://lab.llvm.org:
> 8011/builders/libcxx-libcxxabi-x86_64-linux-ubuntu-
> gcc49-cxx11/builds/573/steps/build.libcxxabi/logs/stdio
>
> I'll have a look soon, might not be able to do so before tomorrow. Please
> feel free to revert if this is blocking.
>
> Sorry for the trouble.
>
> / Asiri
>
> On Thu, Oct 13, 2016 at 4:05 PM, Asiri Rathnayake via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: asiri
>> Date: Thu Oct 13 10:05:19 2016
>> New Revision: 284128
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=284128&view=rev
>> Log:
>> [libcxxabi] Refactor pthread usage into a separate API
>>
>> This patch refactors all pthread uses of libc++abi into a separate API.
>> This
>> is the first step towards supporting an externlly-threaded libc++abi
>> library.
>>
>> I've followed the conventions already used in the libc++ library for the
>> same
>> purpose.
>>
>> Patch from: Saleem Abdulrasool and Asiri Rathnayake
>>
>> Reviewed by: compnerd, EricWF
>>
>> Differential revisions:
>>   https://reviews.llvm.org/D18482 (original)
>>   https://reviews.llvm.org/D24864 (final)
>>
>> Added:
>> libcxxabi/trunk/src/threading_support.h
>> Modified:
>> libcxxabi/trunk/CMakeLists.txt
>> libcxxabi/trunk/src/config.h
>> libcxxabi/trunk/src/cxa_exception.cpp
>> libcxxabi/trunk/src/cxa_exception_storage.cpp
>> libcxxabi/trunk/src/cxa_guard.cpp
>> libcxxabi/trunk/src/cxa_thread_atexit.cpp
>> libcxxabi/trunk/src/fallback_malloc.cpp
>> libcxxabi/trunk/test/test_exception_storage.pass.cpp
>> libcxxabi/trunk/test/test_fallback_malloc.pass.cpp
>>
>> Modified: libcxxabi/trunk/CMakeLists.txt
>> URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/CMakeLis
>> ts.txt?rev=284128&r1=284127&r2=284128&view=diff
>> 
>> ==
>> --- libcxxabi/trunk/CMakeLists.txt (original)
>> +++ libcxxabi/trunk/CMakeLists.txt Thu Oct 13 10:05:19 2016
>> @@ -340,6 +340,7 @@ endif()
>>
>>  if (LIBCXXABI_HAS_PTHREAD_API)
>>add_definitions(-D_LIBCPP_HAS_THREAD_API_PTHREAD)
>> +  add_definitions(-D_LIBCXXABI_USE_THREAD_API_PTHREAD)
>>  endif()
>>
>>  if (MSVC)
>>
>> Modified: libcxxabi/trunk/src/config.h
>> URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/conf
>> ig.h?rev=284128&r1=284127&r2=284128&view=diff
>> 
>> ==
>> --- libcxxabi/trunk/src/config.h (original)
>> +++ libcxxabi/trunk/src/config.h Thu Oct 13 10:05:19 2016
>> @@ -16,6 +16,36 @@
>>
>>  #include 
>>
>> +// Configure inline visibility attributes
>> +#if defined(_WIN32)
>> + #if defined(_MSC_VER) && !defined(__clang__)
>> +  // Using Microsoft Visual C++ compiler
>> +  #define _LIBCXXABI_INLINE_VISIBILITY __forceinline
>> + #else
>> +  #if __has_attribute(__internal_linkage__)
>> +   #define _LIBCXXABI_INLINE_VISIBILITY __attribute__
>> ((__internal_linkage__, __always_inline__))
>> +  #else
>> +   #define _LIBCXXABI_INLINE_VISIBILITY __attribute__
>> ((__always_inline__))
>> +  #endif
>> + #endif
>> +#else
>> + #if __has_attribute(__internal_linkage__)
>> +  #define _LIBCXXABI_INLINE_VISIBILITY __attribute__
>> ((__internal_linkage__, __always_inline__))
>> + #else
>> +  #define _LIBCXXABI_INLINE_VISIBILITY __attribute__
>> ((__visibility__("hidden"), __always_inline__))
>> + #endif
>> +#endif
>> +
>> +// Try and deduce a threading api if one has not been explicitly set.
>> +#if !defined(_LIBCXXABI_HAS_NO_THREADS) && \
>> +!defined(_LIBCXXABI_USE_THREAD_API_PTHREAD)
>> +  #if defined(_POSIX_THREADS) && _POSIX_THREADS >= 0
>> +#define _LIBCXXABI_USE_THREAD_API_PTHREAD
>> +  #else
>> +#error "No thread API"
>> +  #endif
>> +#endif
>> +
>>  // Set this in the CXXFLAGS when you need it, because otherwise we'd
>> have to
>>  // #if !defined(__linux__) && !defined(__APPLE__) && ...
>>  // and so-on for *every* platform.
>>
>> Modified: libcxxabi/trunk/src/cxa_e

Re: [libunwind] r284125 - [libunwind] Add missing include. NFC.

2016-10-13 Thread Asiri Rathnayake via cfe-commits
Had a look at the C99 spec, according to section 7.18.1.1 ("Exact-width
integer types"), the types uint_t should be available in stdint.h
itself, inttypes.h on the other hand builds on stdint.h and provides more
functionality.

I don't see a particular need to include inttypes.h here?

Cheers,

/ Asiri

On Thu, Oct 13, 2016 at 7:46 PM, Joerg Sonnenberger via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> On Thu, Oct 13, 2016 at 02:32:24PM -0000, Asiri Rathnayake via cfe-commits
> wrote:
> > This missing include seems to cause compilation failures on older MacOS
> > versions (< 10.9). This is because r270692 has introduced uint64_t into
> > config.h without including this header.
>
> But that would be inttypes.h, wouldn't it be?
>
> Joerg
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25468: [libcxx] Do not declare the thread api when __external_threading is present

2016-10-13 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

@EricWF: Gentle ping.


https://reviews.llvm.org/D25468



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24864: [libcxxabi] Refactor pthread usage into a separate API

2016-10-14 Thread Asiri Rathnayake via cfe-commits
rmaprath closed this revision.
rmaprath added a comment.

Committed as r284128.


https://reviews.llvm.org/D24864



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r284232 - [libcxx] Do not declare the thread api when __external_threading is present

2016-10-14 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Fri Oct 14 08:00:07 2016
New Revision: 284232

URL: http://llvm.org/viewvc/llvm-project?rev=284232&view=rev
Log:
[libcxx] Do not declare the thread api when __external_threading is present

This fixes a small omission where even when __external_threading is provided,
we attempt to declare a pthread based threading API. Instead, we should leave
out everything for the __external_threading header to take care of.

The __threading_support header provides a proof-of-concept externally threaded
libc++ variant when _LIBCPP_HAS_THREAD_API_EXTERNAL is defined. But if the
__external_threading header is present, we should exclude all of that POC stuff.

Reviewers: EricWF

Differential revision: https://reviews.llvm.org/D25468

Modified:
libcxx/trunk/include/__threading_support

Modified: libcxx/trunk/include/__threading_support
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__threading_support?rev=284232&r1=284231&r2=284232&view=diff
==
--- libcxx/trunk/include/__threading_support (original)
+++ libcxx/trunk/include/__threading_support Fri Oct 14 08:00:07 2016
@@ -25,17 +25,16 @@
 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 #if !defined(__clang__) && (_GNUC_VER < 500)
 #include <__external_threading>
-#define _LIBCPP_EXTERNAL_THREADING
+#define _LIBCPP_HAS_EXTERNAL_THREADING_HEADER
 #elif !defined(__has_include) || __has_include(<__external_threading>)
 #include <__external_threading>
-#define _LIBCPP_EXTERNAL_THREADING
+#define _LIBCPP_HAS_EXTERNAL_THREADING_HEADER
 #endif
 #endif
 
-#if !defined(_LIBCPP_EXTERNAL_THREADING)
+#if !defined(_LIBCPP_HAS_EXTERNAL_THREADING_HEADER)
 #include 
 #include 
-#endif
 
 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 #define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_FUNC_VIS
@@ -242,6 +241,8 @@ void __libcpp_tls_set(__libcpp_tls_key _
 
 _LIBCPP_END_NAMESPACE_STD
 
+#endif // !_LIBCPP_HAS_EXTERNAL_THREADING_HEADER
+
 #endif // _LIBCPP_HAS_NO_THREADS
 
 #endif // _LIBCPP_THREADING_SUPPORT


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r284237 - [libcxx] Improve the gcc workaround for the missing __has_include macro.

2016-10-14 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Fri Oct 14 08:56:58 2016
New Revision: 284237

URL: http://llvm.org/viewvc/llvm-project?rev=284237&view=rev
Log:
[libcxx] Improve the gcc workaround for the missing __has_include macro.

NFC.

Modified:
libcxx/trunk/include/__threading_support

Modified: libcxx/trunk/include/__threading_support
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__threading_support?rev=284237&r1=284236&r2=284237&view=diff
==
--- libcxx/trunk/include/__threading_support (original)
+++ libcxx/trunk/include/__threading_support Fri Oct 14 08:56:58 2016
@@ -19,20 +19,18 @@
 
 #ifndef _LIBCPP_HAS_NO_THREADS
 
-// These checks are carefully arranged so as not to trigger a gcc pre-processor
-// defect which causes it to fail to parse the __has_include check below, the
-// redundancy is intentional.
-#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
-#if !defined(__clang__) && (_GNUC_VER < 500)
-#include <__external_threading>
-#define _LIBCPP_HAS_EXTERNAL_THREADING_HEADER
-#elif !defined(__has_include) || __has_include(<__external_threading>)
-#include <__external_threading>
-#define _LIBCPP_HAS_EXTERNAL_THREADING_HEADER
-#endif
+#ifndef __libcpp_has_include
+  #ifndef __has_include
+#define __libcpp_has_include(x) 0
+  #else
+#define __libcpp_has_include(x) __has_include(x)
+  #endif
 #endif
 
-#if !defined(_LIBCPP_HAS_EXTERNAL_THREADING_HEADER)
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) && \
+__libcpp_has_include(<__external_threading>)
+#include <__external_threading>
+#else
 #include 
 #include 
 
@@ -241,7 +239,7 @@ void __libcpp_tls_set(__libcpp_tls_key _
 
 _LIBCPP_END_NAMESPACE_STD
 
-#endif // !_LIBCPP_HAS_EXTERNAL_THREADING_HEADER
+#endif // !_LIBCPP_HAS_THREAD_API_EXTERNAL || 
!__libcpp_has_include(<__external_threading>)
 
 #endif // _LIBCPP_HAS_NO_THREADS
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24864: [libcxxabi] Refactor pthread usage into a separate API

2016-10-14 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

In https://reviews.llvm.org/D24864#570924, @vitalybuka wrote:

> So there is:
>
> - Looking for __cxa_thread_atexit_impl in c
> - Looking for __cxa_thread_atexit_impl in c - not found
>
>   and libcxx is configured with -DLIBCXX_ENABLE_THREADS=OFF


I think, the problem here is that `cxa_thread_atexit.cpp` is not properly 
guarded against the non-threaded use-case. If you look at the source prior to 
this patch, it refers to `pthread.h` and `pthread_key_t` unconditionally, it 
may have worked because pthread was somehow linked in.

The fix should be fairly straightforward. I will do a patch tomorrow (bit late 
in the day here), hope that's OK?

Cheers,

/ Asiri


https://reviews.llvm.org/D24864



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24864: [libcxxabi] Refactor pthread usage into a separate API

2016-10-14 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

In https://reviews.llvm.org/D24864#570935, @vitalybuka wrote:

> Maybe?
>
>   - if (UNIX AND NOT (APPLE OR CYGWIN))
>   + if (LIBCXXABI_ENABLE_THREADS AND UNIX AND NOT (APPLE OR CYGWIN))
>   list(APPEND LIBCXXABI_SOURCES cxa_thread_atexit.cpp)
>   endif()
>


Yes!

I was just about to say I don't know why it's even trying to build this, given 
that the library is configured with `-DLIBCXXABI_ENABLE_THREADS=OFF`.

Feel free to commit a fix :)

Cheers,

/ Asiri


https://reviews.llvm.org/D24864



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24864: [libcxxabi] Refactor pthread usage into a separate API

2016-10-14 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

In https://reviews.llvm.org/D24864#570954, @vitalybuka wrote:

> Thanks, done https://reviews.llvm.org/D25636


Thanks for the fix!

/ Asiri


https://reviews.llvm.org/D24864



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r290878 - [libcxx] Fix testing of the externally-threaded library build

2017-01-03 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Tue Jan  3 05:32:31 2017
New Revision: 290878

URL: http://llvm.org/viewvc/llvm-project?rev=290878&view=rev
Log:
[libcxx] Fix testing of the externally-threaded library build
 after r290850

Before r290850, building libcxx with -DLIBCXX_HAS_EXTERNAL_THREAD_API=ON had two
uses:
  - Allow platform vendors to plug-in an __external_threading header which
should take care of the entire threading infrastructure of libcxx

  - Allow testing of an externally-threaded library build; where the thread API
is declared using pthread data structures, and the implementation of this
API is provided as a separate library (test/support/external_threads.cpp)
   and linked-in when running the test suite.

r290850 breaks the second use case (pthread data structures are no longer
available). This patch re-stores the ability to build+test an
externally-threaded library variant on a pthread based system.

Modified:
libcxx/trunk/include/__threading_support
libcxx/trunk/test/support/external_threads.cpp

Modified: libcxx/trunk/include/__threading_support
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__threading_support?rev=290878&r1=290877&r2=290878&view=diff
==
--- libcxx/trunk/include/__threading_support (original)
+++ libcxx/trunk/include/__threading_support Tue Jan  3 05:32:31 2017
@@ -28,11 +28,23 @@
 #endif
 
 #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) && \
+!__libcpp_has_include(<__external_threading>)
+// If the <__external_threading> header is absent, build libc++ against a
+// pthread-oriented thread api but leave out its implementation. This setup
+// allows building+testing of an externally-threaded library variant (on any
+// platform that supports pthreads). Here, an 'externally-threaded' library
+// variant is one where the implementation of the libc++ thread api is provided
+// as a separate library.
+#define _LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD
+#endif
+
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) && \
 __libcpp_has_include(<__external_threading>)
 #include <__external_threading>
 #else
 
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
+defined(_LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD)
 #include 
 #include 
 #endif
@@ -45,7 +57,8 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
+defined(_LIBCPP_HAS_THREAD_API_EXTERNAL_PTHREAD)
 // Mutex
 typedef pthread_mutex_t __libcpp_mutex_t;
 #define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
@@ -134,7 +147,8 @@ void *__libcpp_tls_get(__libcpp_tls_key
 _LIBCPP_THREAD_ABI_VISIBILITY
 void __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
 
-#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
+#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
+defined(_LIBCPP_BUILDING_THREAD_API_EXTERNAL_PTHREAD)
 
 int __libcpp_recursive_mutex_init(__libcpp_mutex_t *__m)
 {

Modified: libcxx/trunk/test/support/external_threads.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/external_threads.cpp?rev=290878&r1=290877&r2=290878&view=diff
==
--- libcxx/trunk/test/support/external_threads.cpp (original)
+++ libcxx/trunk/test/support/external_threads.cpp Tue Jan  3 05:32:31 2017
@@ -6,5 +6,5 @@
 // Source Licenses. See LICENSE.TXT for details.
 //
 
//===--===//
-#define _LIBCPP_HAS_THREAD_API_PTHREAD
+#define _LIBCPP_BUILDING_THREAD_API_EXTERNAL_PTHREAD
 #include <__threading_support>


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxxabi] r290888 - [libcxxabi] Introduce an externally threaded libc++abi variant.

2017-01-03 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Tue Jan  3 06:58:34 2017
New Revision: 290888

URL: http://llvm.org/viewvc/llvm-project?rev=290888&view=rev
Log:
[libcxxabi] Introduce an externally threaded libc++abi variant.

r281179 Introduced an externally threaded variant of the libc++ library. This
patch adds support for a similar library variant for libc++abi.

Differential revision: https://reviews.llvm.org/D27575

Reviewers: EricWF

Removed:
libcxxabi/trunk/src/threading_support.h
Modified:
libcxxabi/trunk/CMakeLists.txt
libcxxabi/trunk/src/config.h
libcxxabi/trunk/src/cxa_exception.cpp
libcxxabi/trunk/src/cxa_exception_storage.cpp
libcxxabi/trunk/src/cxa_guard.cpp
libcxxabi/trunk/src/cxa_thread_atexit.cpp
libcxxabi/trunk/src/fallback_malloc.cpp
libcxxabi/trunk/test/CMakeLists.txt
libcxxabi/trunk/test/libcxxabi/test/config.py
libcxxabi/trunk/test/lit.site.cfg.in
libcxxabi/trunk/test/test_exception_storage.pass.cpp
libcxxabi/trunk/test/test_fallback_malloc.pass.cpp

Modified: libcxxabi/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/CMakeLists.txt?rev=290888&r1=290887&r2=290888&view=diff
==
--- libcxxabi/trunk/CMakeLists.txt (original)
+++ libcxxabi/trunk/CMakeLists.txt Tue Jan  3 06:58:34 2017
@@ -118,6 +118,9 @@ option(LIBCXXABI_USE_LLVM_UNWINDER "Buil
 option(LIBCXXABI_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
 option(LIBCXXABI_ENABLE_THREADS "Build with threads enabled" ON)
 option(LIBCXXABI_HAS_PTHREAD_API "Ignore auto-detection and force use of 
pthread API" OFF)
+option(LIBCXXABI_HAS_EXTERNAL_THREAD_API
+  "Build libc++abi with an externalized threading API.
+  This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON." OFF)
 option(LIBCXXABI_BUILD_32_BITS "Build 32 bit libc++abi." ${LLVM_BUILD_32_BITS})
 set(LIBCXXABI_TARGET_TRIPLE "" CACHE STRING "Target triple for cross 
compiling.")
 set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
@@ -347,20 +350,46 @@ if (NOT LIBCXXABI_ENABLE_SHARED)
   list(APPEND LIBCXXABI_COMPILE_FLAGS -D_LIBCPP_BUILD_STATIC)
 endif()
 
+# Threading
 if (NOT LIBCXXABI_ENABLE_THREADS)
   if (LIBCXXABI_HAS_PTHREAD_API)
 message(FATAL_ERROR "LIBCXXABI_HAS_PTHREAD_API can only"
 " be set to ON when LIBCXXABI_ENABLE_THREADS"
 " is also set to ON.")
   endif()
+  if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
+message(FATAL_ERROR "LIBCXXABI_HAS_EXTERNAL_THREAD_API can only"
+" be set to ON when LIBCXXABI_ENABLE_THREADS"
+" is also set to ON.")
+  endif()
   add_definitions(-D_LIBCXXABI_HAS_NO_THREADS)
 endif()
 
+if (LIBCXXABI_HAS_PTHREAD_API AND LIBCXXABI_HAS_EXTERNAL_THREAD_API)
+  message(FATAL_ERROR "The options LIBCXXABI_HAS_EXTERNAL_THREAD_API"
+  "and LIBCXXABI_HAS_PTHREAD_API cannot be both"
+  "set to ON at the same time.")
+endif()
+
+if (LIBCXXABI_HAS_EXTERNAL_THREAD_API AND LIBCXXABI_ENABLE_SHARED)
+  # Need to allow unresolved symbols if this is to work with shared library 
builds
+  if (APPLE)
+add_link_flags("-undefined dynamic_lookup")
+  else()
+# Relax this restriction from HandleLLVMOptions
+string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS 
"${CMAKE_SHARED_LINKER_FLAGS}")
+  endif()
+endif()
+
 if (LIBCXXABI_HAS_PTHREAD_API)
   add_definitions(-D_LIBCPP_HAS_THREAD_API_PTHREAD)
   add_definitions(-D_LIBCXXABI_USE_THREAD_API_PTHREAD)
 endif()
 
+if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
+  add_definitions(-D_LIBCXXABI_HAS_THREAD_API_EXTERNAL)
+endif()
+
 if (MSVC)
   add_definitions(-D_CRT_SECURE_NO_WARNINGS)
 endif()

Modified: libcxxabi/trunk/src/config.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/config.h?rev=290888&r1=290887&r2=290888&view=diff
==
--- libcxxabi/trunk/src/config.h (original)
+++ libcxxabi/trunk/src/config.h Tue Jan  3 06:58:34 2017
@@ -42,6 +42,7 @@
 
 // Try and deduce a threading api if one has not been explicitly set.
 #if !defined(_LIBCXXABI_HAS_NO_THREADS) && \
+!defined(_LIBCXXABI_HAS_THREAD_API_EXTERNAL) && \
 !defined(_LIBCXXABI_USE_THREAD_API_PTHREAD)
   #if defined(_POSIX_THREADS) && _POSIX_THREADS >= 0
 #define _LIBCXXABI_USE_THREAD_API_PTHREAD

Modified: libcxxabi/trunk/src/cxa_exception.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception.cpp?rev=290888&r1=290887&r2=290888&view=diff
==
--- libcxxabi/trunk/src/cxa_exception.cpp (original)
+++ libcxxabi/trunk/src/cxa_exception.cpp Tue Jan  3 06:58:34 2017
@@ -12,7 +12,6 @@
 
//===--===//
 
 #include "config.h"
-#include "threading_support.h"
 #include "cxxabi.h"
 
 #incl

[libcxx] r290889 - [libcxx] Add build/test support for the externally threaded libc++abi variant

2017-01-03 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Tue Jan  3 06:59:50 2017
New Revision: 290889

URL: http://llvm.org/viewvc/llvm-project?rev=290889&view=rev
Log:
[libcxx] Add build/test support for the externally threaded libc++abi variant

Differential revision: https://reviews.llvm.org/D27576

Reviewers: EricWF

Modified:
libcxx/trunk/CMakeLists.txt
libcxx/trunk/include/__threading_support
libcxx/trunk/test/CMakeLists.txt
libcxx/trunk/test/libcxx/test/config.py
libcxx/trunk/test/lit.site.cfg.in

Modified: libcxx/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=290889&r1=290888&r2=290889&view=diff
==
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Tue Jan  3 06:59:50 2017
@@ -221,14 +221,21 @@ if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_
   " when LIBCXX_ENABLE_THREADS is also set to OFF.")
 endif()
 
-if(LIBCXX_HAS_PTHREAD_API AND NOT LIBCXX_ENABLE_THREADS)
-  message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
-  " when LIBCXX_ENABLE_THREADS is also set to ON.")
+if(NOT LIBCXX_ENABLE_THREADS)
+  if(LIBCXX_HAS_PTHREAD_API)
+message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
+" when LIBCXX_ENABLE_THREADS is also set to ON.")
+  endif()
+  if(LIBCXX_HAS_EXTERNAL_THREAD_API)
+message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON"
+" when LIBCXX_ENABLE_THREADS is also set to ON.")
+  endif()
 endif()
 
-if(LIBCXX_HAS_EXTERNAL_THREAD_API AND NOT LIBCXX_ENABLE_THREADS)
-  message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON"
-  " when LIBCXX_ENABLE_THREADS is also set to ON.")
+if(LIBCXX_HAS_PTHREAD_API AND LIBCXX_HAS_EXTERNAL_THREAD_API)
+  message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
+  "and LIBCXX_HAS_PTHREAD_API cannot be both"
+  "set to ON at the same time.")
 endif()
 
 # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE

Modified: libcxx/trunk/include/__threading_support
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__threading_support?rev=290889&r1=290888&r2=290889&view=diff
==
--- libcxx/trunk/include/__threading_support (original)
+++ libcxx/trunk/include/__threading_support Tue Jan  3 06:59:50 2017
@@ -67,7 +67,11 @@ typedef pthread_mutex_t __libcpp_mutex_t
 typedef pthread_cond_t __libcpp_condvar_t;
 #define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
 
-// THread ID
+// Execute once
+typedef pthread_once_t __libcpp_exec_once_flag;
+#define _LIBCPP_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
+
+// Thread id
 typedef pthread_t __libcpp_thread_id;
 
 // Thread
@@ -110,7 +114,17 @@ int __libcpp_condvar_timedwait(__libcpp_
 _LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv);
 
-// Thread ID
+// Execute once
+_LIBCPP_THREAD_ABI_VISIBILITY
+int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
+  void (*init_routine)(void));
+
+// Thread id
+#if defined(__APPLE__) && !defined(__arm__)
+_LIBCPP_THREAD_ABI_VISIBILITY
+mach_port_t __libcpp_thread_get_port();
+#endif
+
 _LIBCPP_THREAD_ABI_VISIBILITY
 bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2);
 
@@ -145,7 +159,7 @@ _LIBCPP_THREAD_ABI_VISIBILITY
 void *__libcpp_tls_get(__libcpp_tls_key __key);
 
 _LIBCPP_THREAD_ABI_VISIBILITY
-void __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
+int __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
 
 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) || \
 defined(_LIBCPP_BUILDING_THREAD_API_EXTERNAL_PTHREAD)
@@ -221,6 +235,19 @@ int __libcpp_condvar_destroy(__libcpp_co
   return pthread_cond_destroy(__cv);
 }
 
+// Execute once
+int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
+  void (*init_routine)(void)) {
+  return pthread_once(flag, init_routine);
+}
+
+// Thread id
+#if defined(__APPLE__) && !defined(__arm__)
+mach_port_t __libcpp_thread_get_port() {
+return pthread_mach_thread_np(pthread_self());
+}
+#endif
+
 // Returns non-zero if the thread ids are equal, otherwise 0
 bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2)
 {
@@ -276,9 +303,9 @@ void *__libcpp_tls_get(__libcpp_tls_key
   return pthread_getspecific(__key);
 }
 
-void __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
+int __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
 {
-  pthread_setspecific(__key, __p);
+return pthread_setspecific(__key, __p);
 }
 
 #endif // _LIBCPP_HAS_THREAD_API_PTHREAD

Modified: libcxx/trunk/test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/CMakeLists.txt?rev=290889&r1=290888&r2=290889&view=diff
===

Re: [libcxx] r291331 - thread: implement sleep_for on Windows

2017-01-06 Thread Asiri Rathnayake via cfe-commits
Wouldn't it be better to introduce a __libcpp_thread_nanosleep() API call
here?

I bumped into a similar issue with a custom thread implementation and have
a downstream patch like that.

Cheers,

/ Asiri


On 7 Jan 2017 2:59 a.m., "Saleem Abdulrasool via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

Author: compnerd
Date: Fri Jan  6 20:48:30 2017
New Revision: 291331

URL: http://llvm.org/viewvc/llvm-project?rev=291331&view=rev
Log:
thread: implement sleep_for on Windows

Windows does not provide an implementation of `nanosleep`.  Round up the
time duration to the nearest ms and use `Sleep`.  Although this may
over-sleep, there is no hard real-time guarantee on the wake, so
sleeping a bit more is better than under-sleeping as it within the
specification.

Modified:
libcxx/trunk/src/thread.cpp

Modified: libcxx/trunk/src/thread.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/
thread.cpp?rev=291331&r1=291330&r2=291331&view=diff

==
--- libcxx/trunk/src/thread.cpp (original)
+++ libcxx/trunk/src/thread.cpp Fri Jan  6 20:48:30 2017
@@ -117,6 +117,12 @@ sleep_for(const chrono::nanoseconds& ns)
 using namespace chrono;
 if (ns > nanoseconds::zero())
 {
+#if defined(_LIBCPP_WIN32API)
+milliseconds ms = duration_cast(ns);
+if (ns > duration_cast(ms))
+  ++ms;
+Sleep(ms.count());
+#else
 seconds s = duration_cast(ns);
 timespec ts;
 typedef decltype(ts.tv_sec) ts_sec;
@@ -134,6 +140,7 @@ sleep_for(const chrono::nanoseconds& ns)

 while (nanosleep(&ts, &ts) == -1 && errno == EINTR)
 ;
+#endif
 }
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [libcxx] r291331 - thread: implement sleep_for on Windows

2017-01-07 Thread Asiri Rathnayake via cfe-commits
Yup, that sounds better.

I'll put up a patch soon.

Cheers,

/ Asiri

On 7 Jan 2017 9:18 p.m., "Saleem Abdulrasool"  wrote:

> I would really rather not introduce a `__libcpp_thread_nanosleep`.
> Different systems may have different granularities for their sleep.  A
> `__libcpp_sleep_for(std::chrono::duration)` sounds reasonable however.
>
> On Fri, Jan 6, 2017 at 11:53 PM, Asiri Rathnayake <
> asiri.rathnay...@gmail.com> wrote:
>
>> Wouldn't it be better to introduce a __libcpp_thread_nanosleep() API call
>> here?
>>
>> I bumped into a similar issue with a custom thread implementation and
>> have a downstream patch like that.
>>
>> Cheers,
>>
>> / Asiri
>>
>>
>> On 7 Jan 2017 2:59 a.m., "Saleem Abdulrasool via cfe-commits" <
>> cfe-commits@lists.llvm.org> wrote:
>>
>> Author: compnerd
>> Date: Fri Jan  6 20:48:30 2017
>> New Revision: 291331
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=291331&view=rev
>> Log:
>> thread: implement sleep_for on Windows
>>
>> Windows does not provide an implementation of `nanosleep`.  Round up the
>> time duration to the nearest ms and use `Sleep`.  Although this may
>> over-sleep, there is no hard real-time guarantee on the wake, so
>> sleeping a bit more is better than under-sleeping as it within the
>> specification.
>>
>> Modified:
>> libcxx/trunk/src/thread.cpp
>>
>> Modified: libcxx/trunk/src/thread.cpp
>> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/thread.
>> cpp?rev=291331&r1=291330&r2=291331&view=diff
>> 
>> ==
>> --- libcxx/trunk/src/thread.cpp (original)
>> +++ libcxx/trunk/src/thread.cpp Fri Jan  6 20:48:30 2017
>> @@ -117,6 +117,12 @@ sleep_for(const chrono::nanoseconds& ns)
>>  using namespace chrono;
>>  if (ns > nanoseconds::zero())
>>  {
>> +#if defined(_LIBCPP_WIN32API)
>> +milliseconds ms = duration_cast(ns);
>> +if (ns > duration_cast(ms))
>> +  ++ms;
>> +Sleep(ms.count());
>> +#else
>>  seconds s = duration_cast(ns);
>>  timespec ts;
>>  typedef decltype(ts.tv_sec) ts_sec;
>> @@ -134,6 +140,7 @@ sleep_for(const chrono::nanoseconds& ns)
>>
>>  while (nanosleep(&ts, &ts) == -1 && errno == EINTR)
>>  ;
>> +#endif
>>  }
>>  }
>>
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>>
>>
>
>
> --
> Saleem Abdulrasool
> compnerd (at) compnerd (dot) org
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r291433 - [libcxx] Fix externally-threaded shared library builds after r291275.

2017-01-09 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Mon Jan  9 04:38:56 2017
New Revision: 291433

URL: http://llvm.org/viewvc/llvm-project?rev=291433&view=rev
Log:
[libcxx] Fix externally-threaded shared library builds after r291275.

Need to allow unresolved symbols in the dylib. This was previously done for
LIBCXX_HAS_EXTERNAL_THREAD_API, but we have since split that into two with
LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY being the externally-threaded variant.

Also a minor CMakeLists.txt cleanup.

Modified:
libcxx/trunk/CMakeLists.txt

Modified: libcxx/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=291433&r1=291432&r2=291433&view=diff
==
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Mon Jan  9 04:38:56 2017
@@ -245,16 +245,17 @@ if(NOT LIBCXX_ENABLE_THREADS)
 
 endif()
 
-if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXX_HAS_EXTERNAL_THREAD_API)
-  message(FATAL_ERROR "The options LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY and "
-  "LIBCXX_HAS_EXTERNAL_THREAD_API cannot both be ON at "
-  "the same time")
-endif()
-
-if(LIBCXX_HAS_PTHREAD_API AND LIBCXX_HAS_EXTERNAL_THREAD_API)
-  message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
-  "and LIBCXX_HAS_PTHREAD_API cannot be both"
-  "set to ON at the same time.")
+if (LIBCXX_HAS_EXTERNAL_THREAD_API)
+  if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY)
+message(FATAL_ERROR "The options LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY and "
+"LIBCXX_HAS_EXTERNAL_THREAD_API cannot both be ON at "
+"the same time")
+  endif()
+  if (LIBCXX_HAS_PTHREAD_API)
+message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
+"and LIBCXX_HAS_PTHREAD_API cannot be both"
+"set to ON at the same time.")
+  endif()
 endif()
 
 # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE
@@ -460,7 +461,7 @@ if (NOT LIBCXX_ENABLE_RTTI)
 endif()
 
 # Threading flags =
-if (LIBCXX_HAS_EXTERNAL_THREAD_API AND LIBCXX_ENABLE_SHARED)
+if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXX_ENABLE_SHARED)
   # Need to allow unresolved symbols if this is to work with shared library 
builds
   if (APPLE)
 add_link_flags("-undefined dynamic_lookup")


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxxabi] r291440 - [libcxxabi] Cleanup and adapt for r291275. NFC.

2017-01-09 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Mon Jan  9 05:57:21 2017
New Revision: 291440

URL: http://llvm.org/viewvc/llvm-project?rev=291440&view=rev
Log:
[libcxxabi] Cleanup and adapt for r291275. NFC.

+ Now that libcxxabi shares the same threading API as libcxx, a whole
  chunk of code in src/config.h is made redundant (I missed this earlier).

+ r291275 split off the externalized-thread-api libcxx configuration from the
  external-thread-library libcxx configuration. libcxxabi should follow the
  same approach.

Modified:
libcxxabi/trunk/CMakeLists.txt
libcxxabi/trunk/src/config.h
libcxxabi/trunk/test/CMakeLists.txt
libcxxabi/trunk/test/lit.site.cfg.in

Modified: libcxxabi/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/CMakeLists.txt?rev=291440&r1=291439&r2=291440&view=diff
==
--- libcxxabi/trunk/CMakeLists.txt (original)
+++ libcxxabi/trunk/CMakeLists.txt Mon Jan  9 05:57:21 2017
@@ -125,6 +125,9 @@ option(LIBCXXABI_HAS_PTHREAD_API "Ignore
 option(LIBCXXABI_HAS_EXTERNAL_THREAD_API
   "Build libc++abi with an externalized threading API.
   This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON." OFF)
+option(LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY
+  "Build libc++abi with an externalized threading library.
+   This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON" OFF)
 option(LIBCXXABI_BUILD_32_BITS "Build 32 bit libc++abi." ${LLVM_BUILD_32_BITS})
 option(LIBCXXABI_INCLUDE_TESTS "Generate build targets for the libc++abi unit 
tests." ${LLVM_INCLUDE_TESTS})
 set(LIBCXXABI_TARGET_TRIPLE "" CACHE STRING "Target triple for cross 
compiling.")
@@ -367,16 +370,28 @@ if (NOT LIBCXXABI_ENABLE_THREADS)
 " be set to ON when LIBCXXABI_ENABLE_THREADS"
 " is also set to ON.")
   endif()
+  if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
+message(FATAL_ERROR "LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY can only"
+" be set to ON when LIBCXXABI_ENABLE_THREADS"
+" is also set to ON.")
+  endif()
   add_definitions(-D_LIBCXXABI_HAS_NO_THREADS)
 endif()
 
-if (LIBCXXABI_HAS_PTHREAD_API AND LIBCXXABI_HAS_EXTERNAL_THREAD_API)
-  message(FATAL_ERROR "The options LIBCXXABI_HAS_EXTERNAL_THREAD_API"
-  "and LIBCXXABI_HAS_PTHREAD_API cannot be both"
-  "set to ON at the same time.")
+if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
+  if (LIBCXXABI_HAS_PTHREAD_API)
+message(FATAL_ERROR "The options LIBCXXABI_HAS_EXTERNAL_THREAD_API"
+" and LIBCXXABI_HAS_PTHREAD_API cannot be both"
+" set to ON at the same time.")
+  endif()
+  if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
+message(FATAL_ERROR "The options LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY"
+" and LIBCXXABI_HAS_EXTERNAL_THREAD_API cannot be both"
+" set to ON at the same time.")
+  endif()
 endif()
 
-if (LIBCXXABI_HAS_EXTERNAL_THREAD_API AND LIBCXXABI_ENABLE_SHARED)
+if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY AND LIBCXXABI_ENABLE_SHARED)
   # Need to allow unresolved symbols if this is to work with shared library 
builds
   if (APPLE)
 add_link_flags("-undefined dynamic_lookup")
@@ -388,11 +403,14 @@ endif()
 
 if (LIBCXXABI_HAS_PTHREAD_API)
   add_definitions(-D_LIBCPP_HAS_THREAD_API_PTHREAD)
-  add_definitions(-D_LIBCXXABI_USE_THREAD_API_PTHREAD)
 endif()
 
 if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
-  add_definitions(-D_LIBCXXABI_HAS_THREAD_API_EXTERNAL)
+  add_definitions(-D_LIBCPP_HAS_THREAD_API_EXTERNAL)
+endif()
+
+if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
+  add_definitions(-D_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL)
 endif()
 
 if (MSVC)

Modified: libcxxabi/trunk/src/config.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/config.h?rev=291440&r1=291439&r2=291440&view=diff
==
--- libcxxabi/trunk/src/config.h (original)
+++ libcxxabi/trunk/src/config.h Mon Jan  9 05:57:21 2017
@@ -16,41 +16,6 @@
 
 #include 
 
-#ifndef __has_attribute
-  #define __has_attribute(x) 0
-#endif
-
-// Configure inline visibility attributes
-#if defined(_WIN32)
- #if defined(_MSC_VER) && !defined(__clang__)
-  // Using Microsoft Visual C++ compiler
-  #define _LIBCXXABI_INLINE_VISIBILITY __forceinline
- #else
-  #if __has_attribute(__internal_linkage__)
-   #define _LIBCXXABI_INLINE_VISIBILITY __attribute__ ((__internal_linkage__, 
__always_inline__))
-  #else
-   #define _LIBCXXABI_INLINE_VISIBILITY __attribute__ ((__always_inline__))
-  #endif
- #endif
-#else
- #if __has_attribute(__internal_linkage__)
-  #define _LIBCXXABI_INLINE_VISIBILITY __attribute__ ((__internal_linkage__, 
__always_inline__))
- #else
-  #define _LIBCXXABI_INLINE_VISIBILITY __attribute__ 
((__visibility__("hidden"), __always_inline__))
- #endif
-#endif
-
-// Try and deduce a t

Re: [PATCH] D21968: [libcxx] Externally threaded libc++ variant - Take 2

2016-08-19 Thread Asiri Rathnayake via cfe-commits
rmaprath added inline comments.


Comment at: CMakeLists.txt:139
@@ -138,1 +138,3 @@
 option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread 
API" OFF)
+option(LIBCXX_HAS_EXTERNAL_THREAD_API
+  "Build libc++ with an externalized threading API.

compnerd wrote:
> Can you use `cmake_dependent_option` here instead please?
I have two problems with this: 
* Currently we don't use the `CMakeDepedentOption` module anywhere else in the 
llvm project
* This option silently forces the cmake switch in question to the `FORCE` 
(last) argument  when the dependency in question is not satisfied. Our current 
approach on the other hand is to issue an error to the user indicating the 
incompatible options (see hunk below).

I'm slightly leaning towards keeping the current approach. @EricWF: WDYT?




Comment at: include/__config:830
@@ -829,1 +829,3 @@
+!defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
+!defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 # if defined(__FreeBSD__) || \

compnerd wrote:
> clang-format?
Running `clang-format -style=llvm` on this file shows that it's going to do a 
lot of changes to it. Do we want that? Perhaps it should be a separate patch?

Not sure if this is what you meant.


https://reviews.llvm.org/D21968



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21968: [libcxx] Externally threaded libc++ variant - Take 2

2016-08-19 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

@compnerd: I plan to look at https://reviews.llvm.org/D18482 soon (going to 
need it when this lands). Got moved to a new machine, still setting up the 
environment :)

@mclow.lists: Ping?


https://reviews.llvm.org/D21968



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21968: [libcxx] Externally threaded libc++ variant - Take 2

2016-08-22 Thread Asiri Rathnayake via cfe-commits
rmaprath added inline comments.


Comment at: include/__external_threading:26
@@ +25,3 @@
+
+#if !defined(_LIBCPP_MUTEX_T) || \
+!defined(_LIBCPP_MUTEX_INITIALIZER) || \

mclow.lists wrote:
> bcraig wrote:
> > So users of external pthreading (or their compiler driver) would need to 
> > provide a pile of -D options on the command line?  Or is it expected that 
> > users will have their own __external_threading header that comes earlier in 
> > the include path?  Please document your expectation.
> My expectation is that system vendors who have a different threading 
> implementation will ship a customized version of the libc++ headers and 
> dylib. 
> 
> The headers will include a replacement `include/__external_threading`, and a 
> modified `include/__config` that contains additional `#define`s
> 
> What this patch does is to provide a customization point to produce such 
> libraries.
> 
This is correct.

With the latest revision, I (following @bcraig's comments) have made this a bit 
more simpler; system vendors can simply drop in the header 
`include/__external_threading` to override the default threading 
implementation. When this header is provided (and 
`_LIBCPP_HAS_THREAD_API_EXTERNAL` is defined - which is automatically wired 
into  `__config` header through `__config_site.in` at build time), the built 
library will end up using the new threading implementation.


https://reviews.llvm.org/D21968



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21968: [libcxx] Externally threaded libc++ variant - Take 2

2016-08-22 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

Comments from @mclow.lists on the latest revision (received offline):

- Need instructions on how to build and test the patch...
- Need to be able to build+test on Mac (looks like there is a small problem in 
the patch w.r.t pthreads that makes the build fail on Mac)
- Need to work on shared library builds as well

I will address these comments soon (as soon as I get familiar with how Macs 
work...)


https://reviews.llvm.org/D21968



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D23796: [libcxx] Make it possible to test static builds of libc++ on OSX

2016-08-23 Thread Asiri Rathnayake via cfe-commits
rmaprath created this revision.
rmaprath added reviewers: EricWF, mclow.lists.
rmaprath added a subscriber: cfe-commits.

Being used to doing static builds and being a complete noob to OSX, this really 
confused me.

Currently if you build `libc++` (in-tree) like so:
```
-DLIBCXX_ENABLE_SHARED=OFF -DLIBCXXABI_ENABLE_SHARED=OFF 
-DLIBUNWIND_ENABLE_SHARED=OFF
```
The `libc++` test runs will fail due to missing symbols corresponding to 
`libc++abi`. This patch should fix it.

https://reviews.llvm.org/D23796

Files:
  test/libcxx/test/target_info.py

Index: test/libcxx/test/target_info.py
===
--- test/libcxx/test/target_info.py
+++ test/libcxx/test/target_info.py
@@ -108,7 +108,12 @@
 # libc++ yet so we still need to explicitly link libc++abi when testing
 # libc++abi
 # See PR22654.
-if(self.full_config.get_lit_conf('name', '') == 'libc++abi'):
+lit_conf_name = self.full_config.get_lit_conf('name', '')
+if(lit_conf_name == 'libc++abi'):
+return True
+# Needs explicit linking of libc++abi for static libc++ builds
+if(lit_conf_name == 'libc++' and
+   not self.full_config.get_lit_bool('enable_shared', True)):
 return True
 # Don't link libc++abi explicitly on OS X because the symbols
 # should be available in libc++ directly.


Index: test/libcxx/test/target_info.py
===
--- test/libcxx/test/target_info.py
+++ test/libcxx/test/target_info.py
@@ -108,7 +108,12 @@
 # libc++ yet so we still need to explicitly link libc++abi when testing
 # libc++abi
 # See PR22654.
-if(self.full_config.get_lit_conf('name', '') == 'libc++abi'):
+lit_conf_name = self.full_config.get_lit_conf('name', '')
+if(lit_conf_name == 'libc++abi'):
+return True
+# Needs explicit linking of libc++abi for static libc++ builds
+if(lit_conf_name == 'libc++' and
+   not self.full_config.get_lit_bool('enable_shared', True)):
 return True
 # Don't link libc++abi explicitly on OS X because the symbols
 # should be available in libc++ directly.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21968: [libcxx] Externally threaded libc++ variant - Take 2

2016-08-23 Thread Asiri Rathnayake via cfe-commits
rmaprath updated this revision to Diff 69010.
rmaprath added a comment.

Addressed above comments from @mclow.lists.

Getting this to work on shared library builds was a bit tricky, had to use 
`-undefined dynamic_lookup` linker option on OSX and strip off the default 
`-Wl,-z,defs` linker option on linux.

Now this should build+test on OSX with the usual cmake options.


https://reviews.llvm.org/D21968

Files:
  CMakeLists.txt
  include/__config
  include/__config_site.in
  include/__threading_support
  lib/CMakeLists.txt
  test/CMakeLists.txt
  test/libcxx/test/config.py
  
test/libcxx/thread/thread.condition/thread.condition.condvar/native_handle.pass.cpp
  
test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/native_handle.pass.cpp
  
test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/native_handle.pass.cpp
  
test/libcxx/thread/thread.threads/thread.thread.class/thread.thread.member/native_handle.pass.cpp
  test/libcxx/thread/thread.threads/thread.thread.class/types.pass.cpp
  test/lit.site.cfg.in
  test/support/external_threads.cpp

Index: test/support/external_threads.cpp
===
--- /dev/null
+++ test/support/external_threads.cpp
@@ -0,0 +1,172 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+#ifndef SUPPORT_EXTERNAL_THREADS
+#define SUPPORT_EXTERNAL_THREADS
+
+#include <__threading_support>
+#include 
+#include 
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+//-- Mutex --//
+
+int __libcpp_recursive_mutex_init(__libcpp_mutex_t* __m)
+{
+// Initialize the allocated pthread_mutex_t object as a recursive mutex
+pthread_mutexattr_t attr;
+int __ec = pthread_mutexattr_init(&attr);
+if (__ec)
+  goto fail;
+
+__ec = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+if (__ec)
+{
+pthread_mutexattr_destroy(&attr);
+goto fail;
+}
+
+__ec = pthread_mutex_init(__m, &attr);
+if (__ec)
+{
+pthread_mutexattr_destroy(&attr);
+goto fail;
+}
+
+__ec = pthread_mutexattr_destroy(&attr);
+if (__ec)
+{
+pthread_mutex_destroy(__m);
+goto fail;
+}
+
+return 0;
+
+fail:
+return __ec;
+}
+
+int __libcpp_mutex_lock(__libcpp_mutex_t* __m)
+{
+return pthread_mutex_lock(__m);
+}
+
+int __libcpp_mutex_trylock(__libcpp_mutex_t* __m)
+{
+return pthread_mutex_trylock(__m);
+}
+
+int __libcpp_mutex_unlock(__libcpp_mutex_t* __m)
+{
+return pthread_mutex_unlock(__m);
+}
+
+int __libcpp_mutex_destroy(__libcpp_mutex_t* __m) {
+return pthread_mutex_destroy(__m);
+}
+
+//-- Condition variable --//
+
+int __libcpp_condvar_signal(__libcpp_condvar_t* __cv)
+{
+return pthread_cond_signal(__cv);
+}
+
+int __libcpp_condvar_broadcast(__libcpp_condvar_t* __cv)
+{
+return pthread_cond_broadcast(__cv);
+}
+
+int __libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m)
+{
+return pthread_cond_wait(__cv, __m);
+}
+
+int __libcpp_condvar_timedwait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m, timespec* __ts)
+{
+return pthread_cond_timedwait(__cv, __m, __ts);
+}
+
+int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv)
+{
+return pthread_cond_destroy(__cv);
+}
+
+//-- Thread --//
+
+bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2) {
+return pthread_equal(t1, t2) != 0;
+}
+
+bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2) {
+return t1 < t2;
+}
+
+int __libcpp_thread_create(__libcpp_thread_t* __t, void* (*__func)(void*), void* __arg)
+{
+return pthread_create(__t, 0, __func, __arg);
+}
+
+__libcpp_thread_id __libcpp_thread_get_current_id()
+{
+return static_cast<__libcpp_thread_id>(pthread_self());
+}
+
+__libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t* __t)
+{
+return *__t;
+}
+
+int __libcpp_thread_join(__libcpp_thread_t* __t)
+{
+// Must return non-zero if the internal state has already been invalidated
+// This can happen for example, if std::thread::join() has been called
+// before.
+if (*__t == 0)
+return -1;
+
+return pthread_join(*__t, 0);
+}
+
+int __libcpp_thread_detach(__libcpp_thread_t* __t)
+{
+// Must return non-zero if the internal state has already been invalidated
+// This can happen for example, if std::thread::detach() has been called
+// before.
+if (*__t == 0)
+return -1;
+
+return pthread_detach(*__t);
+}
+
+void __libcpp_thread_yield()
+{
+sched_yield();
+}
+
+//-- TLS --//
+
+int __libcpp_tl_create(__libcpp_tl_key* __key

Re: [libcxx] r279552 - libcxx: Fix libcxx tests on aarch64 with libunwind

2016-08-23 Thread Asiri Rathnayake via cfe-commits
Would be nice if you can also add a comment around the double-checking
of llvm_unwinder, even something along the lines of "we need libgcc to
appear both before and after... in the link order, for reasons thus far
unknown to me" is fine. Just so that anyone looking through this in the
future is at least made aware of this.

Cheers,

/ Asiri

On Tue, Aug 23, 2016 at 8:25 PM, Adhemerval Zanella via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: azanella
> Date: Tue Aug 23 14:25:12 2016
> New Revision: 279552
>
> URL: http://llvm.org/viewvc/llvm-project?rev=279552&view=rev
> Log:
> libcxx: Fix libcxx tests on aarch64 with libunwind
>
> Some tests uses 'long double' to/from conversions and for some targets
> they are provided by compiler runtime (either compiler-rt or libgcc).
> However when building libcxx with linunwinder current test configuration
> at target_info.py do not include the required libraries, as:
>
>   not llvm_unwinder:
> "-lc++" "-lm" "-lgcc_s" "-lgcc" "-lpthread" "-lc" "-lgcc_s" "-lgcc"
>
>   llvm_unwinder
> "-lc++" "-lm" "-lpthread" "-lc" "-lunwind" "-ldl"
>
> This causes some tests build issues with missing symbols on aarch64,
> for instance, where 'long double' is a binary float with 128-bits with
> mostly of internal operations being provided by software routines.
>
> This patch changes how to define the default linker flags with libunwinder
> by
> adding libgcc regardless.
>
> I checked and aarch64 and x86_64 with libcxx and libunwind (with and
> without
> LIBCXXABI_USE_LLVM_UNWINDER).
>
> Modified:
> libcxx/trunk/test/libcxx/test/target_info.py
>
> Modified: libcxx/trunk/test/libcxx/test/target_info.py
> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/
> libcxx/test/target_info.py?rev=279552&r1=279551&r2=279552&view=diff
> 
> ==
> --- libcxx/trunk/test/libcxx/test/target_info.py (original)
> +++ libcxx/trunk/test/libcxx/test/target_info.py Tue Aug 23 14:25:12 2016
> @@ -180,7 +180,8 @@ class LinuxLocalTI(DefaultTargetInfo):
>  if llvm_unwinder:
>  flags += ['-lunwind', '-ldl']
>  else:
> -flags += ['-lgcc_s', '-lgcc']
> +flags += ['-lgcc_s']
> +flags += ['-lgcc']
>  use_libatomic = self.full_config.get_lit_bool('use_libatomic',
> False)
>  if use_libatomic:
>  flags += ['-latomic']
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21968: [libcxx] Externally threaded libc++ variant - Take 2

2016-08-24 Thread Asiri Rathnayake via cfe-commits
rmaprath added inline comments.


Comment at: include/__config:830
@@ -829,1 +829,3 @@
+!defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
+!defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 # if defined(__FreeBSD__) || \

compnerd wrote:
> I meant on the lines that you added :-).
Will update to reflect rest of the source file.


Comment at: include/__threading_support:261
@@ -200,1 +260,3 @@
+void* __libcpp_tl_get(__libcpp_tl_key __key);
+void __libcpp_tl_set(__libcpp_tl_key __key, void* __p);
 

compnerd wrote:
> I think we should explicitly spell out `tls`.  The extra character won't hurt.
Will fix.


Comment at: lib/CMakeLists.txt:216
@@ +215,3 @@
+  )
+endif()
+

compnerd wrote:
> Have you considered a slightly alternative approach of basically implementing 
> pthreads as an "external" threading model as well?  You could override it, or 
> take the default implementation that is provided.  It avoids having a second 
> supporting DSO for threading as we could always statically link against it.
So, the particulars of this design was discussed and (generally) agreed upon 
sometime back.

Currently pthreads **is** hidden behind the same threading API as the 
externally threaded variant (on this patch). To override the default (pthread) 
implementation, you just have to drop in an `__external_threading` header and 
specify the `-DLIBCXX_HAS_EXTERNAL_THREAD_API` cmake option.

There's no need to provide a second DSO if your `__external_threading` header 
(and your  thread-system sources) are available at `libc++` build time.

But we have a **requirement** that the library needs to be build-able in such a 
way you can provide a second DSO holding the implementation of the API. That 
is, we need to be able to build and ship a library to which customers can 
drop-in their own thread implementation (i.e. the thread-support DSO).

Note that in one of my earlier patches, I proposed an even more de-coupled 
external threading system where even the types like `__libcpp_mutex_t` were 
opaque pointers. @mclow.lists opposed that (perhaps rightfully so, now I think 
about it) and currently these types need to be known at `libc++` compile time. 
The implementation of the API functions like `__libcpp_mutex_lock()` can be 
deferred to link time (this is what is provided in the second DSO).

Hope that clarifies everything here?








Comment at: test/support/external_threads.cpp:26
@@ +25,3 @@
+if (__ec)
+  goto fail;
+

compnerd wrote:
> I think this would be nicer as:
> 
>   if (int error = pthread_mutexattr_init(&attr))
> return error;
I think I'm following the conventions used in the `libc++` source files here. 
Will double check tomorrow.


Comment at: test/support/external_threads.cpp:52
@@ +51,3 @@
+fail:
+return __ec;
+}

compnerd wrote:
> I don't think that the label for failure is adding anything since you really 
> are handling the destruction of the mutex at all failure sites.
Not sure what I did here. Will double check and fix.


Comment at: test/support/external_threads.cpp:70
@@ +69,3 @@
+
+int __libcpp_mutex_destroy(__libcpp_mutex_t* __m) {
+return pthread_mutex_destroy(__m);

compnerd wrote:
> Please choose a single style.
Will fix.


Comment at: test/support/external_threads.cpp:103
@@ +102,3 @@
+
+bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2) {
+return pthread_equal(t1, t2) != 0;

compnerd wrote:
> Please choose a single style (and below).
Will fix.


Comment at: test/support/external_threads.cpp:131
@@ +130,3 @@
+// before.
+if (*__t == 0)
+return -1;

compnerd wrote:
> Can you compare to `nullptr` instead?
I can't remember exactly why, but I think there was a problem with using 
`nullptr` here. I will check and get back.


Comment at: test/support/external_threads.cpp:142
@@ +141,3 @@
+// before.
+if (*__t == 0)
+return -1;

compnerd wrote:
> Same.
Need to check.


https://reviews.llvm.org/D21968



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23855: Make exception-throwing from a noexcept build `abort()`.

2016-08-25 Thread Asiri Rathnayake via cfe-commits
rmaprath added a subscriber: rmaprath.
rmaprath added a comment.

I don't know how I missed this. Thanks for the patch!!!


https://reviews.llvm.org/D23855



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D23926: [libcxx] Don't use C99 math ops in -std=c++03 mode

2016-08-26 Thread Asiri Rathnayake via cfe-commits
rmaprath created this revision.
rmaprath added reviewers: mclow.lists, EricWF.
rmaprath added a subscriber: cfe-commits.

`C99` math ops should not be available when compiling in `-std=c++03` mode.

https://reviews.llvm.org/D23926

Files:
  include/math.h
  test/std/depr/depr.c.headers/math_h.pass.cpp
  test/std/numerics/c.math/cmath.pass.cpp
  test/std/numerics/complex.number/cmplx.over/proj.pass.cpp

Index: test/std/numerics/complex.number/cmplx.over/proj.pass.cpp
===
--- test/std/numerics/complex.number/cmplx.over/proj.pass.cpp
+++ test/std/numerics/complex.number/cmplx.over/proj.pass.cpp
@@ -34,16 +34,20 @@
 test(T x, typename std::enable_if::value>::type* = 0)
 {
 static_assert((std::is_same >::value), "");
+#if TEST_STD_VER > 3
 assert(std::proj(x) == proj(std::complex(x, 0)));
+#endif
 }
 
 template 
 void
 test(T x, typename std::enable_if::value &&
   !std::is_floating_point::value>::type* = 0)
 {
 static_assert((std::is_same >::value), "");
+#if TEST_STD_VER > 3
 assert(std::proj(x) == proj(std::complex(x, 0)));
+#endif
 }
 
 template 
Index: test/std/numerics/c.math/cmath.pass.cpp
===
--- test/std/numerics/c.math/cmath.pass.cpp
+++ test/std/numerics/c.math/cmath.pass.cpp
@@ -752,6 +752,8 @@
 assert(std::isunordered(-1.0, 0.F) == false);
 }
 
+#if TEST_STD_VER > 3
+
 void test_acosh()
 {
 static_assert((std::is_same::value), "");
@@ -1479,6 +1481,8 @@
 assert(std::trunc(1) == 1);
 }
 
+#endif
+
 int main()
 {
 test_abs();
@@ -1516,6 +1520,7 @@
 test_islessgreater();
 test_isnan();
 test_isunordered();
+#if TEST_STD_VER > 3
 test_acosh();
 test_asinh();
 test_atanh();
@@ -1551,4 +1556,5 @@
 test_scalbn();
 test_tgamma();
 test_trunc();
+#endif
 }
Index: test/std/depr/depr.c.headers/math_h.pass.cpp
===
--- test/std/depr/depr.c.headers/math_h.pass.cpp
+++ test/std/depr/depr.c.headers/math_h.pass.cpp
@@ -750,6 +750,8 @@
 assert(isunordered(-1.0, 0.F) == false);
 }
 
+#if TEST_STD_VER > 3
+
 void test_acosh()
 {
 static_assert((std::is_same::value), "");
@@ -1455,6 +1457,8 @@
 assert(trunc(1) == 1);
 }
 
+#endif
+
 int main()
 {
 test_abs();
@@ -1492,6 +1496,7 @@
 test_islessgreater();
 test_isnan();
 test_isunordered();
+#if TEST_STD_VER > 3
 test_acosh();
 test_asinh();
 test_atanh();
@@ -1527,4 +1532,5 @@
 test_scalbn();
 test_tgamma();
 test_trunc();
+#endif
 }
Index: include/math.h
===
--- include/math.h
+++ include/math.h
@@ -302,6 +302,10 @@
 
 #ifdef __cplusplus
 
+#if 201103L <= __cplusplus
+  #define __LIBCPP_USE_C99_MATH 1
+#endif
+
 // We support including .h headers inside 'extern "C"' contexts, so switch
 // back to C++ linkage before including these C++ headers.
 extern "C++" {
@@ -946,7 +950,7 @@
 
 // acosh
 
-#ifndef _LIBCPP_MSVCRT
+#if !defined(_LIBCPP_MSVCRT) && defined(__LIBCPP_USE_C99_MATH)
 inline _LIBCPP_INLINE_VISIBILITY float   acosh(float __lcpp_x) _NOEXCEPT   {return acoshf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double acosh(long double __lcpp_x) _NOEXCEPT {return acoshl(__lcpp_x);}
 
@@ -958,7 +962,7 @@
 
 // asinh
 
-#ifndef _LIBCPP_MSVCRT
+#if !defined(_LIBCPP_MSVCRT) && defined(__LIBCPP_USE_C99_MATH)
 inline _LIBCPP_INLINE_VISIBILITY float   asinh(float __lcpp_x) _NOEXCEPT   {return asinhf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double asinh(long double __lcpp_x) _NOEXCEPT {return asinhl(__lcpp_x);}
 
@@ -970,7 +974,7 @@
 
 // atanh
 
-#ifndef _LIBCPP_MSVCRT
+#if !defined(_LIBCPP_MSVCRT) && defined(__LIBCPP_USE_C99_MATH)
 inline _LIBCPP_INLINE_VISIBILITY float   atanh(float __lcpp_x) _NOEXCEPT   {return atanhf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double atanh(long double __lcpp_x) _NOEXCEPT {return atanhl(__lcpp_x);}
 
@@ -982,7 +986,7 @@
 
 // cbrt
 
-#ifndef _LIBCPP_MSVCRT
+#if !defined(_LIBCPP_MSVCRT) && defined(__LIBCPP_USE_C99_MATH)
 inline _LIBCPP_INLINE_VISIBILITY float   cbrt(float __lcpp_x) _NOEXCEPT   {return cbrtf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double cbrt(long double __lcpp_x) _NOEXCEPT {return cbrtl(__lcpp_x);}
 
@@ -994,7 +998,7 @@
 
 // copysign
 
-#if !defined(_VC_CRT_MAJOR_VERSION) || (_VC_CRT_MAJOR_VERSION < 12)
+#if defined(__LIBCPP_USE_C99_MATH) && (!defined(_VC_CRT_MAJOR_VERSION) || (_VC_CRT_MAJOR_VERSION < 12))
 inline _LIBCPP_INLINE_VISIBILITY float copysign(float __lcpp_x,
 float __lcpp_y) _NOEXCEPT {
   return copysignf(__lcpp_x, __lcpp_y);
@@ -1005,6 +1009,7 @@
 }
 #endif
 
+#if defined(__LIBCPP_USE_C99_MATH)
 template 
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::__lazy_enable_if
@@ -1020,9 +1025,9 @@
   

Re: [PATCH] D23926: [libcxx] Don't use C99 math ops in -std=c++03 mode

2016-08-27 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

In https://reviews.llvm.org/D23926#527080, @EricWF wrote:

> We already provide many C++11 extensions in C++03 mode, why should this be an 
> exception?


This is kind of what I wanted to find out. Do we document what those extensions 
are?

We have quite a strict C library which is picky about what it exposes under 
different standards. For example, it won't expose `C99` math ops if it is being 
used under `__cplusplus < 201103L`, which leads to compiler errors (when 
integrated with `libc++` and used with `-std=c++03`) for a simple program like:

  #include 
  int x;

We could make our C library a bit more lenient to fix this, but I couldn't find 
it documented anywhere what stand `libcxx` takes on C++03 support. I also sent 
an email to `cfe-dev` about this but didn't get much attention, so I decided to 
start with a patch instead :)

I'm happy to document these C++03 extensions on libcxx.llvm.org if I can find 
out what those extensions are. Any pointers?

Cheers,

/ Asiri


https://reviews.llvm.org/D23926



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23926: [libcxx] Don't use C99 math ops in -std=c++03 mode

2016-08-30 Thread Asiri Rathnayake via cfe-commits
rmaprath updated this revision to Diff 69710.
rmaprath added a comment.

Re-spinning a new patch to test the waters.

@EricWF: Does this approach look OK?

/ Asiri


https://reviews.llvm.org/D23926

Files:
  include/__config
  include/math.h
  test/std/depr/depr.c.headers/math_h.pass.cpp
  test/std/numerics/c.math/cmath.pass.cpp
  test/std/numerics/complex.number/cmplx.over/proj.pass.cpp

Index: test/std/numerics/complex.number/cmplx.over/proj.pass.cpp
===
--- test/std/numerics/complex.number/cmplx.over/proj.pass.cpp
+++ test/std/numerics/complex.number/cmplx.over/proj.pass.cpp
@@ -34,7 +34,9 @@
 test(T x, typename std::enable_if::value>::type* = 0)
 {
 static_assert((std::is_same >::value), "");
+#if TEST_STD_VER > 3 || !_LIBCPP_STRICT_C99_COMPATIBILITY
 assert(std::proj(x) == proj(std::complex(x, 0)));
+#endif
 }
 
 template 
@@ -43,7 +45,9 @@
   !std::is_floating_point::value>::type* = 0)
 {
 static_assert((std::is_same >::value), "");
+#if TEST_STD_VER > 3 || !_LIBCPP_STRICT_C99_COMPATIBILITY
 assert(std::proj(x) == proj(std::complex(x, 0)));
+#endif
 }
 
 template 
Index: test/std/numerics/c.math/cmath.pass.cpp
===
--- test/std/numerics/c.math/cmath.pass.cpp
+++ test/std/numerics/c.math/cmath.pass.cpp
@@ -752,6 +752,8 @@
 assert(std::isunordered(-1.0, 0.F) == false);
 }
 
+#if TEST_STD_VER > 3 || !_LIBCPP_STRICT_C99_COMPATIBILITY
+
 void test_acosh()
 {
 static_assert((std::is_same::value), "");
@@ -1479,6 +1481,8 @@
 assert(std::trunc(1) == 1);
 }
 
+#endif
+
 int main()
 {
 test_abs();
@@ -1516,6 +1520,7 @@
 test_islessgreater();
 test_isnan();
 test_isunordered();
+#if TEST_STD_VER > 3 || !_LIBCPP_STRICT_C99_COMPATIBILITY
 test_acosh();
 test_asinh();
 test_atanh();
@@ -1551,4 +1556,5 @@
 test_scalbn();
 test_tgamma();
 test_trunc();
+#endif
 }
Index: test/std/depr/depr.c.headers/math_h.pass.cpp
===
--- test/std/depr/depr.c.headers/math_h.pass.cpp
+++ test/std/depr/depr.c.headers/math_h.pass.cpp
@@ -750,6 +750,8 @@
 assert(isunordered(-1.0, 0.F) == false);
 }
 
+#if TEST_STD_VER > 3 || !_LIBCPP_STRICT_C99_COMPATIBILITY
+
 void test_acosh()
 {
 static_assert((std::is_same::value), "");
@@ -1455,6 +1457,8 @@
 assert(trunc(1) == 1);
 }
 
+#endif
+
 int main()
 {
 test_abs();
@@ -1492,6 +1496,7 @@
 test_islessgreater();
 test_isnan();
 test_isunordered();
+#if TEST_STD_VER > 3 || !_LIBCPP_STRICT_C99_COMPATIBILITY
 test_acosh();
 test_asinh();
 test_atanh();
@@ -1527,4 +1532,5 @@
 test_scalbn();
 test_tgamma();
 test_trunc();
+#endif
 }
Index: include/math.h
===
--- include/math.h
+++ include/math.h
@@ -302,6 +302,10 @@
 
 #ifdef __cplusplus
 
+#if __cplusplus >= 201103L || !_LIBCPP_STRICT_C99_COMPATIBILITY
+  #define __LIBCPP_USE_C99_MATH
+#endif
+
 // We support including .h headers inside 'extern "C"' contexts, so switch
 // back to C++ linkage before including these C++ headers.
 extern "C++" {
@@ -946,7 +950,7 @@
 
 // acosh
 
-#ifndef _LIBCPP_MSVCRT
+#if !defined(_LIBCPP_MSVCRT) && defined(__LIBCPP_USE_C99_MATH)
 inline _LIBCPP_INLINE_VISIBILITY float   acosh(float __lcpp_x) _NOEXCEPT   {return acoshf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double acosh(long double __lcpp_x) _NOEXCEPT {return acoshl(__lcpp_x);}
 
@@ -958,7 +962,7 @@
 
 // asinh
 
-#ifndef _LIBCPP_MSVCRT
+#if !defined(_LIBCPP_MSVCRT) && defined(__LIBCPP_USE_C99_MATH)
 inline _LIBCPP_INLINE_VISIBILITY float   asinh(float __lcpp_x) _NOEXCEPT   {return asinhf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double asinh(long double __lcpp_x) _NOEXCEPT {return asinhl(__lcpp_x);}
 
@@ -970,7 +974,7 @@
 
 // atanh
 
-#ifndef _LIBCPP_MSVCRT
+#if !defined(_LIBCPP_MSVCRT) && defined(__LIBCPP_USE_C99_MATH)
 inline _LIBCPP_INLINE_VISIBILITY float   atanh(float __lcpp_x) _NOEXCEPT   {return atanhf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double atanh(long double __lcpp_x) _NOEXCEPT {return atanhl(__lcpp_x);}
 
@@ -982,7 +986,7 @@
 
 // cbrt
 
-#ifndef _LIBCPP_MSVCRT
+#if !defined(_LIBCPP_MSVCRT) && defined(__LIBCPP_USE_C99_MATH)
 inline _LIBCPP_INLINE_VISIBILITY float   cbrt(float __lcpp_x) _NOEXCEPT   {return cbrtf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double cbrt(long double __lcpp_x) _NOEXCEPT {return cbrtl(__lcpp_x);}
 
@@ -994,7 +998,7 @@
 
 // copysign
 
-#if !defined(_VC_CRT_MAJOR_VERSION) || (_VC_CRT_MAJOR_VERSION < 12)
+#if defined(__LIBCPP_USE_C99_MATH) && (!defined(_VC_CRT_MAJOR_VERSION) || (_VC_CRT_MAJOR_VERSION < 12))
 inline _LIBCPP_INLINE_VISIBILITY float copysign(float __lcpp_x,
 float __lcpp_y) _NOEXCEPT {
   ret

Re: [PATCH] D23926: [libcxx] Don't use C99 math ops in -std=c++03 mode

2016-09-01 Thread Asiri Rathnayake via cfe-commits
rmaprath updated this revision to Diff 69962.
rmaprath added a comment.

Simplified the patch a little bit more.

Now, library vendors should be able to define 
`_LIBCPP_STRICT_C99_COMPATIBILITY` and `libc++` will not use/test C99 math 
functions in `C++03/98` modes. Currently it's only the math functions, we can 
extend this approach to other affected areas if the approach is OK. Not 100% 
sure about the namings, can change them as needed.

@EricWF: Gentle ping.


https://reviews.llvm.org/D23926

Files:
  include/__config
  include/math.h
  test/std/depr/depr.c.headers/math_h.pass.cpp
  test/std/numerics/c.math/cmath.pass.cpp
  test/std/numerics/complex.number/cmplx.over/proj.pass.cpp

Index: test/std/numerics/complex.number/cmplx.over/proj.pass.cpp
===
--- test/std/numerics/complex.number/cmplx.over/proj.pass.cpp
+++ test/std/numerics/complex.number/cmplx.over/proj.pass.cpp
@@ -34,7 +34,9 @@
 test(T x, typename std::enable_if::value>::type* = 0)
 {
 static_assert((std::is_same >::value), "");
+#if _LIBCPP_USE_C99
 assert(std::proj(x) == proj(std::complex(x, 0)));
+#endif
 }
 
 template 
@@ -43,7 +45,9 @@
   !std::is_floating_point::value>::type* = 0)
 {
 static_assert((std::is_same >::value), "");
+#if _LIBCPP_USE_C99
 assert(std::proj(x) == proj(std::complex(x, 0)));
+#endif
 }
 
 template 
Index: test/std/numerics/c.math/cmath.pass.cpp
===
--- test/std/numerics/c.math/cmath.pass.cpp
+++ test/std/numerics/c.math/cmath.pass.cpp
@@ -752,6 +752,8 @@
 assert(std::isunordered(-1.0, 0.F) == false);
 }
 
+#if _LIBCPP_USE_C99
+
 void test_acosh()
 {
 static_assert((std::is_same::value), "");
@@ -1479,6 +1481,8 @@
 assert(std::trunc(1) == 1);
 }
 
+#endif
+
 int main()
 {
 test_abs();
@@ -1516,6 +1520,7 @@
 test_islessgreater();
 test_isnan();
 test_isunordered();
+#if _LIBCPP_USE_C99
 test_acosh();
 test_asinh();
 test_atanh();
@@ -1551,4 +1556,5 @@
 test_scalbn();
 test_tgamma();
 test_trunc();
+#endif
 }
Index: test/std/depr/depr.c.headers/math_h.pass.cpp
===
--- test/std/depr/depr.c.headers/math_h.pass.cpp
+++ test/std/depr/depr.c.headers/math_h.pass.cpp
@@ -750,6 +750,8 @@
 assert(isunordered(-1.0, 0.F) == false);
 }
 
+#if _LIBCPP_USE_C99
+
 void test_acosh()
 {
 static_assert((std::is_same::value), "");
@@ -1455,6 +1457,8 @@
 assert(trunc(1) == 1);
 }
 
+#endif
+
 int main()
 {
 test_abs();
@@ -1492,6 +1496,7 @@
 test_islessgreater();
 test_isnan();
 test_isunordered();
+#if _LIBCPP_USE_C99
 test_acosh();
 test_asinh();
 test_atanh();
@@ -1527,4 +1532,5 @@
 test_scalbn();
 test_tgamma();
 test_trunc();
+#endif
 }
Index: include/math.h
===
--- include/math.h
+++ include/math.h
@@ -946,7 +946,7 @@
 
 // acosh
 
-#ifndef _LIBCPP_MSVCRT
+#if !defined(_LIBCPP_MSVCRT) && _LIBCPP_USE_C99
 inline _LIBCPP_INLINE_VISIBILITY float   acosh(float __lcpp_x) _NOEXCEPT   {return acoshf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double acosh(long double __lcpp_x) _NOEXCEPT {return acoshl(__lcpp_x);}
 
@@ -958,7 +958,7 @@
 
 // asinh
 
-#ifndef _LIBCPP_MSVCRT
+#if !defined(_LIBCPP_MSVCRT) && _LIBCPP_USE_C99
 inline _LIBCPP_INLINE_VISIBILITY float   asinh(float __lcpp_x) _NOEXCEPT   {return asinhf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double asinh(long double __lcpp_x) _NOEXCEPT {return asinhl(__lcpp_x);}
 
@@ -970,7 +970,7 @@
 
 // atanh
 
-#ifndef _LIBCPP_MSVCRT
+#if !defined(_LIBCPP_MSVCRT) && _LIBCPP_USE_C99
 inline _LIBCPP_INLINE_VISIBILITY float   atanh(float __lcpp_x) _NOEXCEPT   {return atanhf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double atanh(long double __lcpp_x) _NOEXCEPT {return atanhl(__lcpp_x);}
 
@@ -982,7 +982,7 @@
 
 // cbrt
 
-#ifndef _LIBCPP_MSVCRT
+#if !defined(_LIBCPP_MSVCRT) && _LIBCPP_USE_C99
 inline _LIBCPP_INLINE_VISIBILITY float   cbrt(float __lcpp_x) _NOEXCEPT   {return cbrtf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double cbrt(long double __lcpp_x) _NOEXCEPT {return cbrtl(__lcpp_x);}
 
@@ -994,7 +994,7 @@
 
 // copysign
 
-#if !defined(_VC_CRT_MAJOR_VERSION) || (_VC_CRT_MAJOR_VERSION < 12)
+#if _LIBCPP_USE_C99 && (!defined(_VC_CRT_MAJOR_VERSION) || (_VC_CRT_MAJOR_VERSION < 12))
 inline _LIBCPP_INLINE_VISIBILITY float copysign(float __lcpp_x,
 float __lcpp_y) _NOEXCEPT {
   return copysignf(__lcpp_x, __lcpp_y);
@@ -1005,6 +1005,7 @@
 }
 #endif
 
+#if _LIBCPP_USE_C99
 template 
 inline _LIBCPP_INLINE_VISIBILITY
 typename std::__lazy_enable_if
@@ -1020,9 +1021,9 @@
  std::is_same<_A2, __result_type>::value)), "");
 return copysign((__result_type)__lcpp_x

Re: [PATCH] D23926: [libcxx] Don't use C99 math ops in -std=c++03 mode

2016-09-03 Thread Asiri Rathnayake via cfe-commits
@Eric: Ping?
On 1 Sep 2016 11:33, "Asiri Rathnayake via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

> rmaprath updated this revision to Diff 69962.
> rmaprath added a comment.
>
> Simplified the patch a little bit more.
>
> Now, library vendors should be able to define 
> `_LIBCPP_STRICT_C99_COMPATIBILITY`
> and `libc++` will not use/test C99 math functions in `C++03/98` modes.
> Currently it's only the math functions, we can extend this approach to
> other affected areas if the approach is OK. Not 100% sure about the
> namings, can change them as needed.
>
> @EricWF: Gentle ping.
>
>
> https://reviews.llvm.org/D23926
>
> Files:
>   include/__config
>   include/math.h
>   test/std/depr/depr.c.headers/math_h.pass.cpp
>   test/std/numerics/c.math/cmath.pass.cpp
>   test/std/numerics/complex.number/cmplx.over/proj.pass.cpp
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23926: [libcxx] Don't use C99 math ops in -std=c++03 mode

2016-09-03 Thread Asiri Rathnayake via cfe-commits
@mclow.lists: Our C library is aware of the fact that it may be used from a
C++ context, yes.

So you think it's OK for libc++ to expect C99 operations at all language
standards?

Cheers,

/ Asiri
On 4 Sep 2016 01:16, "Marshall Clow via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

> mclow.lists added a comment.
>
> > We have quite a strict C library which is picky about what it exposes
> under different standards. For example, it won't expose C99 math ops if it
> is being used under `__cplusplus < 201103L` ...
>
>
> That sounds .. odd to me, having the behavior of the C library depend on
> the value of `__cplusplus`
>
>
> https://reviews.llvm.org/D23926
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21968: [libcxx] Externally threaded libc++ variant - Take 2

2016-09-03 Thread Asiri Rathnayake via cfe-commits
@mclow.lists: Ping ?
On 24 Aug 2016 22:46, "Asiri Rathnayake via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

> rmaprath added inline comments.
>
> 
> Comment at: include/__config:830
> @@ -829,1 +829,3 @@
> +!defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
> +!defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
>  # if defined(__FreeBSD__) || \
> 
> compnerd wrote:
> > I meant on the lines that you added :-).
> Will update to reflect rest of the source file.
>
> 
> Comment at: include/__threading_support:261
> @@ -200,1 +260,3 @@
> +void* __libcpp_tl_get(__libcpp_tl_key __key);
> +void __libcpp_tl_set(__libcpp_tl_key __key, void* __p);
>
> 
> compnerd wrote:
> > I think we should explicitly spell out `tls`.  The extra character won't
> hurt.
> Will fix.
>
> 
> Comment at: lib/CMakeLists.txt:216
> @@ +215,3 @@
> +  )
> +endif()
> +
> 
> compnerd wrote:
> > Have you considered a slightly alternative approach of basically
> implementing pthreads as an "external" threading model as well?  You could
> override it, or take the default implementation that is provided.  It
> avoids having a second supporting DSO for threading as we could always
> statically link against it.
> So, the particulars of this design was discussed and (generally) agreed
> upon sometime back.
>
> Currently pthreads **is** hidden behind the same threading API as the
> externally threaded variant (on this patch). To override the default
> (pthread) implementation, you just have to drop in an
> `__external_threading` header and specify the 
> `-DLIBCXX_HAS_EXTERNAL_THREAD_API`
> cmake option.
>
> There's no need to provide a second DSO if your `__external_threading`
> header (and your  thread-system sources) are available at `libc++` build
> time.
>
> But we have a **requirement** that the library needs to be build-able in
> such a way you can provide a second DSO holding the implementation of the
> API. That is, we need to be able to build and ship a library to which
> customers can drop-in their own thread implementation (i.e. the
> thread-support DSO).
>
> Note that in one of my earlier patches, I proposed an even more de-coupled
> external threading system where even the types like `__libcpp_mutex_t` were
> opaque pointers. @mclow.lists opposed that (perhaps rightfully so, now I
> think about it) and currently these types need to be known at `libc++`
> compile time. The implementation of the API functions like
> `__libcpp_mutex_lock()` can be deferred to link time (this is what is
> provided in the second DSO).
>
> Hope that clarifies everything here?
>
>
>
>
>
>
>
> 
> Comment at: test/support/external_threads.cpp:26
> @@ +25,3 @@
> +if (__ec)
> +  goto fail;
> +
> 
> compnerd wrote:
> > I think this would be nicer as:
> >
> >   if (int error = pthread_mutexattr_init(&attr))
> > return error;
> I think I'm following the conventions used in the `libc++` source files
> here. Will double check tomorrow.
>
> 
> Comment at: test/support/external_threads.cpp:52
> @@ +51,3 @@
> +fail:
> +return __ec;
> +}
> 
> compnerd wrote:
> > I don't think that the label for failure is adding anything since you
> really are handling the destruction of the mutex at all failure sites.
> Not sure what I did here. Will double check and fix.
>
> 
> Comment at: test/support/external_threads.cpp:70
> @@ +69,3 @@
> +
> +int __libcpp_mutex_destroy(__libcpp_mutex_t* __m) {
> +return pthread_mutex_destroy(__m);
> 
> compnerd wrote:
> > Please choose a single style.
> Will fix.
>
> 
> Comment at: test/support/external_threads.cpp:103
> @@ +102,3 @@
> +
> +bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id
> t2) {
> +return pthread_equal(t1, t2) != 0;
> 
> compnerd wrote:
> > Please choose a single style (and below).
> Will fix.
>
> 
> Comment at: test/support/external_threads.cpp:131
> @@ +130,3 @@
> +// before.
> +if (*__t == 0)
> +return -1;
> 
> compnerd wrote:
> > Can you compare to `nullptr` instead?
> I can't remember exactly why, but I think there was a problem with using
> `nullptr` here. I will check and get back.
>
> 
> Comment at: test/support/external_threads.cpp:142
> @@ +141,3 @@
> +// before.
> +if (*__t == 0)
> +return -1;
> 
> compnerd wrote:
> > Same.
> Need to check.
>
>
> https://reviews.llvm.org/D21968
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23926: [libcxx] Don't use C99 math ops in -std=c++03 mode

2016-09-05 Thread Asiri Rathnayake via cfe-commits
Hi @EricWD, @mclow.lists,

Thanks for the comments.

I will discuss this downstream a bit and get back. What I don't want to do
is deviate too much from upstream in terms of expectations. We may have to
shed some of our old expectations with libc++, I wanted to first clarify
upstream position on this.

Would be good to get these points documented though. I will do a docs patch
once i have discussed this internally.

Cheers,

/ Asiri

PS: @mclow.lists: Ping on the thread api patch... ;)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21968: [libcxx] Externally threaded libc++ variant - Take 2

2016-09-08 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

In https://reviews.llvm.org/D21968#534462, @EricWF wrote:

> This looks great.  Two comments:
>
> 1. The declarations should be used in both the inline and external pthread 
> implementation. They also need visibility declarations.
> 2. Why can't we use the inline implementation to implement 
> `external_threads.cpp`?
>
>   I took a stab at it here 
> .


Yup, that looks better.

I will incorporate this change and also address the remaining comments from 
@compnerd before I commit.

Thanks all!

/ Asiri


https://reviews.llvm.org/D21968



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21968: [libcxx] Externally threaded libc++ variant - Take 2

2016-09-09 Thread Asiri Rathnayake via cfe-commits
rmaprath updated this revision to Diff 70840.
rmaprath added a comment.
Herald added a subscriber: beanz.

Final patch incorporating all the changes from @EricWF and @compnerd.

Will commit tomorrow (@mclow.lists gave approval earlier)

/ Asiri


https://reviews.llvm.org/D21968

Files:
  CMakeLists.txt
  include/__config
  include/__config_site.in
  include/__threading_support
  include/thread
  lib/CMakeLists.txt
  test/CMakeLists.txt
  test/libcxx/test/config.py
  
test/libcxx/thread/thread.condition/thread.condition.condvar/native_handle.pass.cpp
  
test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/native_handle.pass.cpp
  
test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/native_handle.pass.cpp
  
test/libcxx/thread/thread.threads/thread.thread.class/thread.thread.member/native_handle.pass.cpp
  test/libcxx/thread/thread.threads/thread.thread.class/types.pass.cpp
  test/lit.site.cfg.in
  test/support/external_threads.cpp

Index: test/support/external_threads.cpp
===
--- /dev/null
+++ test/support/external_threads.cpp
@@ -0,0 +1,10 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+#define _LIBCPP_BUILDING_EXTERNAL_THREADS
+#include <__threading_support>
Index: test/lit.site.cfg.in
===
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -26,6 +26,7 @@
 config.use_libatomic= "@LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB@"
 
 config.libcxxabi_shared = "@LIBCXXABI_ENABLE_SHARED@"
+config.libcxx_external_thread_api  = "@LIBCXX_HAS_EXTERNAL_THREAD_API@"
 
 # Let the main config do the real work.
 lit_config.load_config(config, "@LIBCXX_SOURCE_DIR@/test/lit.cfg")
Index: test/libcxx/thread/thread.threads/thread.thread.class/types.pass.cpp
===
--- test/libcxx/thread/thread.threads/thread.thread.class/types.pass.cpp
+++ test/libcxx/thread/thread.threads/thread.thread.class/types.pass.cpp
@@ -7,7 +7,7 @@
 //
 //===--===//
 //
-// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: libcpp-has-no-threads, libcpp-has-thread-api-external
 
 // 
 
Index: test/libcxx/thread/thread.threads/thread.thread.class/thread.thread.member/native_handle.pass.cpp
===
--- test/libcxx/thread/thread.threads/thread.thread.class/thread.thread.member/native_handle.pass.cpp
+++ test/libcxx/thread/thread.threads/thread.thread.class/thread.thread.member/native_handle.pass.cpp
@@ -7,7 +7,7 @@
 //
 //===--===//
 //
-// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: libcpp-has-no-threads, libcpp-has-thread-api-external
 
 // 
 
Index: test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/native_handle.pass.cpp
===
--- test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/native_handle.pass.cpp
+++ test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/native_handle.pass.cpp
@@ -7,7 +7,7 @@
 //
 //===--===//
 //
-// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: libcpp-has-no-threads, libcpp-has-thread-api-external
 
 // 
 
Index: test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/native_handle.pass.cpp
===
--- test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/native_handle.pass.cpp
+++ test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/native_handle.pass.cpp
@@ -7,7 +7,7 @@
 //
 //===--===//
 //
-// UNSUPPORTED: libcpp-has-no-threads
+// UNSUPPORTED: libcpp-has-no-threads, libcpp-has-thread-api-external
 
 // 
 
Index: test/libcxx/thread/thread.condition/thread.condition.condvar/native_handle.pass.cpp
===
--- test/libcxx/thread/thread.condition/thread.condition.condvar/native_handle.pass.cpp
+++ test/libcxx/thread/thread.condition/thread.cond

[libcxx] r281179 - [libcxx] Introduce an externally-threaded libc++ variant.

2016-09-11 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Sun Sep 11 16:46:40 2016
New Revision: 281179

URL: http://llvm.org/viewvc/llvm-project?rev=281179&view=rev
Log:
[libcxx] Introduce an externally-threaded libc++ variant.

This patch further decouples libc++ from pthread, allowing libc++ to be built
against other threading systems. There are two main use cases:

- Building libc++ against a thread library other than pthreads.

- Building libc++ with an "external" thread API, allowing a separate library to
  provide the implementation of that API.

The two use cases are quite similar, the second one being sligtly more
de-coupled than the first. The cmake option LIBCXX_HAS_EXTERNAL_THREAD_API
enables both kinds of builds. One needs to place an <__external_threading>
header file containing an implementation of the "libc++ thread API" declared
in the <__threading_support> header.

For the second use case, the implementation of the libc++ thread API can
delegate to a custom "external" thread API where the implementation of this
external API is provided in a seperate library. This mechanism allows toolchain
vendors to distribute a build of libc++ with a custom thread-porting-layer API
(which is the "external" API above), platform vendors (recipients of the
toolchain/libc++) are then required to provide their implementation of this API
to be linked with (end-user) C++ programs.

Note that the second use case still requires establishing the basic types that
get passed between the external thread library and the libc++ library
(e.g. __libcpp_mutex_t). These cannot be opaque pointer types (libc++ sources
won't compile otherwise). It should also be noted that the second use case can
have a slight performance penalty; as all the thread constructs need to cross a
library boundary through an additional function call.

When the header <__external_threading> is omitted, libc++ is built with the
"libc++ thread API" (declared in <__threading_support>) as the "external" thread
API (basic types are pthread based). An implementation (pthread based) of this
API is provided in test/support/external_threads.cpp, which is built into a
separate DSO and linked in when running the libc++ test suite. A test run
therefore demonstrates the second use case (less the intermediate custom API).

Differential revision: https://reviews.llvm.org/D21968

Reviewers: bcraig, compnerd, EricWF, mclow.lists

Added:
libcxx/trunk/test/support/external_threads.cpp
  - copied, changed from r280988, 
libcxx/trunk/test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/native_handle.pass.cpp
Modified:
libcxx/trunk/CMakeLists.txt
libcxx/trunk/include/__config
libcxx/trunk/include/__config_site.in
libcxx/trunk/include/__threading_support
libcxx/trunk/include/thread
libcxx/trunk/lib/CMakeLists.txt
libcxx/trunk/test/CMakeLists.txt
libcxx/trunk/test/libcxx/test/config.py

libcxx/trunk/test/libcxx/thread/thread.condition/thread.condition.condvar/native_handle.pass.cpp

libcxx/trunk/test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/native_handle.pass.cpp

libcxx/trunk/test/libcxx/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/native_handle.pass.cpp

libcxx/trunk/test/libcxx/thread/thread.threads/thread.thread.class/thread.thread.member/native_handle.pass.cpp

libcxx/trunk/test/libcxx/thread/thread.threads/thread.thread.class/types.pass.cpp
libcxx/trunk/test/lit.site.cfg.in

Modified: libcxx/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=281179&r1=281178&r2=281179&view=diff
==
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Sun Sep 11 16:46:40 2016
@@ -140,6 +140,9 @@ option(LIBCXX_ENABLE_MONOTONIC_CLOCK
This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
 option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" 
OFF)
 option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread 
API" OFF)
+option(LIBCXX_HAS_EXTERNAL_THREAD_API
+  "Build libc++ with an externalized threading API.
+   This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
 
 # Misc options 
 # FIXME: Turn -pedantic back ON. It is currently off because it warns
@@ -197,6 +200,11 @@ if(LIBCXX_HAS_PTHREAD_API AND NOT LIBCXX
   " when LIBCXX_ENABLE_THREADS is also set to ON.")
 endif()
 
+if(LIBCXX_HAS_EXTERNAL_THREAD_API AND NOT LIBCXX_ENABLE_THREADS)
+  message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON"
+  " when LIBCXX_ENABLE_THREADS is also set to ON.")
+endif()
+
 # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE
 # is ON.
 if

Re: [libcxx] r281179 - [libcxx] Introduce an externally-threaded libc++ variant.

2016-09-12 Thread Asiri Rathnayake via cfe-commits
Hi Mike,

That does look related to my change. Is this an internal build? I was
looking out for the bots on llvm.org but didn't spot any issues (yet).

Will try to reproduce locally. Would it be OK if I find a fix tomorrow?
(night time here in the UK), can revert if this is blocking you.

Cheers,

/ Asiri


On Mon, Sep 12, 2016 at 9:25 PM, Mike Aizatsky via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Asiri,
>
> The boot strap build has started to fail for. Your change seems to be
> related, right?
>
> [14/22] Building CXX object projects/libcxx/lib/
> CMakeFiles/cxx_objects.dir/__/src/locale.cpp.o
> FAILED: /usr/bin/g++   -D_DEBUG -D_GNU_SOURCE 
> -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
> -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
> -Iprojects/libcxx/lib -I/usr/local/google/home/aizatsky/
> src/llvm/projects/libcxx/lib -Iinclude 
> -I/usr/local/google/home/aizatsky/src/llvm/include
> -I/usr/local/google/home/aizatsky/src/llvm/projects/libcxx/include -fPIC
> -fvisibility-inlines-hidden -Wall -W -Wno-unuse
> d-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers
>  -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor
> -Wno-comment -std=c++11 -ffunction-sections -fdata-sections -O3 -UN
> DEBUG -DLIBCXX_BUILDING_LIBCXXABI -std=c++11 -nostdinc++ -Wall -Wextra -W
> -Wwrite-strings -Wno-unused-parameter -Wno-long-long -Werror=return-type
> -Wno-attributes -Wno-literal-suffix -Wno-c++14-compat -Wno-erro
> r -fPIC -MMD -MT 
> projects/libcxx/lib/CMakeFiles/cxx_objects.dir/__/src/locale.cpp.o
> -MF projects/libcxx/lib/CMakeFiles/cxx_objects.dir/__/src/locale.cpp.o.d
> -o projects/libcxx/lib/CMakeFiles/cxx_objects.dir/__/
> src/locale.cpp.o -c /usr/local/google/home/aizatsky/src/llvm/projects/
> libcxx/src/locale.cpp
> In file included from /usr/local/google/home/aizatsky/src/llvm/projects/
> libcxx/include/__mutex_base:17:0,
>  from /usr/local/google/home/aizatsky/src/llvm/projects/
> libcxx/include/mutex:189,
>  from /usr/local/google/home/aizatsky/src/llvm/projects/
> libcxx/include/__locale:18,
>  from /usr/local/google/home/aizatsky/src/llvm/projects/
> libcxx/include/locale:182,
>  from /usr/local/google/home/aizatsky/src/llvm/projects/
> libcxx/src/locale.cpp:17:
> /usr/local/google/home/aizatsky/src/llvm/projects/
> libcxx/include/__threading_support:22:90: error: missing binary operator
> before token "("
>  #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) && (!defined(__has_include)
> || __has_include(<__external_threading>))
>
> ^
> In file included from /usr/local/google/home/aizatsky/src/llvm/projects/
> libcxx/include/algorithm:637:0,
>  from /usr/local/google/home/aizatsky/src/llvm/projects/
> libcxx/include/__string:55,
>  from /usr/local/google/home/aizatsky/src/llvm/projects/
> libcxx/include/string_view:166,
>  from /usr/local/google/home/aizatsky/src/llvm/projects/
> libcxx/include/string:464,
>  from /usr/local/google/home/aizatsky/src/llvm/projects/
> libcxx/src/locale.cpp:16:
>
>
> On Sun, Sep 11, 2016 at 2:55 PM Asiri Rathnayake via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: asiri
>> Date: Sun Sep 11 16:46:40 2016
>> New Revision: 281179
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=281179&view=rev
>> Log:
>> [libcxx] Introduce an externally-threaded libc++ variant.
>>
>> This patch further decouples libc++ from pthread, allowing libc++ to be
>> built
>> against other threading systems. There are two main use cases:
>>
>> - Building libc++ against a thread library other than pthreads.
>>
>> - Building libc++ with an "external" thread API, allowing a separate
>> library to
>>   provide the implementation of that API.
>>
>> The two use cases are quite similar, the second one being sligtly more
>> de-coupled than the first. The cmake option LIBCXX_HAS_EXTERNAL_THREAD_API
>> enables both kinds of builds. One needs to place an <__external_threading>
>> header file containing an implementation of the "libc++ thread API"
>> declared
>> in the <__threading_support> header.
>>
>> For the second use case, the implementation of the libc++ thread API can
>> delegate to a custom "external" thread API where the implementation of
>> this
>> external API is provided in a seperate library. This mechanism allows
>> toolchain
>> vendors to distribute a build of libc++ with a custom
>> thread-porting-layer API
>> (which is the 

Re: [libcxx] r281179 - [libcxx] Introduce an externally-threaded libc++ variant.

2016-09-12 Thread Asiri Rathnayake via cfe-commits
OK, I'm able to reproduce locally. Looks like gcc (4.8.3 at least) does not
like my patch.

Working on a fix...

On Mon, Sep 12, 2016 at 9:43 PM, Asiri Rathnayake <
asiri.rathnay...@gmail.com> wrote:

> Hi Mike,
>
> That does look related to my change. Is this an internal build? I was
> looking out for the bots on llvm.org but didn't spot any issues (yet).
>
> Will try to reproduce locally. Would it be OK if I find a fix tomorrow?
> (night time here in the UK), can revert if this is blocking you.
>
> Cheers,
>
> / Asiri
>
>
> On Mon, Sep 12, 2016 at 9:25 PM, Mike Aizatsky via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Asiri,
>>
>> The boot strap build has started to fail for. Your change seems to be
>> related, right?
>>
>> [14/22] Building CXX object projects/libcxx/lib/CMakeFiles
>> /cxx_objects.dir/__/src/locale.cpp.o
>> FAILED: /usr/bin/g++   -D_DEBUG -D_GNU_SOURCE
>> -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D__STDC_CONSTANT_MACROS
>> -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Iprojects/libcxx/lib
>> -I/usr/local/google/home/aizatsky/
>> src/llvm/projects/libcxx/lib -Iinclude 
>> -I/usr/local/google/home/aizatsky/src/llvm/include
>> -I/usr/local/google/home/aizatsky/src/llvm/projects/libcxx/include -fPIC
>> -fvisibility-inlines-hidden -Wall -W -Wno-unuse
>> d-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers
>>  -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor
>> -Wno-comment -std=c++11 -ffunction-sections -fdata-sections -O3 -UN
>> DEBUG -DLIBCXX_BUILDING_LIBCXXABI -std=c++11 -nostdinc++ -Wall -Wextra -W
>> -Wwrite-strings -Wno-unused-parameter -Wno-long-long -Werror=return-type
>> -Wno-attributes -Wno-literal-suffix -Wno-c++14-compat -Wno-erro
>> r -fPIC -MMD -MT 
>> projects/libcxx/lib/CMakeFiles/cxx_objects.dir/__/src/locale.cpp.o
>> -MF projects/libcxx/lib/CMakeFiles/cxx_objects.dir/__/src/locale.cpp.o.d
>> -o projects/libcxx/lib/CMakeFiles/cxx_objects.dir/__/
>> src/locale.cpp.o -c /usr/local/google/home/aizatsk
>> y/src/llvm/projects/libcxx/src/locale.cpp
>> In file included from /usr/local/google/home/aizatsk
>> y/src/llvm/projects/libcxx/include/__mutex_base:17:0,
>>  from /usr/local/google/home/aizatsk
>> y/src/llvm/projects/libcxx/include/mutex:189,
>>  from /usr/local/google/home/aizatsk
>> y/src/llvm/projects/libcxx/include/__locale:18,
>>  from /usr/local/google/home/aizatsk
>> y/src/llvm/projects/libcxx/include/locale:182,
>>  from /usr/local/google/home/aizatsk
>> y/src/llvm/projects/libcxx/src/locale.cpp:17:
>> /usr/local/google/home/aizatsky/src/llvm/projects/libcxx/
>> include/__threading_support:22:90: error: missing binary operator before
>> token "("
>>  #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) &&
>> (!defined(__has_include) || __has_include(<__external_threading>))
>>
>> ^
>> In file included from /usr/local/google/home/aizatsk
>> y/src/llvm/projects/libcxx/include/algorithm:637:0,
>>  from /usr/local/google/home/aizatsk
>> y/src/llvm/projects/libcxx/include/__string:55,
>>  from /usr/local/google/home/aizatsk
>> y/src/llvm/projects/libcxx/include/string_view:166,
>>  from /usr/local/google/home/aizatsk
>> y/src/llvm/projects/libcxx/include/string:464,
>>  from /usr/local/google/home/aizatsk
>> y/src/llvm/projects/libcxx/src/locale.cpp:16:
>>
>>
>> On Sun, Sep 11, 2016 at 2:55 PM Asiri Rathnayake via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: asiri
>>> Date: Sun Sep 11 16:46:40 2016
>>> New Revision: 281179
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=281179&view=rev
>>> Log:
>>> [libcxx] Introduce an externally-threaded libc++ variant.
>>>
>>> This patch further decouples libc++ from pthread, allowing libc++ to be
>>> built
>>> against other threading systems. There are two main use cases:
>>>
>>> - Building libc++ against a thread library other than pthreads.
>>>
>>> - Building libc++ with an "external" thread API, allowing a separate
>>> library to
>>>   provide the implementation of that API.
>>>
>>> The two use cases are quite similar, the second one being sligtly more
>>> de-coupled than the first. The cmake option
>>> LIBCXX_HAS_EXTERNAL_THREAD_API
>>> enables both kinds of builds. 

Re: [libcxx] r281179 - [libcxx] Introduce an externally-threaded libc++ variant.

2016-09-12 Thread Asiri Rathnayake via cfe-commits
Hi Mike,

Can you check if https://reviews.llvm.org/D24475 fixes the issue for you?
This looks like a bug in the gcc pre-processor (in older versions of gcc).

I'm a bit hesitant because my gcc (4.8.3) bumps into a different issue
(crash!) as well, but that seem to have nothing to do with my patch (can
reproduce without my patch...).

Cheers,

/ Asiri

On Mon, Sep 12, 2016 at 9:49 PM, Asiri Rathnayake <
asiri.rathnay...@gmail.com> wrote:

> OK, I'm able to reproduce locally. Looks like gcc (4.8.3 at least) does
> not like my patch.
>
> Working on a fix...
>
> On Mon, Sep 12, 2016 at 9:43 PM, Asiri Rathnayake <
> asiri.rathnay...@gmail.com> wrote:
>
>> Hi Mike,
>>
>> That does look related to my change. Is this an internal build? I was
>> looking out for the bots on llvm.org but didn't spot any issues (yet).
>>
>> Will try to reproduce locally. Would it be OK if I find a fix tomorrow?
>> (night time here in the UK), can revert if this is blocking you.
>>
>> Cheers,
>>
>> / Asiri
>>
>>
>> On Mon, Sep 12, 2016 at 9:25 PM, Mike Aizatsky via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Asiri,
>>>
>>> The boot strap build has started to fail for. Your change seems to be
>>> related, right?
>>>
>>> [14/22] Building CXX object projects/libcxx/lib/CMakeFiles
>>> /cxx_objects.dir/__/src/locale.cpp.o
>>> FAILED: /usr/bin/g++   -D_DEBUG -D_GNU_SOURCE
>>> -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D__STDC_CONSTANT_MACROS
>>> -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Iprojects/libcxx/lib
>>> -I/usr/local/google/home/aizatsky/
>>> src/llvm/projects/libcxx/lib -Iinclude 
>>> -I/usr/local/google/home/aizatsky/src/llvm/include
>>> -I/usr/local/google/home/aizatsky/src/llvm/projects/libcxx/include
>>> -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unuse
>>> d-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers
>>>  -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor
>>> -Wno-comment -std=c++11 -ffunction-sections -fdata-sections -O3 -UN
>>> DEBUG -DLIBCXX_BUILDING_LIBCXXABI -std=c++11 -nostdinc++ -Wall -Wextra
>>> -W -Wwrite-strings -Wno-unused-parameter -Wno-long-long -Werror=return-type
>>> -Wno-attributes -Wno-literal-suffix -Wno-c++14-compat -Wno-erro
>>> r -fPIC -MMD -MT projects/libcxx/lib/CMakeFiles
>>> /cxx_objects.dir/__/src/locale.cpp.o -MF projects/libcxx/lib/CMakeFiles
>>> /cxx_objects.dir/__/src/locale.cpp.o.d -o projects/libcxx/lib/CMakeFiles
>>> /cxx_objects.dir/__/
>>> src/locale.cpp.o -c /usr/local/google/home/aizatsk
>>> y/src/llvm/projects/libcxx/src/locale.cpp
>>> In file included from /usr/local/google/home/aizatsk
>>> y/src/llvm/projects/libcxx/include/__mutex_base:17:0,
>>>  from /usr/local/google/home/aizatsk
>>> y/src/llvm/projects/libcxx/include/mutex:189,
>>>  from /usr/local/google/home/aizatsk
>>> y/src/llvm/projects/libcxx/include/__locale:18,
>>>  from /usr/local/google/home/aizatsk
>>> y/src/llvm/projects/libcxx/include/locale:182,
>>>  from /usr/local/google/home/aizatsk
>>> y/src/llvm/projects/libcxx/src/locale.cpp:17:
>>> /usr/local/google/home/aizatsky/src/llvm/projects/libcxx/inc
>>> lude/__threading_support:22:90: error: missing binary operator before
>>> token "("
>>>  #if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) &&
>>> (!defined(__has_include) || __has_include(<__external_threading>))
>>>
>>>   ^
>>> In file included from /usr/local/google/home/aizatsk
>>> y/src/llvm/projects/libcxx/include/algorithm:637:0,
>>>  from /usr/local/google/home/aizatsk
>>> y/src/llvm/projects/libcxx/include/__string:55,
>>>  from /usr/local/google/home/aizatsk
>>> y/src/llvm/projects/libcxx/include/string_view:166,
>>>  from /usr/local/google/home/aizatsk
>>> y/src/llvm/projects/libcxx/include/string:464,
>>>  from /usr/local/google/home/aizatsk
>>> y/src/llvm/projects/libcxx/src/locale.cpp:16:
>>>
>>>
>>> On Sun, Sep 11, 2016 at 2:55 PM Asiri Rathnayake via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
>>>> Author: asiri
>>>> Date: Sun Sep 11 16:46:40 2016
>>>> New Revision: 281179
>>>>
>>>> URL: http://llvm.org/viewvc/llvm-project?rev=2

[libcxx] r281310 - [libcxx] Fix gcc builds.

2016-09-13 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Tue Sep 13 04:32:32 2016
New Revision: 281310

URL: http://llvm.org/viewvc/llvm-project?rev=281310&view=rev
Log:
[libcxx] Fix gcc builds.

Step around a gcc pre-processor defect which causes it to fail to
parse the __has_include macro check.

Modified:
libcxx/trunk/include/__threading_support

Modified: libcxx/trunk/include/__threading_support
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__threading_support?rev=281310&r1=281309&r2=281310&view=diff
==
--- libcxx/trunk/include/__threading_support (original)
+++ libcxx/trunk/include/__threading_support Tue Sep 13 04:32:32 2016
@@ -19,9 +19,20 @@
 
 #ifndef _LIBCPP_HAS_NO_THREADS
 
-#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) && (!defined(__has_include) || 
__has_include(<__external_threading>))
+// These checks are carefully arranged so as not to trigger a gcc pre-processor
+// defect which causes it to fail to parse the __has_include check below, the
+// redundancy is intentional.
+#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
+#if !defined(__clang__) && (_GNUC_VER < 500)
 #include <__external_threading>
-#else
+#define _LIBCPP_EXTERNAL_THREADING
+#elif !defined(__has_include) || __has_include(<__external_threading>)
+#include <__external_threading>
+#define _LIBCPP_EXTERNAL_THREADING
+#endif
+#endif
+
+#if !defined(_LIBCPP_EXTERNAL_THREADING)
 #include 
 #include 
 #endif


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24562: [libcxx] Recover no-exceptions XFAILs

2016-09-14 Thread Asiri Rathnayake via cfe-commits
rmaprath created this revision.
rmaprath added reviewers: EricWF, mclow.lists.
rmaprath added a subscriber: cfe-commits.

When we added support for the no-exceptions build of `libc++`, all the tests 
that used exceptions got a blanket XFAIL for the no-exceptions variety.

Previously, we tried to fix-up these tests with an elaborate setjmp/longjmp 
hackery (see D14653), which was rejected on the grounds of being too 
complicated / obtrusive.

The current patch is a representative fix that does the most obvious thing 
instead: use pre-processor macros to exclude just the bits of the test that use 
exceptions. Unlike in the previous patch, this means we are not trying to 
associate / verify a particular behaviour of the no-exceptions library with 
respect to exceptional situations (like calling abort). Here we simply save the 
parts of the test that has nothing to do with exceptions, I think this is a 
fair compromise.

We could also split the test file into two; one that uses exceptions and one 
that does not, though I can't think of any added benefits of that approach.

If this patch is approved I'll go ahead and update the rest of the tests (~150) 
to follow the same.

https://reviews.llvm.org/D24562

Files:
  test/std/re/re.alg/re.alg.search/grep.pass.cpp

Index: test/std/re/re.alg/re.alg.search/grep.pass.cpp
===
--- test/std/re/re.alg/re.alg.search/grep.pass.cpp
+++ test/std/re/re.alg/re.alg.search/grep.pass.cpp
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // template 
@@ -23,6 +22,7 @@
 #include "test_macros.h"
 #include "test_iterators.h"
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 extern "C" void LLVMFuzzerTestOneInput(const char *data)
 {
 size_t size = strlen(data);
@@ -47,6 +47,7 @@
 
LLVMFuzzerTestOneInput(R"XX(Õ)_%()()((\8'_%()_%()_%()_%(()_%()_%()_%(.t;)()¥f()_%()(.)_%;)()!¥f)()XX");
 #endif
 }
+#endif
 
 int main()
 {
@@ -82,5 +83,7 @@
 assert(m.position(0) == 0);
 assert(m.str(0) == "");
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 fuzz_tests();
+#endif
 }


Index: test/std/re/re.alg/re.alg.search/grep.pass.cpp
===
--- test/std/re/re.alg/re.alg.search/grep.pass.cpp
+++ test/std/re/re.alg/re.alg.search/grep.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // template 
@@ -23,6 +22,7 @@
 #include "test_macros.h"
 #include "test_iterators.h"
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 extern "C" void LLVMFuzzerTestOneInput(const char *data)
 {
 size_t size = strlen(data);
@@ -47,6 +47,7 @@
 LLVMFuzzerTestOneInput(R"XX(Õ)_%()()((\8'_%()_%()_%()_%(()_%()_%()_%(.t;)()¥f()_%()(.)_%;)()!¥f)()XX");
 #endif
 }
+#endif
 
 int main()
 {
@@ -82,5 +83,7 @@
 assert(m.position(0) == 0);
 assert(m.str(0) == "");
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 fuzz_tests();
+#endif
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24562: [libcxx] Recover no-exceptions XFAILs

2016-09-14 Thread Asiri Rathnayake via cfe-commits
rmaprath updated this revision to Diff 71349.
rmaprath added a comment.

(Added more context)


https://reviews.llvm.org/D24562

Files:
  test/std/re/re.alg/re.alg.search/grep.pass.cpp

Index: test/std/re/re.alg/re.alg.search/grep.pass.cpp
===
--- test/std/re/re.alg/re.alg.search/grep.pass.cpp
+++ test/std/re/re.alg/re.alg.search/grep.pass.cpp
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // template 
@@ -23,6 +22,7 @@
 #include "test_macros.h"
 #include "test_iterators.h"
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 extern "C" void LLVMFuzzerTestOneInput(const char *data)
 {
 size_t size = strlen(data);
@@ -47,6 +47,7 @@
 
LLVMFuzzerTestOneInput(R"XX(Õ)_%()()((\8'_%()_%()_%()_%(()_%()_%()_%(.t;)()¥f()_%()(.)_%;)()!¥f)()XX");
 #endif
 }
+#endif
 
 int main()
 {
@@ -82,5 +83,7 @@
 assert(m.position(0) == 0);
 assert(m.str(0) == "");
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 fuzz_tests();
+#endif
 }


Index: test/std/re/re.alg/re.alg.search/grep.pass.cpp
===
--- test/std/re/re.alg/re.alg.search/grep.pass.cpp
+++ test/std/re/re.alg/re.alg.search/grep.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // template 
@@ -23,6 +22,7 @@
 #include "test_macros.h"
 #include "test_iterators.h"
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 extern "C" void LLVMFuzzerTestOneInput(const char *data)
 {
 size_t size = strlen(data);
@@ -47,6 +47,7 @@
 LLVMFuzzerTestOneInput(R"XX(Õ)_%()()((\8'_%()_%()_%()_%(()_%()_%()_%(.t;)()¥f()_%()(.)_%;)()!¥f)()XX");
 #endif
 }
+#endif
 
 int main()
 {
@@ -82,5 +83,7 @@
 assert(m.position(0) == 0);
 assert(m.str(0) == "");
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 fuzz_tests();
+#endif
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24562: [libcxx] Recover no-exceptions XFAILs

2016-09-14 Thread Asiri Rathnayake via cfe-commits
rmaprath added a comment.

In https://reviews.llvm.org/D24562#542630, @mclow.lists wrote:

> What an awful test.  I wonder who wrote such a steaming pile.  Probably me.


I think I've thrown quite a lot of XFAILs like this in the past, just to get 
the no-exceptions build passing. Now I've got to clean them up one by one :)

Are you OK with this way of fixing them?

Cheers,

/ Asiri


https://reviews.llvm.org/D24562



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24562: [libcxx] Recover no-exceptions XFAILs

2016-09-15 Thread Asiri Rathnayake via cfe-commits
rmaprath added inline comments.


Comment at: test/std/re/re.alg/re.alg.search/grep.pass.cpp:25
@@ -25,2 +24,3 @@
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 extern "C" void LLVMFuzzerTestOneInput(const char *data)

EricWF wrote:
> I prefer putting the `#if` on the inside of the function so you don't also 
> have to `#ifdef` it out in `main()` below. 
> 
Thanks. That's much better.

I'll convert as much tests as possible and submit and overall patch for a final 
review.


https://reviews.llvm.org/D24562



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23926: [libcxx] Don't use C99 math ops in -std=c++03 mode

2016-09-16 Thread Asiri Rathnayake via cfe-commits
rmaprath abandoned this revision.
rmaprath added a comment.

Abandoning: we've decided to relax our C library to expose C99 functionality in 
C++98/03 modes. This is more inline with upstream intentions and allows us to 
get rid of some fiddly downstream libc++ patches as well.

Thanks Marshall and Eric for the comments / chats.

/ Asiri


https://reviews.llvm.org/D23926



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r281731 - [libcxx] Add missing c++98 xfail. NFC.

2016-09-16 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Fri Sep 16 09:32:19 2016
New Revision: 281731

URL: http://llvm.org/viewvc/llvm-project?rev=281731&view=rev
Log:
[libcxx] Add missing c++98 xfail. NFC.

This is the only test failing in c++98 mode at the moment.

Modified:
libcxx/trunk/test/std/iterators/iterator.range/begin-end.pass.cpp

Modified: libcxx/trunk/test/std/iterators/iterator.range/begin-end.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/iterators/iterator.range/begin-end.pass.cpp?rev=281731&r1=281730&r2=281731&view=diff
==
--- libcxx/trunk/test/std/iterators/iterator.range/begin-end.pass.cpp (original)
+++ libcxx/trunk/test/std/iterators/iterator.range/begin-end.pass.cpp Fri Sep 
16 09:32:19 2016
@@ -7,7 +7,7 @@
 //
 
//===--===//
 
-// XFAIL: c++03
+// XFAIL: c++03, c++98
 
 // 
 // template  auto begin(C& c) -> decltype(c.begin());


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxxabi] r299435 - Fix exception address alignment test for EHABI

2017-04-04 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Tue Apr  4 09:03:54 2017
New Revision: 299435

URL: http://llvm.org/viewvc/llvm-project?rev=299435&view=rev
Log:
Fix exception address alignment test for EHABI

This test fails on ARM bare-metal targets because it assumes the Itanium ABI,
whereas EHABI requires the exception address to be 8-byte aligned.

I was a bit puzzled at first because this should've failed on the public
arm-linux builder too. I think the reason it passes there is because we don't
include libunwind headers in the include path when running the libcxxabi tests,
so the system unwind.h gets picked up.

Reviewers: rengolin, EricWF
Differential revision: https://reviews.llvm.org/D31178

Modified:
libcxxabi/trunk/CMakeLists.txt
libcxxabi/trunk/test/libcxxabi/test/config.py
libcxxabi/trunk/test/lit.site.cfg.in
libcxxabi/trunk/test/test_exception_address_alignment.pass.cpp

Modified: libcxxabi/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/CMakeLists.txt?rev=299435&r1=299434&r2=299435&view=diff
==
--- libcxxabi/trunk/CMakeLists.txt (original)
+++ libcxxabi/trunk/CMakeLists.txt Tue Apr  4 09:03:54 2017
@@ -502,9 +502,14 @@ if (LIBCXXABI_USE_LLVM_UNWINDER OR LLVM_
 set(LIBCXXABI_LIBUNWIND_SOURCES "")
   endif()
 
-  if (NOT LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL 
"LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL-NOTFOUND")
+  if (LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL 
"LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL-NOTFOUND")
+set(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL "")
+  endif()
+
+  if (NOT LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "")
 include_directories("${LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL}")
   endif()
+
   if (NOT LIBCXXABI_LIBUNWIND_SOURCES STREQUAL "")
 include_directories("${LIBCXXABI_LIBUNWIND_SOURCES}")
   endif()

Modified: libcxxabi/trunk/test/libcxxabi/test/config.py
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/libcxxabi/test/config.py?rev=299435&r1=299434&r2=299435&view=diff
==
--- libcxxabi/trunk/test/libcxxabi/test/config.py (original)
+++ libcxxabi/trunk/test/libcxxabi/test/config.py Tue Apr  4 09:03:54 2017
@@ -84,6 +84,13 @@ class Configuration(LibcxxConfiguration)
   % libcxxabi_headers)
 self.cxx.compile_flags += ['-I' + libcxxabi_headers]
 
+libunwind_headers = self.get_lit_conf('libunwind_headers', None)
+if self.get_lit_bool('llvm_unwinder', False) and libunwind_headers:
+if not os.path.isdir(libunwind_headers):
+self.lit_config.fatal("libunwind_headers='%s' is not a 
directory."
+  % libunwind_headers)
+self.cxx.compile_flags += ['-I' + libunwind_headers]
+
 def configure_compile_flags_exceptions(self):
 pass
 

Modified: libcxxabi/trunk/test/lit.site.cfg.in
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/lit.site.cfg.in?rev=299435&r1=299434&r2=299435&view=diff
==
--- libcxxabi/trunk/test/lit.site.cfg.in (original)
+++ libcxxabi/trunk/test/lit.site.cfg.in Tue Apr  4 09:03:54 2017
@@ -6,6 +6,7 @@ config.libcxxabi_obj_root   = "@LIBC
 config.abi_library_path = "@LIBCXXABI_LIBRARY_DIR@"
 config.libcxx_src_root  = "@LIBCXXABI_LIBCXX_PATH@"
 config.cxx_headers  = "@LIBCXXABI_LIBCXX_INCLUDES@"
+config.libunwind_headers= "@LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL@"
 config.cxx_library_root = "@LIBCXXABI_LIBCXX_LIBRARY_PATH@"
 config.llvm_unwinder= "@LIBCXXABI_USE_LLVM_UNWINDER@"
 config.enable_threads   = "@LIBCXXABI_ENABLE_THREADS@"

Modified: libcxxabi/trunk/test/test_exception_address_alignment.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/test_exception_address_alignment.pass.cpp?rev=299435&r1=299434&r2=299435&view=diff
==
--- libcxxabi/trunk/test/test_exception_address_alignment.pass.cpp (original)
+++ libcxxabi/trunk/test/test_exception_address_alignment.pass.cpp Tue Apr  4 
09:03:54 2017
@@ -15,8 +15,8 @@
 // working around this failure.
 // XFAIL: darwin && libcxxabi-has-system-unwinder
 
-// Test that the address of the exception object is properly aligned to the
-// largest supported alignment for the system.
+// Test that the address of the exception object is properly aligned as 
required
+// by the relevant ABI
 
 #include 
 #include 
@@ -24,7 +24,16 @@
 #include 
 
 struct __attribute__((aligned)) AlignedType {};
-static_assert(alignof(AlignedType) == alignof(_Unwind_Exception),
+
+// EHABI  : 8-byte aligned
+// Itanium: Largest supported alignment for the system
+#if defined(_LIBUNWIND_ARM_EHABI)
+#  define EXPECTED_ALIGNMENT 8
+#else
+#  define EXPECTED_ALI

[libcxx] r292107 - [libcxx] Don't assume __libcpp_thread_t is an integral type

2017-01-16 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Mon Jan 16 06:19:54 2017
New Revision: 292107

URL: http://llvm.org/viewvc/llvm-project?rev=292107&view=rev
Log:
[libcxx] Don't assume __libcpp_thread_t is an integral type

We have already refactored the underlying platform thread type into
__libcpp_thread_t, but there are few places in the source where we
still assume it is an integral type.

This patch refactores those points back into the threading API.

Differential revision: https://reviews.llvm.org/D28608

Reviewers: EricWF

Modified:
libcxx/trunk/include/__threading_support
libcxx/trunk/include/thread

Modified: libcxx/trunk/include/__threading_support
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__threading_support?rev=292107&r1=292106&r2=292107&view=diff
==
--- libcxx/trunk/include/__threading_support (original)
+++ libcxx/trunk/include/__threading_support Mon Jan 16 06:19:54 2017
@@ -61,6 +61,8 @@ typedef pthread_once_t __libcpp_exec_onc
 typedef pthread_t __libcpp_thread_id;
 
 // Thread
+#define _LIBCPP_NULL_THREAD 0U
+
 typedef pthread_t __libcpp_thread_t;
 
 // Thrad Local Storage
@@ -86,6 +88,8 @@ typedef INIT_ONCE __libcpp_exec_once_fla
 typedef DWORD __libcpp_thread_id;
 
 // Thread
+#define _LIBCPP_NULL_THREAD 0U
+
 typedef HANDLE __libcpp_thread_t;
 
 // Thread Local Storage
@@ -158,6 +162,9 @@ bool __libcpp_thread_id_less(__libcpp_th
 
 // Thread
 _LIBCPP_THREAD_ABI_VISIBILITY
+bool __libcpp_thread_isnull(const __libcpp_thread_t *__t);
+
+_LIBCPP_THREAD_ABI_VISIBILITY
 int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
void *__arg);
 
@@ -309,6 +316,10 @@ bool __libcpp_thread_id_less(__libcpp_th
 }
 
 // Thread
+bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) {
+  return *__t == 0;
+}
+
 int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
void *__arg)
 {
@@ -506,6 +517,10 @@ __libcpp_beginthreadex_thunk(void *__raw
   return static_cast(reinterpret_cast(__func(__arg)));
 }
 
+bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) {
+  return *__t == 0;
+}
+
 int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
void *__arg)
 {

Modified: libcxx/trunk/include/thread
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/thread?rev=292107&r1=292106&r2=292107&view=diff
==
--- libcxx/trunk/include/thread (original)
+++ libcxx/trunk/include/thread Mon Jan 16 06:19:54 2017
@@ -290,7 +290,7 @@ public:
 typedef __libcpp_thread_t native_handle_type;
 
 _LIBCPP_INLINE_VISIBILITY
-thread() _NOEXCEPT : __t_(0) {}
+thread() _NOEXCEPT : __t_(_LIBCPP_NULL_THREAD) {}
 #ifndef _LIBCPP_HAS_NO_VARIADICS
 template http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r292108 - [libcxx] Improve design documentation for the external-thread-library

2017-01-16 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Mon Jan 16 06:44:08 2017
New Revision: 292108

URL: http://llvm.org/viewvc/llvm-project?rev=292108&view=rev
Log:
[libcxx] Improve design documentation for the external-thread-library
  configuration

NFC.

Differential revision: https://reviews.llvm.org/D28610

Reviewers: EricWF

Modified:
libcxx/trunk/docs/DesignDocs/ThreadingSupportAPI.rst

Modified: libcxx/trunk/docs/DesignDocs/ThreadingSupportAPI.rst
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/docs/DesignDocs/ThreadingSupportAPI.rst?rev=292108&r1=292107&r2=292108&view=diff
==
--- libcxx/trunk/docs/DesignDocs/ThreadingSupportAPI.rst (original)
+++ libcxx/trunk/docs/DesignDocs/ThreadingSupportAPI.rst Mon Jan 16 06:44:08 
2017
@@ -33,13 +33,22 @@ interface normally provided by ``<__thre
 External Threading Library
 ==
 
-Normally ``<__threading_support>`` provides inline definitions to each internal
-threading API function it declares. However libc++ also supports using an
-external library to provide the definitions.
+libc++ can be compiled with its internal threading API delegating to an 
external
+library. Such a configuration is useful for library vendors who wish to
+distribute a thread-agnostic libc++ library, where the users of the library are
+expected to provide the implementation of the libc++ internal threading API.
 
-When ``_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL`` libc++ does not provide inline
-definitions for the internal API, instead assuming the definitions will be
-provided by an external library.
+On a production setting, this would be achieved through a custom
+``<__external_threading>`` header, which declares the libc++ internal threading
+API but leaves out the implementation.
+
+The ``-DLIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY`` option allows building libc++ in
+such a configuration while allowing it to be tested on a platform that supports
+any of the threading systems (e.g. pthread) supported in 
``__threading_support``
+header. Therefore, the main purpose of this option is to allow testing of this
+particular configuration of the library without being tied to a vendor-specific
+threading system. This option is only meant to be used by libc++ library
+developers.
 
 Threading Configuration Macros
 ==


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r292109 - [libcxx] Follow-up to r292107

2017-01-16 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Mon Jan 16 07:13:01 2017
New Revision: 292109

URL: http://llvm.org/viewvc/llvm-project?rev=292109&view=rev
Log:
[libcxx] Follow-up to r292107

I've missed a couple of updates. NFC.

Modified:
libcxx/trunk/src/thread.cpp

Modified: libcxx/trunk/src/thread.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/thread.cpp?rev=292109&r1=292108&r2=292109&view=diff
==
--- libcxx/trunk/src/thread.cpp (original)
+++ libcxx/trunk/src/thread.cpp Mon Jan 16 07:13:01 2017
@@ -40,7 +40,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 thread::~thread()
 {
-if (__t_ != 0)
+if (!__libcpp_thread_isnull(&__t_))
 terminate();
 }
 
@@ -48,11 +48,11 @@ void
 thread::join()
 {
 int ec = EINVAL;
-if (__t_ != 0)
+if (!__libcpp_thread_isnull(&__t_))
 {
 ec = __libcpp_thread_join(&__t_);
 if (ec == 0)
-__t_ = 0;
+__t_ = _LIBCPP_NULL_THREAD;
 }
 
 if (ec)
@@ -63,11 +63,11 @@ void
 thread::detach()
 {
 int ec = EINVAL;
-if (__t_ != 0)
+if (!__libcpp_thread_isnull(&__t_))
 {
 ec = __libcpp_thread_detach(&__t_);
 if (ec == 0)
-__t_ = 0;
+__t_ = _LIBCPP_NULL_THREAD;
 }
 
 if (ec)


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D29063: [libcxx] Never use within libc++

2017-01-24 Thread Asiri Rathnayake via cfe-commits
Thanks for the lightening fast response :)

/ Asiri

On Tue, Jan 24, 2017 at 12:38 PM, Eric Fiselier via Phabricator via
cfe-commits  wrote:

> EricWF added a comment.
>
> It seems like weird usages of `_LIBCPP_ASSERT` in `` are
> causing this problem.
> Specifically the usages in `` attempt to use `_LIBCPP_ASSERT`
> in C++11 constexpr functions and this currently does not work.
>
> For now I've reverted this change in r292923.
>
>
> https://reviews.llvm.org/D29063
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [libcxx] r290889 - [libcxx] Add build/test support for the externally threaded libc++abi variant

2017-01-25 Thread Asiri Rathnayake via cfe-commits
(including cfe-commits)

On Wed, Jan 25, 2017 at 5:51 PM, Asiri Rathnayake <
asiri.rathnay...@gmail.com> wrote:

> Hi Nico,
>
> On Wed, Jan 25, 2017 at 5:32 PM, Nico Weber via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Is it intentional that this change affects non-LIBCXX_HAS_EXTERNAL_THREAD_API
>> builds at all?#
>>
>
> Nope. But I'm not sure how this got broken on Mac.
>
> IIRC,  defines mach_port_t type on Mac, which gets included
> when _LIBCPP_HAS_THREAD_API_PTHREAD is defined (which is what we expect
> to be the case on Mac, normally).
>
> I'll have to build this on a Mac tomorrow. Hopefully that's OK?
>
> Cheers,
>
> / Asiri
>
>
>
>>
>> On Wed, Jan 25, 2017 at 12:31 PM, Nico Weber  wrote:
>>
>>> This breaks all our mac builds with:
>>>
>>> /b/c/b/ClangToTMac__dbg_/src/third_party/llvm-build/Release+
>>> Asserts/bin/../include/c++/v1/__threading_support:154:1: error: unknown
>>> type name 'mach_port_t'
>>> mach_port_t __libcpp_thread_get_port();
>>>
>>> On Tue, Jan 3, 2017 at 7:59 AM, Asiri Rathnayake via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
>>>> Author: asiri
>>>> Date: Tue Jan  3 06:59:50 2017
>>>> New Revision: 290889
>>>>
>>>> URL: http://llvm.org/viewvc/llvm-project?rev=290889&view=rev
>>>> Log:
>>>> [libcxx] Add build/test support for the externally threaded libc++abi
>>>> variant
>>>>
>>>> Differential revision: https://reviews.llvm.org/D27576
>>>>
>>>> Reviewers: EricWF
>>>>
>>>> Modified:
>>>> libcxx/trunk/CMakeLists.txt
>>>> libcxx/trunk/include/__threading_support
>>>> libcxx/trunk/test/CMakeLists.txt
>>>> libcxx/trunk/test/libcxx/test/config.py
>>>> libcxx/trunk/test/lit.site.cfg.in
>>>>
>>>> Modified: libcxx/trunk/CMakeLists.txt
>>>> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.
>>>> txt?rev=290889&r1=290888&r2=290889&view=diff
>>>> 
>>>> ==
>>>> --- libcxx/trunk/CMakeLists.txt (original)
>>>> +++ libcxx/trunk/CMakeLists.txt Tue Jan  3 06:59:50 2017
>>>> @@ -221,14 +221,21 @@ if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_
>>>>" when LIBCXX_ENABLE_THREADS is also set to
>>>> OFF.")
>>>>  endif()
>>>>
>>>> -if(LIBCXX_HAS_PTHREAD_API AND NOT LIBCXX_ENABLE_THREADS)
>>>> -  message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
>>>> -  " when LIBCXX_ENABLE_THREADS is also set to ON.")
>>>> +if(NOT LIBCXX_ENABLE_THREADS)
>>>> +  if(LIBCXX_HAS_PTHREAD_API)
>>>> +message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
>>>> +" when LIBCXX_ENABLE_THREADS is also set to
>>>> ON.")
>>>> +  endif()
>>>> +  if(LIBCXX_HAS_EXTERNAL_THREAD_API)
>>>> +message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be
>>>> set to ON"
>>>> +" when LIBCXX_ENABLE_THREADS is also set to
>>>> ON.")
>>>> +  endif()
>>>>  endif()
>>>>
>>>> -if(LIBCXX_HAS_EXTERNAL_THREAD_API AND NOT LIBCXX_ENABLE_THREADS)
>>>> -  message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set
>>>> to ON"
>>>> -  " when LIBCXX_ENABLE_THREADS is also set to ON.")
>>>> +if(LIBCXX_HAS_PTHREAD_API AND LIBCXX_HAS_EXTERNAL_THREAD_API)
>>>> +  message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
>>>> +  "and LIBCXX_HAS_PTHREAD_API cannot be both"
>>>> +  "set to ON at the same time.")
>>>>  endif()
>>>>
>>>>  # Ensure LLVM_USE_SANITIZER is not specified when
>>>> LIBCXX_GENERATE_COVERAGE
>>>>
>>>> Modified: libcxx/trunk/include/__threading_support
>>>> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__t
>>>> hreading_support?rev=290889&r1=290888&r2=290889&view=diff
>>>> 
>>&

Re: [libcxx] r290889 - [libcxx] Add build/test support for the externally threaded libc++abi variant

2017-01-25 Thread Asiri Rathnayake via cfe-commits
@Nico: could you let me know your build configuration? (cmake options)

I'm surprised this went unnoticed for so long.

Thanks.

/ Asiri

On 25 Jan 2017 5:52 p.m., "Asiri Rathnayake" 
wrote:

> (including cfe-commits)
>
> On Wed, Jan 25, 2017 at 5:51 PM, Asiri Rathnayake <
> asiri.rathnay...@gmail.com> wrote:
>
>> Hi Nico,
>>
>> On Wed, Jan 25, 2017 at 5:32 PM, Nico Weber via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Is it intentional that this change affects 
>>> non-LIBCXX_HAS_EXTERNAL_THREAD_API
>>> builds at all?#
>>>
>>
>> Nope. But I'm not sure how this got broken on Mac.
>>
>> IIRC,  defines mach_port_t type on Mac, which gets included
>> when _LIBCPP_HAS_THREAD_API_PTHREAD is defined (which is what we expect
>> to be the case on Mac, normally).
>>
>> I'll have to build this on a Mac tomorrow. Hopefully that's OK?
>>
>> Cheers,
>>
>> / Asiri
>>
>>
>>
>>>
>>> On Wed, Jan 25, 2017 at 12:31 PM, Nico Weber 
>>> wrote:
>>>
>>>> This breaks all our mac builds with:
>>>>
>>>> /b/c/b/ClangToTMac__dbg_/src/third_party/llvm-build/Release+
>>>> Asserts/bin/../include/c++/v1/__threading_support:154:1: error:
>>>> unknown type name 'mach_port_t'
>>>> mach_port_t __libcpp_thread_get_port();
>>>>
>>>> On Tue, Jan 3, 2017 at 7:59 AM, Asiri Rathnayake via cfe-commits <
>>>> cfe-commits@lists.llvm.org> wrote:
>>>>
>>>>> Author: asiri
>>>>> Date: Tue Jan  3 06:59:50 2017
>>>>> New Revision: 290889
>>>>>
>>>>> URL: http://llvm.org/viewvc/llvm-project?rev=290889&view=rev
>>>>> Log:
>>>>> [libcxx] Add build/test support for the externally threaded libc++abi
>>>>> variant
>>>>>
>>>>> Differential revision: https://reviews.llvm.org/D27576
>>>>>
>>>>> Reviewers: EricWF
>>>>>
>>>>> Modified:
>>>>> libcxx/trunk/CMakeLists.txt
>>>>> libcxx/trunk/include/__threading_support
>>>>> libcxx/trunk/test/CMakeLists.txt
>>>>> libcxx/trunk/test/libcxx/test/config.py
>>>>> libcxx/trunk/test/lit.site.cfg.in
>>>>>
>>>>> Modified: libcxx/trunk/CMakeLists.txt
>>>>> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.
>>>>> txt?rev=290889&r1=290888&r2=290889&view=diff
>>>>> 
>>>>> ==
>>>>> --- libcxx/trunk/CMakeLists.txt (original)
>>>>> +++ libcxx/trunk/CMakeLists.txt Tue Jan  3 06:59:50 2017
>>>>> @@ -221,14 +221,21 @@ if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_
>>>>>" when LIBCXX_ENABLE_THREADS is also set to
>>>>> OFF.")
>>>>>  endif()
>>>>>
>>>>> -if(LIBCXX_HAS_PTHREAD_API AND NOT LIBCXX_ENABLE_THREADS)
>>>>> -  message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
>>>>> -  " when LIBCXX_ENABLE_THREADS is also set to
>>>>> ON.")
>>>>> +if(NOT LIBCXX_ENABLE_THREADS)
>>>>> +  if(LIBCXX_HAS_PTHREAD_API)
>>>>> +message(FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
>>>>> +" when LIBCXX_ENABLE_THREADS is also set to
>>>>> ON.")
>>>>> +  endif()
>>>>> +  if(LIBCXX_HAS_EXTERNAL_THREAD_API)
>>>>> +message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be
>>>>> set to ON"
>>>>> +" when LIBCXX_ENABLE_THREADS is also set to
>>>>> ON.")
>>>>> +  endif()
>>>>>  endif()
>>>>>
>>>>> -if(LIBCXX_HAS_EXTERNAL_THREAD_API AND NOT LIBCXX_ENABLE_THREADS)
>>>>> -  message(FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be
>>>>> set to ON"
>>>>> -  " when LIBCXX_ENABLE_THREADS is also set to
>>>>> ON.")
>>>>> +if(LIBCXX_HAS_PTHREAD_API AND LIBCXX_HAS_EXTERNAL_THREAD_API)
>>>>> +  message(FATAL_ERROR "The options LIBCXX_HAS_EXTE

Re: [libcxx] r290889 - [libcxx] Add build/test support for the externally threaded libc++abi variant

2017-01-25 Thread Asiri Rathnayake via cfe-commits
Hi Nico,

Thanks for the links. I may have a clue to what is going on.

I think in your Mac environment,  does not provide
either pthread_mach_thread_np() function or define the type mach_port_t (is
there a way for you to check this btw? just to make sure).

This was not a problem before (for your builds) because this function was
only used in libcxxabi sources. In my eagerness to get rid of all pthread
dependencies in libcxx/libcxxabi, I have lifted this out into
__threading_support header in libcxx (which is our new threading API for
both libcxx and libcxxabi).

@Eric: would it be OK to leave this Mac-specific pthread dependency in
libcxxabi sources as it was? In that way, libcxx builds like Nico's won't
be affected.

Another option is to try and detect the conditions (on Mac environments)
where pthread_mach_thread_np/mach_port_t is available, and only define the
corresponding libcxx thread-api function (__libcpp_thread_get_port) when
this condition is true. Unfortunately I'm not familiar with Mac enough to
know this. Any thoughts?

Side note:- Btw, if I'm correct with the above analysis, it won't be
possible to build libcxxabi in Nico's environment (even before my changes).
The dependency on pthread_mach_thread_np() was already there
in __cxa_guard_acquire().

Thanks.

/ Asiri


On Wed, Jan 25, 2017 at 7:34 PM, Nico Weber  wrote:

> Sure! https://build.chromium.org/p/chromium.fyi/builders/
> ClangToTMacASan/builds/8565/steps/gclient%20runhooks/logs/stdio has the
> invocations to build llvm/clang/compiler/rt, and https://build.chromium.
> org/p/chromium.fyi/builders/ClangToTMacASan/builds/8565/
> steps/compile/logs/stdio is the actual build using that setup.
>
> On Wed, Jan 25, 2017 at 1:57 PM, Asiri Rathnayake <
> asiri.rathnay...@gmail.com> wrote:
>
>> @Nico: could you let me know your build configuration? (cmake options)
>>
>> I'm surprised this went unnoticed for so long.
>>
>> Thanks.
>>
>> / Asiri
>>
>> On 25 Jan 2017 5:52 p.m., "Asiri Rathnayake" 
>> wrote:
>>
>>> (including cfe-commits)
>>>
>>> On Wed, Jan 25, 2017 at 5:51 PM, Asiri Rathnayake <
>>> asiri.rathnay...@gmail.com> wrote:
>>>
>>>> Hi Nico,
>>>>
>>>> On Wed, Jan 25, 2017 at 5:32 PM, Nico Weber via cfe-commits <
>>>> cfe-commits@lists.llvm.org> wrote:
>>>>
>>>>> Is it intentional that this change affects
>>>>> non-LIBCXX_HAS_EXTERNAL_THREAD_API builds at all?#
>>>>>
>>>>
>>>> Nope. But I'm not sure how this got broken on Mac.
>>>>
>>>> IIRC,  defines mach_port_t type on Mac, which gets included
>>>> when _LIBCPP_HAS_THREAD_API_PTHREAD is defined (which is what we
>>>> expect to be the case on Mac, normally).
>>>>
>>>> I'll have to build this on a Mac tomorrow. Hopefully that's OK?
>>>>
>>>> Cheers,
>>>>
>>>> / Asiri
>>>>
>>>>
>>>>
>>>>>
>>>>> On Wed, Jan 25, 2017 at 12:31 PM, Nico Weber 
>>>>> wrote:
>>>>>
>>>>>> This breaks all our mac builds with:
>>>>>>
>>>>>> /b/c/b/ClangToTMac__dbg_/src/third_party/llvm-build/Release+
>>>>>> Asserts/bin/../include/c++/v1/__threading_support:154:1: error:
>>>>>> unknown type name 'mach_port_t'
>>>>>> mach_port_t __libcpp_thread_get_port();
>>>>>>
>>>>>> On Tue, Jan 3, 2017 at 7:59 AM, Asiri Rathnayake via cfe-commits <
>>>>>> cfe-commits@lists.llvm.org> wrote:
>>>>>>
>>>>>>> Author: asiri
>>>>>>> Date: Tue Jan  3 06:59:50 2017
>>>>>>> New Revision: 290889
>>>>>>>
>>>>>>> URL: http://llvm.org/viewvc/llvm-project?rev=290889&view=rev
>>>>>>> Log:
>>>>>>> [libcxx] Add build/test support for the externally threaded
>>>>>>> libc++abi variant
>>>>>>>
>>>>>>> Differential revision: https://reviews.llvm.org/D27576
>>>>>>>
>>>>>>> Reviewers: EricWF
>>>>>>>
>>>>>>> Modified:
>>>>>>> libcxx/trunk/CMakeLists.txt
>>>>>>> libcxx/trunk/include/__threading_support
>>>>>>> libcxx/trunk/test/CMakeLists.txt
>>>>>>> libcxx/trunk/test/libcxx/test/config.py
>>

[libcxxabi] r293166 - Fix chromium build (libcxxabi)

2017-01-26 Thread Asiri Rathnayake via cfe-commits
Author: asiri
Date: Thu Jan 26 04:38:03 2017
New Revision: 293166

URL: http://llvm.org/viewvc/llvm-project?rev=293166&view=rev
Log:
Fix chromium build (libcxxabi)

Pull the dependency on pthread_mach_thread_np() back into libcxxabi.

Modified:
libcxxabi/trunk/src/cxa_guard.cpp

Modified: libcxxabi/trunk/src/cxa_guard.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_guard.cpp?rev=293166&r1=293165&r2=293166&view=diff
==
--- libcxxabi/trunk/src/cxa_guard.cpp (original)
+++ libcxxabi/trunk/src/cxa_guard.cpp Thu Jan 26 04:38:03 2017
@@ -179,7 +179,19 @@ _LIBCXXABI_FUNC_VIS int __cxa_guard_acqu
 if (result)
 {
 #if defined(__APPLE__) && !defined(__arm__)
-const lock_type id = std::__libcpp_thread_get_port();
+// This is a special-case pthread dependency for Mac. We can't pull 
this
+// out into libcxx's threading API (__threading_support) because not 
all
+// supported Mac environments provide this function (in pthread.h). To
+// make it possible to build/use libcxx in those environments, we have 
to
+// keep this pthread dependency local to libcxxabi. If there is some
+// convenient way to detect precisely when pthread_mach_thread_np is
+// available in a given Mac environment, it might still be possible to
+// bury this dependency in __threading_support.
+#ifdef _LIBCPP_HAS_THREAD_API_PTHREAD
+   const lock_type id = 
pthread_mach_thread_np(std::__libcpp_thread_get_current_id());
+#else
+   #error "How do I pthread_mach_thread_np()?"
+#endif
 lock_type lock = get_lock(*guard_object);
 if (lock)
 {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   >