Skip to content

Instantly share code, notes, and snippets.

@jckarter
Created July 21, 2012 02:26
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jckarter/3154264 to your computer and use it in GitHub Desktop.
Patch Intel Threading Building Blocks to support clang -std=c++11 -stdlib=libc++ on macosx
diff -Nur -x 'macos_*' tbb40_20120613oss.orig/build/macos.clang-libcxx.inc tbb40_20120613oss/build/macos.clang-libcxx.inc
--- tbb40_20120613oss.orig/build/macos.clang-libcxx.inc 1969-12-31 16:00:00.000000000 -0800
+++ tbb40_20120613oss/build/macos.clang-libcxx.inc 2012-07-20 15:10:31.000000000 -0700
@@ -0,0 +1,11 @@
+include $(tbb_root)/build/macos.clang.inc
+
+LIBS += -stdlib=libc++
+CPLUS_FLAGS += -stdlib=libc++
+
+CPP11_FLAGS = -std=c++11 -D_TBB_CPP0X
+
+ifneq (00,$(lambdas)$(cpp0x))
+ CXX_ONLY_FLAGS += $(CPP11_FLAGS)
+endif
+
diff -Nur -x 'macos_*' tbb40_20120613oss.orig/include/tbb/cache_aligned_allocator.h tbb40_20120613oss/include/tbb/cache_aligned_allocator.h
--- tbb40_20120613oss.orig/include/tbb/cache_aligned_allocator.h 2012-06-28 00:07:16.000000000 -0700
+++ tbb40_20120613oss/include/tbb/cache_aligned_allocator.h 2012-07-20 16:53:19.000000000 -0700
@@ -103,12 +103,12 @@
//! Copy-construct value at location pointed to by p.
#if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __TBB_CPP11_RVALUE_REF_PRESENT
- template<typename... Args>
- void construct(pointer p, Args&&... args)
+ template<typename U, typename... Args>
+ void construct(U *p, Args&&... args)
#if __TBB_CPP11_STD_FORWARD_BROKEN
- { ::new((void *)p) T((args)...); }
+ { ::new((void *)p) U((args)...); }
#else
- { ::new((void *)p) T(std::forward<Args>(args)...); }
+ { ::new((void *)p) U(std::forward<Args>(args)...); }
#endif
#else // __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __TBB_CPP11_RVALUE_REF_PRESENT
void construct( pointer p, const value_type& value ) {::new((void*)(p)) value_type(value);}
diff -Nur -x 'macos_*' tbb40_20120613oss.orig/include/tbb/compat/tuple tbb40_20120613oss/include/tbb/compat/tuple
--- tbb40_20120613oss.orig/include/tbb/compat/tuple 2012-06-28 00:07:17.000000000 -0700
+++ tbb40_20120613oss/include/tbb/compat/tuple 2012-07-20 15:49:59.000000000 -0700
@@ -505,10 +505,36 @@
#if TBB_IMPLEMENT_CPP0X
namespace std {
using tbb::interface5::tuple;
+using tbb::interface5::get;
+#ifndef _LIBCPP_UTILITY
using tbb::interface5::tuple_size;
using tbb::interface5::tuple_element;
-using tbb::interface5::get;
+#endif
}
+
+#ifdef _LIBCPP_UTILITY
+
+// LLVM libc++ populates the std namespace from an inline namespace versioned by the
+// abi version, so simply using tbb::interface5::tuple_size etc. causes name lookup
+// ambiguities.
+
+namespace std {
+
+template<int N, class T0, class T1, class T2, class T3, class T4 __TBB_CLASS_T_PACK >
+class tuple_element<N, tbb::interface5::tuple<T0, T1, T2, T3, T4 __TBB_T_PACK> > :
+ public tbb::interface5::tuple_element<N, tbb::interface5::tuple<T0, T1, T2, T3, T4 __TBB_T_PACK> >
+{
+};
+
+template<class T0, class T1, class T2, class T3, class T4 __TBB_CLASS_T_PACK >
+class tuple_size<tbb::interface5::tuple<T0, T1, T2, T3, T4 __TBB_T_PACK> > :
+ public tbb::interface5::tuple_size<tbb::interface5::tuple<T0, T1, T2, T3, T4 __TBB_T_PACK> >
+{
+};
+
+}
+#endif
+
#endif
#undef __TBB_T_PACK
diff -Nur -x 'macos_*' tbb40_20120613oss.orig/include/tbb/internal/_flow_graph_or_impl.h tbb40_20120613oss/include/tbb/internal/_flow_graph_or_impl.h
--- tbb40_20120613oss.orig/include/tbb/internal/_flow_graph_or_impl.h 2012-06-28 00:07:17.000000000 -0700
+++ tbb40_20120613oss/include/tbb/internal/_flow_graph_or_impl.h 2012-07-20 16:59:51.000000000 -0700
@@ -64,10 +64,20 @@
template<typename OutputTuple>
struct or_output_type {
typedef OutputTuple tuple_types;
- typedef struct {
+ struct type {
size_t indx;
OutputTuple result;
- } type;
+#ifdef _LIBCPP_TUPLE
+ // The LLVM libc++ that ships with Mac OS X 10.7 has a bug in tuple that disables
+ // the copy assignment operator (LLVM bug #11921).
+
+ type &operator=(type const &x) {
+ indx = x.indx;
+ result = const_cast<OutputTuple&>(x.result);
+ return *this;
+ }
+#endif
+ };
};
template<typename TupleTypes,int N>
diff -Nur -x 'macos_*' tbb40_20120613oss.orig/include/tbb/memory_pool.h tbb40_20120613oss/include/tbb/memory_pool.h
--- tbb40_20120613oss.orig/include/tbb/memory_pool.h 2012-06-28 00:07:17.000000000 -0700
+++ tbb40_20120613oss/include/tbb/memory_pool.h 2012-07-20 16:13:12.000000000 -0700
@@ -137,12 +137,12 @@
}
//! Copy-construct value at location pointed to by p.
#if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __TBB_CPP11_RVALUE_REF_PRESENT
- template<typename... Args>
- void construct(pointer p, Args&&... args)
+ template<typename U, typename... Args>
+ void construct(U *p, Args&&... args)
#if __TBB_CPP11_STD_FORWARD_BROKEN
- { ::new((void *)p) T((args)...); }
+ { ::new((void *)p) U((args)...); }
#else
- { ::new((void *)p) T(std::forward<Args>(args)...); }
+ { ::new((void *)p) U(std::forward<Args>(args)...); }
#endif
#else // __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __TBB_CPP11_RVALUE_REF_PRESENT
void construct( pointer p, const value_type& value ) { ::new((void*)(p)) value_type(value); }
diff -Nur -x 'macos_*' tbb40_20120613oss.orig/include/tbb/scalable_allocator.h tbb40_20120613oss/include/tbb/scalable_allocator.h
--- tbb40_20120613oss.orig/include/tbb/scalable_allocator.h 2012-06-28 00:07:15.000000000 -0700
+++ tbb40_20120613oss/include/tbb/scalable_allocator.h 2012-07-20 16:13:51.000000000 -0700
@@ -218,12 +218,12 @@
return (absolutemax > 0 ? absolutemax : 1);
}
#if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __TBB_CPP11_RVALUE_REF_PRESENT
- template<typename... Args>
- void construct(pointer p, Args&&... args)
+ template<typename U, typename... Args>
+ void construct(U *p, Args&&... args)
#if __TBB_CPP11_STD_FORWARD_BROKEN
- { ::new((void *)p) T((args)...); }
+ { ::new((void *)p) U((args)...); }
#else
- { ::new((void *)p) T(std::forward<Args>(args)...); }
+ { ::new((void *)p) U(std::forward<Args>(args)...); }
#endif
#else // __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __TBB_CPP11_RVALUE_REF_PRESENT
void construct( pointer p, const value_type& value ) {::new((void*)(p)) value_type(value);}
diff -Nur -x 'macos_*' tbb40_20120613oss.orig/include/tbb/tbb_allocator.h tbb40_20120613oss/include/tbb/tbb_allocator.h
--- tbb40_20120613oss.orig/include/tbb/tbb_allocator.h 2012-06-28 00:07:18.000000000 -0700
+++ tbb40_20120613oss/include/tbb/tbb_allocator.h 2012-07-20 16:53:25.000000000 -0700
@@ -122,12 +122,12 @@
//! Copy-construct value at location pointed to by p.
#if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __TBB_CPP11_RVALUE_REF_PRESENT
- template<typename... Args>
- void construct(pointer p, Args&&... args)
+ template<typename U, typename... Args>
+ void construct(U *p, Args&&... args)
#if __TBB_CPP11_STD_FORWARD_BROKEN
- { ::new((void *)p) T((args)...); }
+ { ::new((void *)p) U((args)...); }
#else
- { ::new((void *)p) T(std::forward<Args>(args)...); }
+ { ::new((void *)p) U(std::forward<Args>(args)...); }
#endif
#else // __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __TBB_CPP11_RVALUE_REF_PRESENT
void construct( pointer p, const value_type& value ) {::new((void*)(p)) value_type(value);}
diff -Nur -x 'macos_*' tbb40_20120613oss.orig/include/tbb/tbb_config.h tbb40_20120613oss/include/tbb/tbb_config.h
--- tbb40_20120613oss.orig/include/tbb/tbb_config.h 2012-06-28 00:07:18.000000000 -0700
+++ tbb40_20120613oss/include/tbb/tbb_config.h 2012-07-20 17:47:56.000000000 -0700
@@ -163,6 +163,12 @@
/** By default, use C++0x classes if available **/
#if __GNUC__==4 && __GNUC_MINOR__>=4 && __GXX_EXPERIMENTAL_CXX0X__
#define TBB_IMPLEMENT_CPP0X 0
+ #elif __clang__ && __cplusplus >= 201103L
+ #if __has_include(<tuple>) && __has_include(<thread>)
+ #define TBB_IMPLEMENT_CPP0X 0
+ #else
+ #define TBB_IMPLEMENT_CPP0X 1
+ #endif
#else
#define TBB_IMPLEMENT_CPP0X 1
#endif
@@ -274,7 +280,7 @@
#define __TBB_TEMPLATE_FRIENDS_BROKEN 1
#endif
-#if __GLIBC__==2 && __GLIBC_MINOR__==3 || __MINGW32__ || (__APPLE__ && __INTEL_COMPILER==1200 && !TBB_USE_DEBUG)
+#if __GLIBC__==2 && __GLIBC_MINOR__==3 || __MINGW32__ || (__APPLE__ && (__clang__ || __INTEL_COMPILER==1200 && !TBB_USE_DEBUG))
//! Macro controlling EH usages in TBB tests
/** Some older versions of glibc crash when exception handling happens concurrently. **/
#define __TBB_THROW_ACROSS_MODULE_BOUNDARY_BROKEN 1
diff -Nur -x 'macos_*' tbb40_20120613oss.orig/include/tbb/tbb_exception.h tbb40_20120613oss/include/tbb/tbb_exception.h
--- tbb40_20120613oss.orig/include/tbb/tbb_exception.h 2012-06-28 00:07:16.000000000 -0700
+++ tbb40_20120613oss/include/tbb/tbb_exception.h 2012-07-20 18:18:12.000000000 -0700
@@ -37,6 +37,7 @@
#pragma warning (disable: 4530)
#endif
+#include <exception>
#include <stdexcept>
#include <string> // required to construct std exception classes
@@ -354,7 +355,12 @@
private:
tbb_exception_ptr ( const std::exception_ptr& src ) : my_ptr(src) {}
+
+#if _MSC_VER || !__clang__ && __TBB_GCC_VERSION < 40600
tbb_exception_ptr ( const captured_exception& src ) : my_ptr(std::copy_exception(src)) {}
+#else
+ tbb_exception_ptr ( const captured_exception& src ) : my_ptr(std::make_exception_ptr(src)) {}
+#endif
}; // class tbb::internal::tbb_exception_ptr
} // namespace internal
diff -Nur -x 'macos_*' tbb40_20120613oss.orig/src/test/harness.h tbb40_20120613oss/src/test/harness.h
--- tbb40_20120613oss.orig/src/test/harness.h 2012-06-28 00:07:04.000000000 -0700
+++ tbb40_20120613oss/src/test/harness.h 2012-07-20 17:53:25.000000000 -0700
@@ -63,13 +63,15 @@
#if __INTEL_COMPILER
#define __TBB_LAMBDAS_PRESENT ( _TBB_CPP0X && __INTEL_COMPILER > 1100 )
+#elif __clang__
+#define __TBB_LAMBDAS_PRESENT ( _TBB_CPP0X && __has_feature(cxx_lambdas))
#elif __GNUC__
#define __TBB_LAMBDAS_PRESENT ( _TBB_CPP0X && __TBB_GCC_VERSION >= 40500 )
#elif _MSC_VER
#define __TBB_LAMBDAS_PRESENT ( _MSC_VER>=1600 )
#endif
-#if defined(_MSC_VER) && _MSC_VER < 1400
+#if defined(_MSC_VER) && _MSC_VER < 1400 || __clang__
#define __TBB_EXCEPTION_TYPE_INFO_BROKEN 1
#else
#define __TBB_EXCEPTION_TYPE_INFO_BROKEN 0
diff -Nur -x 'macos_*' tbb40_20120613oss.orig/src/test/harness_allocator.h tbb40_20120613oss/src/test/harness_allocator.h
--- tbb40_20120613oss.orig/src/test/harness_allocator.h 2012-06-28 00:07:07.000000000 -0700
+++ tbb40_20120613oss/src/test/harness_allocator.h 2012-07-20 13:22:34.000000000 -0700
@@ -36,6 +36,7 @@
#elif _WIN32
#include "tbb/machine/windows_api.h"
#endif /* OS specific */
+#include <memory>
#include <new>
#if !TBB_USE_EXCEPTIONS && _MSC_VER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment