[Bug c/60581] New: gcc doesn't isssue a strict aliasing warning on a code that seems to break it
galtgendo at o2 dot pl
gcc-bugzilla@gcc.gnu.org
Wed Mar 19 09:07:00 GMT 2014
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60581
Bug ID: 60581
Summary: gcc doesn't isssue a strict aliasing warning on a code
that seems to break it
Product: gcc
Version: 4.7.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: galtgendo at o2 dot pl
The problem is described here: https://bugs.gentoo.org/show_bug.cgi?id=505026
The code to trigger comes from a launchpad bug:
https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1072650
As you may notice, it's acros distros and affects many compiler versions
(confirmed for 4.6.3 on ubuntu, 4.7.3 and 4.8.2 on Gentoo).
Following code (AFAICT) violates strict aliasing rules:
#include <stdio.h>
struct psuedo_hdr
{
int saddr;
int daddr;
char zero;
char protocol;
short len;
} __attribute__((packed));
int main()
{
unsigned int i;
unsigned int sum = 0;
struct psuedo_hdr hdr;
hdr.saddr = 0xaabbccdd;
hdr.daddr = 0x11223344;
hdr.zero = 0;
hdr.protocol = 6;
hdr.len = 2;
for (i = 0; i < sizeof(hdr); i += 2)
sum += *(short *)((char *)(&hdr) + i);
printf("0x%x\n", sum);
return 0;
}
however, '-O2 -Wall' doesn't result in the strict aliasing warning.
More information about the Gcc-bugs
mailing list