Opened 23 months ago

Last modified 20 months 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:

Description

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 20 months 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 http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html, scroll to the very bottom, Issue 6).

Alternatives:

  • 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.