Bug 93269 - 32bit-pointer to uint64_t cast sign-extends
Summary: 32bit-pointer to uint64_t cast sign-extends
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 9.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-14 19:03 UTC by Jan Kratochvil
Modified: 2020-01-14 19:43 UTC (History)
0 users

See Also:
Host:
Target: x86_64-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Kratochvil 2020-01-14 19:03:28 UTC
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
int main() {
void *p=(void *)0x80000000;
printf(  "%p"        "\n",                           p );// 0x80000000
printf("0x%" PRIxPTR "\n",                (uintptr_t)p );// 0x80000000
printf("0x%" PRIx64  "\n",reinterpret_cast<uint64_t>(p));// 0xffffffff80000000
printf("0x%" PRIx64  "\n",                (uint64_t) p );// 0xffffffff80000000
printf("0x%" PRIx64  "\n",      (uint64_t)(uintptr_t)p );// 0x80000000
}


gcc-9.2.1-1.fc30.x86_64
g++ -o addr_t2 addr_t2.cpp -Wall -g -m32
0x80000000
0x80000000
0xffffffff80000000
0xffffffff80000000
0x80000000

clang-8.0.0-3.fc30.x86_64
clang++ -o addr_t2 addr_t2.cpp -Wall -g -m32 ;./addr_t2
0x80000000
0x80000000
0x80000000
0x80000000
0x80000000

It may be in some standard but it looks suspicious to me.
Comment 2 Andrew Pinski 2020-01-14 19:20:21 UTC
This is implementation defined area.  And is documented.  Neither is clang or gcc is wrong.  Now I dont know where clang it is documented but I posted where gcc behavior is documented. So closing as invalid.
Comment 3 Andrew Pinski 2020-01-14 19:20:35 UTC
.
Comment 4 Jan Kratochvil 2020-01-14 19:43:04 UTC
Thanks.