Sent from my iPhone
On Jul 6, 2009, at 6:12 PM, "mikulas at artax dot karlin dot mff dot
cuni dot cz" <gcc-bugzi...@gcc.gnu.org> wrote:
Gcc became recently (4.4) very bad regarding false positive type-
punned
warnings. In previous versions, the warnings could be suppressed by
casting to
(void *), in 3.x and 4.1 it worked perfectly, in 4.3 it still worked
somehow
(except in -Wstrict-aliasing=3 mode), in 4.4 there are cases where
it doesn't
work at all.
I don't want to completely disable the warnings with -Wno-strict-
aliasing (this
could leave bugs unnotified), but I need a method to disable them on
case-by-case basis once I verified that the code in question is
correct.
Simple example, compile with -O2 -Wall:
extern int c;
int a(void)
{
return *(short *)(void *)&c;
}
This is a very bad example of a false positive as you are acessing an
int as a short; that is undefined. I will look at your code later on,
my laptop for home is currently broken.
In 4.4 the warning can't be disabled at all! The (void *) cast
doesn't suppress
the warning and none of three options to -Wstrict-aliasing helps. In
4.3 the
cast to (void *) suppressed the warning in -Wstrict-aliasing 1,2
modes (and
didn't suppress it in the default mode 3), in 4.4 the warning can't be
suppressed at all.
Gcc developers tried to made these warnings more "intelligent" with
less false
positives, but unfortunatelly they completely broke the method to
disable them
in the specific case. For me, false positives are not a major
problem --- when
I get a false positive, I just read the code, check it and if I
conclude that
it's OK, I disable the warning with (void *).
But if there's no way to disable false positives, it makes the
warnings
completely useless.
--
Summary: dereferencing type-punned pointer warnings cannot
be
disabled
Product: gcc
Version: 4.4.1
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: regression
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mikulas at artax dot karlin dot mff dot cuni dot cz
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40665