public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/42136] New: Inconsistent strict-aliasing warning with cast from char[]
@ 2009-11-21 22:48 astrange at ithinksw dot com
2009-11-21 22:56 ` [Bug c/42136] " rguenth at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: astrange at ithinksw dot com @ 2009-11-21 22:48 UTC (permalink / raw)
To: gcc-bugs
Source:
typedef union u { unsigned i; unsigned short s[2]; unsigned char c[4]; } u;
char c[4] __attribute__((aligned));
short s[2] __attribute__((aligned));
int f1()
{
return ((union u*)s)->i;
}
int f2()
{
return ((union u*)c)->i;
}
Using gcc 4.5:
> gcc -O3 -fstrict-aliasing -Wall -S wstrict_aliasing_char.c
wstrict_aliasing_char.c: In function 'f2':
wstrict_aliasing_char.c:13:17: warning: dereferencing type-punned pointer will
break strict-aliasing rules
I would expect either both or neither of the functions to warn, since pointer
casting to unions is given in the manual as something that violates
strict-aliasing, although gcc doesn't seem to actually take advantage of this.
Instead, it looks like the warning is hardcoded to apply to a cast from char
(c-common.c:1746 in r1554411):
alias_set_type set1 =
get_alias_set (TREE_TYPE (TREE_OPERAND (expr, 0)));
alias_set_type set2 = get_alias_set (TREE_TYPE (type));
if (set1 != set2 && set2 != 0
&& (set1 == 0 || !alias_sets_conflict_p (set1, set2)))
{
warning (OPT_Wstrict_aliasing, "dereferencing type-punned "
"pointer will break strict-aliasing rules");
return true;
}
This came up during some x264 work, but it's taken care of now with some
__attribute__((may_alias)).
--
Summary: Inconsistent strict-aliasing warning with cast from
char[]
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: astrange at ithinksw dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42136
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c/42136] Inconsistent strict-aliasing warning with cast from char[]
2009-11-21 22:48 [Bug c/42136] New: Inconsistent strict-aliasing warning with cast from char[] astrange at ithinksw dot com
@ 2009-11-21 22:56 ` rguenth at gcc dot gnu dot org
0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-11-21 22:56 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from rguenth at gcc dot gnu dot org 2009-11-21 22:56 -------
!alias_sets_conflict_p (set1, set2) should really be alias_set_subset_of
with all the added false positives from the very imprecise frontend code
that this would cause.
Thus, the cast from short[] also should warn.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |diagnostic
Last reconfirmed|0000-00-00 00:00:00 |2009-11-21 22:56:31
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42136
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-11-21 22:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-21 22:48 [Bug c/42136] New: Inconsistent strict-aliasing warning with cast from char[] astrange at ithinksw dot com
2009-11-21 22:56 ` [Bug c/42136] " rguenth at gcc dot gnu dot org
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).