mt_allocator.cc assumes sizeof(size_t) == sizeof(void *)

Joel Sherrill joel.sherrill@oarcorp.com
Fri Nov 7 15:07:00 GMT 2014


Hi

On m32c-rtems, we have a build error in C++ because size_t
is 16-bits and pointers are 24 bits. m32c-elf probably does not
enable __GTHREAD support like rtems does.  Since this is code
shared across targets, what is the best way to fix this?

My first inclination would be to use uintptr_t for the variable
_M_id but I don't know what other impacts that would have
or where else this needs to be fixed.

../../../../../../gcc/libstdc++-v3/src/c++98/mt_allocator.cc: In
function 'void {anonymous}::_M_destroy_thread_key(void*)':
../../../../../../gcc/libstdc++-v3/src/c++98/mt_allocator.cc:77:51:
error: cast from 'void*' to 'size_t {aka unsigned int}' loses precision
[-fpermissive]
       size_t _M_id = reinterpret_cast<size_t>(__id);
                                                   ^
../../../../../../gcc/libstdc++-v3/src/c++98/mt_allocator.cc: In member
function 'std::size_t __gnu_cxx::__pool<true>::_M_get_thread_id()':
../../../../../../gcc/libstdc++-v3/src/c++98/mt_allocator.cc:630:25:
error: cast from 'void*' to 'std::size_t {aka unsigned int}' loses
precision [-fpermissive]
  size_t _M_id = (size_t)v;
                         ^
../../../../../../gcc/libstdc++-v3/src/c++98/mt_allocator.cc:643:52:
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
      __gthread_setspecific(freelist._M_key, (void*)_M_id);
                                                    ^
Thanks.

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill@OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985




More information about the Gcc mailing list