Opened 3 years ago

Last modified 3 years ago

#11546 new bug

Compiler warning: cast from pointer to integer of different size

Reported by: wereHamster Owned by:
Priority: normal Milestone:
Component: Compiler Version:
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


While building the stage1 compiler:

In file included from rts/Capability.h:25:0,
                 from includes/dist-derivedconstants/header/tmp.c:15:
rts/Task.h: In function 'serialiseTaskId':
rts/Task.h:318:12: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
     return (TaskId) taskID;

I'm building a cross-compiler with build/host=x86_64-linux-gnu and target=mips-unknown-linux-musl

Change History (1)

comment:1 Changed 3 years ago by wereHamster

The cast is from OSThreadId (pthread_t) to TaskId (StgWord64). Musl defines the former as TYPEDEF struct __pthread * pthread_t.

pthread_t is not required to be an arithmetic type (it can be a struct), so musl does not violate POSIX (see, scroll to the very bottom, Issue 6).


  • Cast to (size_t) first, just like in the case of defined(freebsd_HOST_OS) || defined(darwin_HOST_OS) (see the implementation of the serialiseTaskId function). A dirty solution which may not work on platforms where pthread_t truly is a struct and not a pointer/integer.
  • Make TaskId a type alias for OSThreadId (because AFAICS the two are equal).
  • Allocate our own (numeric) Thread Ids and store them in TLS (on POSIX platforms), to be independent of the implementation of pthread_t.
  • Simply give up on platforms where pthread_t is not an alias for an arithmetic type (probably difficult to detect at compile / configure time).
Note: See TracTickets for help on using tickets.