This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/79142] bit shift + compare returns wrong value
- From: "layer at known dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 19 Jan 2017 00:04:14 +0000
- Subject: [Bug c/79142] bit shift + compare returns wrong value
- Auto-submitted: auto-generated
- References: <bug-79142-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79142
--- Comment #1 from layer at known dot net ---
And the code:
#include <stdio.h>
/* whatever the shift in badexample does,
* the function should never return 1
*/
long
badexample(unsigned long iv)
{
long ov = ((long)(1)) << ((iv & 0x3f) + 1);
if (ov == 1)
ov = 0;
return ov;
}
int
main()
{
int i;
for(i=60;i<65;i++)
printf("%d=>0x%lx\n",i&63,badexample(i&63));
}