public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103635] New: size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv
@ 2021-12-09 18:07 mark at harmstone dot com
  2021-12-09 22:34 ` [Bug target/103635] " redi at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: mark at harmstone dot com @ 2021-12-09 18:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103635

            Bug ID: 103635
           Summary: size_t and uintptr_t have wrong sizes with
                    x86_64-w64-mingw32-g++ -mabi=sysv
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mark at harmstone dot com
  Target Milestone: ---

When you add the option -mabi=sysv to mingw for amd64, it changes size_t and
uintptr_t from 64 to 32 bits.

Minimal example:

tmp.cpp:
#include <stddef.h>
static_assert(sizeof(size_t) == 8, "!");
static_assert(sizeof(uintptr_t) == 8, "!");

Working:
x86_64-pc-linux-gnu-g++ -mabi=ms -c tmp.cpp
x86_64-pc-linux-gnu-g++ -mabi=sysv -c tmp.cpp
x86_64-pc-cygwin-g++ -mabi=ms -c tmp.cpp
x86_64-pc-cygwin-g++ -mabi=sysv -c tmp.cpp
x86_64-w64-mingw32-g++ -mabi=ms -c tmp.cpp

Not working:
x86_64-w64-mingw32-g++ -mabi=sysv -c tmp.cpp
tmp.cpp:2:30: error: static assertion failed: !
    2 | static_assert(sizeof(size_t) == 8, "!");
      |               ~~~~~~~~~~~~~~~^~~~
tmp.cpp:3:33: error: static assertion failed: !
    3 | static_assert(sizeof(uintptr_t) == 8, "!");
      | 

My hunch is that perhaps GCC is assuming that long is the same size as a
pointer, which it's not on Windows. The SysV specs say that size_t is
equivalent to unsigned long on LP64 (but unsurprisingly doesn't mention the
LLP64 that Windows uses).

The practical problem this causes is that you can't #include <string> on mingw
with -mabi=sysv, as _mm_malloc amongst others uses size_t to do pointer
arithmetic.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-12-12 16:35 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-09 18:07 [Bug c++/103635] New: size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv mark at harmstone dot com
2021-12-09 22:34 ` [Bug target/103635] " redi at gcc dot gnu.org
2021-12-09 23:01 ` mark at harmstone dot com
2021-12-10  0:32 ` redi at gcc dot gnu.org
2021-12-10  0:36 ` mark at harmstone dot com
2021-12-10  0:46 ` pinskia at gcc dot gnu.org
2021-12-11 14:07 ` mark at harmstone dot com
2021-12-12  3:07 ` pinskia at gcc dot gnu.org
2021-12-12  3:42 ` mark at harmstone dot com
2021-12-12  3:45 ` pinskia at gcc dot gnu.org
2021-12-12 12:26 ` mark at harmstone dot com
2021-12-12 12:36 ` pinskia at gcc dot gnu.org
2021-12-12 16:35 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).