Bug 44985 - warnings: gcc shifts integer by its entire size
Summary: warnings: gcc shifts integer by its entire size
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 5.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-19 07:25 UTC by Jay
Modified: 2021-05-31 01:36 UTC (History)
1 user (show)

See Also:
Host:
Target:
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 Jay 2010-07-19 07:25:24 UTC
Hm, it seems on some 32bit systems, where there is no -m64, wideint can be a mere 32bits.
 
In which case the code should probably say:
 
hwi = ((hwi >> (shift - 1)) >> 1);
 
This was targeting OpenBSD/x86.
Maybe I should just stick need_64bit_hwint = yes on config.gcc for that and move along?
Assume there is always long long or __int64?
Coverage of this case is pretty rare now from my skimming.
 
 - Jay
 
----------------------------------------
> From: jay.krell@cornell.edu
> To: gcc@gcc.gnu.org
> Subject: suggest assert wide_int larger than hashval_t
> Date: Mon, 19 Jul 2010 06:44:33 +0000
>
>
> I get this in 4.3.5:
>
> ../../gcc/gcc/varasm.c: In function `const_rtx_hash_1':
> ../../gcc/gcc/varasm.c:3387: warning: right shift count >= width of type
>
> ./include/hashtab.h:typedef unsigned int hashval_t;
>
>   unsigned HOST_WIDE_INT hwi;
>   hashval_t h, *hp;
>  ...
>     const int shift = sizeof (hashval_t) * CHAR_BIT;
>     const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
>     int i;
>
>     h ^= (hashval_t) hwi;
>     for (i = 1; i < n; ++i)
>       {
>         hwi >>= shift;  here
>
>
> It looks about the same in 4.5.0 except without const:
>
>
>     int shift = (sizeof (hashval_t) * CHAR_BIT);
>
>
> Something is amiss here locally, for the types to be the same size.
>
>
> But maybe add gcc_assert(sizeof(hashval_t) < sizeof(HOST_WIDE_INT),
> outside the loop? It should be optimized away anyway.
>
>
> Maybe I'd get -Werror but I use -disable-bootstrap.
> Native compiler is gcc, but old.
>
>
> Thanks,
>  - Jay
Comment 1 Andrew Pinski 2021-05-31 01:36:00 UTC
HOST_WIDE_INT has been 64bit always since GCC 5 since r5-894 so this is no longer a bug.