From 02a9443db9b11ea959a0f65005506e21404ef933 Mon Sep 17 00:00:00 2001 From: Rasmus Munk Larsen Date: Fri, 13 Jul 2018 11:03:04 -0700 Subject: Clang produces incorrect Thumb2 assembler when using alloca. Don't define EIGEN_ALLOCA when generating Thumb with clang. --- Eigen/src/Core/util/Memory.h | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/util/Memory.h b/Eigen/src/Core/util/Memory.h index 85bc75da6..1805041c7 100644 --- a/Eigen/src/Core/util/Memory.h +++ b/Eigen/src/Core/util/Memory.h @@ -77,7 +77,7 @@ inline void throw_std_bad_alloc() // "no overloaded function has restriction specifiers that are compatible with the ambient context" // // "throw_std_bad_alloc" has the EIGEN_DEVICE_FUNC attribute, so it seems that hipcc expects - // the same on "operator new" + // the same on "operator new" // Reverting code back to the old version in this #if block for the hipcc compiler // new int[huge]; @@ -169,13 +169,13 @@ EIGEN_DEVICE_FUNC inline void* aligned_malloc(std::size_t size) void *result; #if (EIGEN_DEFAULT_ALIGN_BYTES==0) || EIGEN_MALLOC_ALREADY_ALIGNED - + #if defined(EIGEN_HIP_DEVICE_COMPILE) result = ::malloc(size); #else result = std::malloc(size); #endif - + #if EIGEN_DEFAULT_ALIGN_BYTES==16 eigen_assert((size<16 || (std::size_t(result)%16)==0) && "System's malloc returned an unaligned pointer. Compile with EIGEN_MALLOC_ALREADY_ALIGNED=0 to fallback to handmade alignd memory allocator."); #endif @@ -199,7 +199,7 @@ EIGEN_DEVICE_FUNC inline void aligned_free(void *ptr) #else std::free(ptr); #endif - + #else handmade_aligned_free(ptr); #endif @@ -248,7 +248,7 @@ template<> EIGEN_DEVICE_FUNC inline void* conditional_aligned_malloc(std: #else void *result = std::malloc(size); #endif - + if(!result && size) throw_std_bad_alloc(); return result; @@ -588,6 +588,15 @@ template struct smart_memmove_helper { #endif #endif +// With clang -Oz -mthumb, alloca changes the stack pointer in a way that is +// not allowed in Thumb2. -DEIGEN_STACK_ALLOCATION_LIMIT=0 doesn't work because +// the compiler still emits bad code because stack allocation checks use "<=". +// TODO: Eliminate after https://bugs.llvm.org/show_bug.cgi?id=23772 +// is fixed. +#if defined(__clang__) && defined(__ANDROID__) && defined(__thumb__) + #undef EIGEN_ALLOCA +#endif + // This helper class construct the allocated memory, and takes care of destructing and freeing the handled data // at destruction time. In practice this helper class is mainly useful to avoid memory leak in case of exceptions. template class aligned_stack_memory_handler : noncopyable @@ -701,7 +710,7 @@ template void swap(scoped_array &a,scoped_array &b) } // end namespace internal /** \internal - * + * * The macro ei_declare_aligned_stack_constructed_variable(TYPE,NAME,SIZE,BUFFER) declares, allocates, * and construct an aligned buffer named NAME of SIZE elements of type TYPE on the stack * if the size in bytes is smaller than EIGEN_STACK_ALLOCATION_LIMIT, and if stack allocation is supported by the platform @@ -716,7 +725,7 @@ template void swap(scoped_array &a,scoped_array &b) * } * \endcode * The underlying stack allocation function can controlled with the EIGEN_ALLOCA preprocessor token. - * + * * The macro ei_declare_local_nested_eval(XPR_T,XPR,N,NAME) is analogue to * \code * typename internal::nested_eval::type NAME(XPR); -- cgit v1.2.3