public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/26492] New: -Wstrict-aliasing=2 warns about explicitly allowed cast to pointer to union.
@ 2006-02-28 1:09 bartoldeman at users dot sourceforge dot net
2006-02-28 1:10 ` [Bug c/26492] " pinskia at gcc dot gnu dot org
2006-02-28 1:29 ` bartoldeman at users dot sourceforge dot net
0 siblings, 2 replies; 3+ messages in thread
From: bartoldeman at users dot sourceforge dot net @ 2006-02-28 1:09 UTC (permalink / raw)
To: gcc-bugs
In a discussion about aliasing, some aliasing was explicitly allowed: see
http://gcc.gnu.org/ml/gcc/1999-06n/msg00294.html
from Mark Mitchell.
quote: "
extern void printf(const char*, ...);
#define noalias(type, ptr) \
(((union { type __x__; __typeof__(*(ptr)) __y__;} *)(ptr))->__x__)
typedef unsigned short usa[2];
int
main ()
{
int a = 0x12345678;
printf ("%x\n", a);
noalias(usa, &a)[1] = 0;
printf ("%x\n", a);
return 0;
}
Here's what I get:
linux1.codesourcery.com% ./a.out
12345678
5678
which is I think what you expected.
"
This still works, but with gcc 4.0.3 and -Wstrict-aliasing=2 I see:
(using #include <stdio.h> instead of extern void printf...)
$ gcc -O2 -Wstrict-aliasing=2 alias.c
alias.c: In function 'main':
alias.c:13: warning: dereferencing type-punned pointer might break
strict-aliasing rules
$ ./a.out
12345678
5678
It would be nice if the warning would not trigger in this case. Although the
documentation does not say it must trigger, this is claimed to be a documented
extension and should work warning-free IMHO.
--
Summary: -Wstrict-aliasing=2 warns about explicitly allowed cast
to pointer to union.
Product: gcc
Version: 4.0.3
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: bartoldeman at users dot sourceforge dot net
GCC build triplet: i486-linux-gnu
GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26492
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-02-28 1:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-28 1:09 [Bug c/26492] New: -Wstrict-aliasing=2 warns about explicitly allowed cast to pointer to union bartoldeman at users dot sourceforge dot net
2006-02-28 1:10 ` [Bug c/26492] " pinskia at gcc dot gnu dot org
2006-02-28 1:29 ` bartoldeman at users dot sourceforge dot net
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).