From 0b6cff3d1d918f642bcb5bdfbbfa6dcd8a7d35ec Mon Sep 17 00:00:00 2001 From: Ben Pritchard Date: Thu, 18 Feb 2016 12:38:27 -0500 Subject: [PATCH 1/4] Fixes for compilation/segfault problems with Intel (issue 94) --- include/pybind11/attr.h | 2 +- include/pybind11/cast.h | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/pybind11/attr.h b/include/pybind11/attr.h index 15d5982a..8c77a412 100644 --- a/include/pybind11/attr.h +++ b/include/pybind11/attr.h @@ -277,7 +277,7 @@ template struct process_attribute void ignore_unused(const T&) { } +inline void ignore_unused(const int *) { } /// Recursively iterate over variadic template arguments template struct process_attributes { diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 2dfcc771..b153d6ef 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -519,9 +519,16 @@ public: explicit operator type*() { return this->value; } explicit operator type&() { return *(this->value); } - explicit operator holder_type&() { return holder; } explicit operator holder_type*() { return &holder; } + // Workaround for Intel compiler bug + // see pybind11 issue 94 + #if defined(__ICC) || defined(__INTEL_COMPILER) + operator holder_type&() { return holder; } + #else + explicit operator holder_type&() { return holder; } + #endif + static handle cast(const holder_type &src, return_value_policy policy, handle parent) { return type_caster_generic::cast( src.get(), policy, parent, &typeid(type), ©_constructor, &src); From 70ee47ddcff0aaecebfdd3aeab190739ff204f5f Mon Sep 17 00:00:00 2001 From: Ben Pritchard Date: Thu, 18 Feb 2016 13:06:43 -0500 Subject: [PATCH 2/4] Add Intel to cmake file. Supress Intel inline/noinline warning --- CMakeLists.txt | 9 ++++++++- include/pybind11/pybind11.h | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6c05523..5d440454 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,7 @@ endif() string(REPLACE "+" "" PYTHONLIBS_VERSION_STRING "+${PYTHONLIBS_VERSION_STRING}") find_package(PythonInterp ${PYTHONLIBS_VERSION_STRING} EXACT REQUIRED) -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel") CHECK_CXX_COMPILER_FLAG("-std=c++14" HAS_CPP14_FLAG) CHECK_CXX_COMPILER_FLAG("-std=c++11" HAS_CPP11_FLAG) @@ -57,10 +57,17 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") # Check for Link Time Optimization support + # (GCC/Clang) CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG) if (HAS_LTO_FLAG) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto") endif() + + # Intel equivalent to LTO is called IPO + CHECK_CXX_COMPILER_FLAG("-ipo" HAS_IPO_FLAG) + if (HAS_IPO_FLAG) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ipo") + endif() endif() endif() diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 7b816d38..ecd6ce1a 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -17,6 +17,8 @@ # pragma warning(disable: 4996) // warning C4996: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name # pragma warning(disable: 4100) // warning C4100: Unreferenced formal parameter # pragma warning(disable: 4512) // warning C4512: Assignment operator was implicitly defined as deleted +#elif defined(__ICC) || defined(__INTEL_COMPILER) +# pragma warning(disable:2196) // warning #2196: routine is both "inline" and "noinline" #elif defined(__GNUG__) and !defined(__clang__) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wunused-but-set-parameter" From 2de6e1d14281dea8995e7fa34f00c159996ecbcc Mon Sep 17 00:00:00 2001 From: Ben Pritchard Date: Thu, 18 Feb 2016 13:20:15 -0500 Subject: [PATCH 3/4] Remove some unnecessary semicolons (compilers warn on higher levels) --- include/pybind11/common.h | 2 +- include/pybind11/operators.h | 10 +++++----- include/pybind11/pybind11.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/pybind11/common.h b/include/pybind11/common.h index 6d06c9dd..e4cb9be5 100644 --- a/include/pybind11/common.h +++ b/include/pybind11/common.h @@ -149,7 +149,7 @@ enum class return_value_policy : int { /// Format strings for basic number types template struct format_descriptor { }; -#define PYBIND11_DECL_FMT(t, n) template<> struct format_descriptor { static std::string value() { return n; }; }; +#define PYBIND11_DECL_FMT(t, n) template<> struct format_descriptor { static std::string value() { return n; }; } PYBIND11_DECL_FMT(int8_t, "b"); PYBIND11_DECL_FMT(uint8_t, "B"); PYBIND11_DECL_FMT(int16_t, "h"); PYBIND11_DECL_FMT(uint16_t, "H"); PYBIND11_DECL_FMT(int32_t, "i"); PYBIND11_DECL_FMT(uint32_t, "I"); PYBIND11_DECL_FMT(int64_t, "q"); PYBIND11_DECL_FMT(uint64_t, "Q"); PYBIND11_DECL_FMT(float, "f"); PYBIND11_DECL_FMT(double, "d"); PYBIND11_DECL_FMT(bool, "?"); diff --git a/include/pybind11/operators.h b/include/pybind11/operators.h index 7eab419c..b10bfe30 100644 --- a/include/pybind11/operators.h +++ b/include/pybind11/operators.h @@ -76,13 +76,13 @@ template struct op_impl op(const self_t &, const self_t &) { \ return op_(); \ -}; \ +} \ template op_ op(const self_t &, const T &) { \ return op_(); \ -}; \ +} \ template op_ op(const T &, const self_t &) { \ return op_(); \ -}; +} #define PYBIND11_INPLACE_OPERATOR(id, op, expr) \ template struct op_impl { \ @@ -92,7 +92,7 @@ template struct op_impl op_ op(const self_t &, const T &) { \ return op_(); \ -}; +} #define PYBIND11_UNARY_OPERATOR(id, op, expr) \ template struct op_impl { \ @@ -102,7 +102,7 @@ template struct op_impl op(const self_t &) { \ return op_(); \ -}; +} PYBIND11_BINARY_OPERATOR(sub, rsub, operator-, l - r) PYBIND11_BINARY_OPERATOR(add, radd, operator+, l + r) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index ecd6ce1a..0688a31d 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -974,7 +974,7 @@ PYBIND11_NOINLINE inline void keep_alive_impl(int Nurse, int Patient, handle arg NAMESPACE_END(detail) -template detail::init init() { return detail::init(); }; +template detail::init init() { return detail::init(); } template void implicitly_convertible() { auto implicit_caster = [](PyObject *obj, PyTypeObject *type) -> PyObject * { From 33f3430d0c1d6c0ac90aa6f3ac62de108fda3f67 Mon Sep 17 00:00:00 2001 From: Ben Pritchard Date: Thu, 18 Feb 2016 15:25:51 -0500 Subject: [PATCH 4/4] Add intel warning push/pop --- include/pybind11/pybind11.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 0688a31d..8cffb382 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -18,6 +18,7 @@ # pragma warning(disable: 4100) // warning C4100: Unreferenced formal parameter # pragma warning(disable: 4512) // warning C4512: Assignment operator was implicitly defined as deleted #elif defined(__ICC) || defined(__INTEL_COMPILER) +# pragma warning(push) # pragma warning(disable:2196) // warning #2196: routine is both "inline" and "noinline" #elif defined(__GNUG__) and !defined(__clang__) # pragma GCC diagnostic push @@ -1056,6 +1057,8 @@ NAMESPACE_END(pybind11) #if defined(_MSC_VER) # pragma warning(pop) +#elif defined(__ICC) || defined(__INTEL_COMPILER) +# pragma warning(pop) #elif defined(__GNUG__) and !defined(__clang__) # pragma GCC diagnostic pop #endif