Bug 36385 - Assume that long is scalar size of a pointer
Summary: Assume that long is scalar size of a pointer
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 36386 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-05-30 08:22 UTC by Kai Tietz
Modified: 2009-09-08 15:35 UTC (History)
3 users (show)

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


Attachments
Remove cast warnings for target with sizeof (void *)>sizeof(long) (393 bytes, patch)
2009-08-31 19:29 UTC, Kai Tietz
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kai Tietz 2008-05-30 08:22:17 UTC
In tree-ssa-reassoc.c the code assumes wrongly, that the 'long' scalar type has pointer size width. This is at least for w64 not true.
As reference see insert_operand_rank(), and find_operand_rank.
Comment 1 Andrew Pinski 2008-05-30 09:55:34 UTC
It just assume that the size of a pointer is at least the sizeof long so this only causes a warning.  This fact is true for w64 where long is 32bits while pointers are 64bits.
Comment 2 Andrew Pinski 2008-05-30 09:55:54 UTC
*** Bug 36386 has been marked as a duplicate of this bug. ***
Comment 3 Kai Tietz 2008-05-30 10:14:29 UTC
It true. Just two warnings are shown, but the back-cast of a long to a pointer on w64 in insert_operand_rank() is evil. If the pointer is on heap, it can be easily truncated and point to nowhere.
Comment 4 Andrew Pinski 2008-05-30 10:21:26 UTC
Look into the code rank is actually a number.  So we are taking an integer and storing it into a void* and then we will access it via find_operand_rank which casts the pointer back to an integer type.  operand_rank will only contains these integer and never a real pointer and is only modified by insert_operand_rank and only looked into by find_operand_rank.  So as mentioned this is not a bug which will cause wrong code.  We will never access what is contained in that pointer as it is not really a pointer.
Comment 5 Kai Tietz 2008-05-30 10:32:28 UTC
(In reply to comment #4)
I see. So just two misleading warnings are there.
Comment 6 Kai Tietz 2009-08-31 19:29:19 UTC
Created attachment 18457 [details]
Remove cast warnings for target with sizeof (void *)>sizeof(long)

If define __INTPTR_TYPE__ is present, this patch uses it to cast from pointer to long, and from long to pointer.

Tested for i686-pc-mingw32 and for x86_64-pc-mingw32.

Ok, for apply?
Comment 7 Kai Tietz 2009-09-08 15:35:05 UTC
Fixed by  revision 151515 for 4.5 version.
As this bug depends to new config/stdint.m4 and 2.64 support in gcc configure, this won't be backported to 4.4.x