This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/46702] New: inlining generates strict-aliasing warnings
- From: "gnb at fastmail dot fm" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 29 Nov 2010 05:21:59 +0000
- Subject: [Bug c/46702] New: inlining generates strict-aliasing warnings
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46702
Summary: inlining generates strict-aliasing warnings
Product: gcc
Version: 4.4.5
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: gnb@fastmail.fm
Inlining a function which does dereferences cast pointers can cause
strict-aliasing warnings, where the same function not inlined causes
no warnings. This is surprising and counterintuitive; one would expect
the function would be correct or not regardless of the inlining context.
Test case:
#include <stdint.h>
extern int baz(const char *);
#ifdef NOWARNINGS
void foo(char *p) __attribute__((noinline));
#endif
void foo(char *p)
{
*(uint32_t *)p = 0x42;
}
void bar(void)
{
union { char c[4]; uint64_t alignment; } buf;
char *x = (char *)&buf;
foo(x);
baz(x);
}
me@mybox> gcc -c -o foo.o -O2 -Wall -Wextra foo.c
foo.c: In function âbarâ:
foo.c:11: warning: dereferencing pointer âp.0â does break strict-aliasing rules
foo.c:11: note: initialized from here
me@mybox> gcc -c -o foo.o -O2 -Wall -Wextra -DNOWARNINGS foo.c
me@mybox> gcc --version
gcc (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Seen in the wild in this code:
http://git.cyrusimap.org/cyrus-imapd/tree/imap/mbdump.c#n109