From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29356 invoked by alias); 6 Oct 2010 20:57:09 -0000 Received: (qmail 29347 invoked by uid 22791); 6 Oct 2010 20:57:08 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,MISSING_MID,TW_BJ,TW_CX,TW_DC,TW_GX X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 06 Oct 2010 20:57:03 +0000 From: "rguenther at suse dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenther at suse dot de X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Date: Wed, 06 Oct 2010 20:57:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-10/txt/msg00568.txt.bz2 Message-ID: <20101006205700.Iz8cmiJpHdAQxMkkkzKmEq95Ri-S5Q7DtaKr42vmb9Y@z> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D41874 --- Comment #10 from rguenther at suse dot de 20= 10-10-06 20:56:56 UTC --- On Wed, 6 Oct 2010, muravev at yandex dot ru wrote: > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D41874 >=20 > --- Comment #9 from Ilya Murav'jov 2010-10-06 = 19:43:30 UTC --- > I've come across another weird warning emission in g++ 4.4: >=20 > $ cat test.cc > #include > struct interface_type { >=20 > virtual interface_type* clone(void* storage) const > { > return ::new (storage) interface_type(); > } > }; >=20 > struct poly_base { >=20 > poly_base(const interface_type& x) { x.clone(data); } >=20 > typedef char storage_t[100]; > storage_t data; > }; >=20 > struct instance_t: interface_type {}; >=20 > int main() > { > instance_t pi; > poly_base p1(pi); >=20 > interface_type* ptr =3D (interface_type*)(p1.data); > poly_base p2(*ptr); > } > $ g++ -O3 -Wstrict-aliasing test.cc -o /dev/null > test.cc: In function =E2=80=98int main()=E2=80=99: > test.cc:12: warning: dereferencing pointer =E2=80=98ptr=E2=80=99 does bre= ak strict-aliasing > rules > test.cc:25: note: initialized from here >=20 > $ g++ -v > Using built-in specs. > Target: i486-linux-gnu > Configured with: ../src/configure -v --with-pkgversion=3D'Ubuntu 4.4.1-4u= buntu9' > --with-bugurl=3Dfile:///usr/share/doc/gcc-4.4/README.Bugs > --enable-languages=3Dc,c++,fortran,objc,obj-c++ --prefix=3D/usr --enable-= shared > --enable-multiarch --enable-linker-build-id --with-system-zlib > --libexecdir=3D/usr/lib --without-included-gettext --enable-threads=3Dpos= ix > --with-gxx-include-dir=3D/usr/include/c++/4.4 --program-suffix=3D-4.4 --e= nable-nls > --enable-clocale=3Dgnu --enable-libstdcxx-debug --enable-objc-gc > --enable-targets=3Dall --disable-werror --with-arch-32=3Di486 --with-tune= =3Dgeneric > --enable-checking=3Drelease --build=3Di486-linux-gnu --host=3Di486-linux-= gnu > --target=3Di486-linux-gnu > Thread model: posix > gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9) >=20 > I get this only in g++ 4.4, g++ 4.5 does not warn. >=20 > I want to note that this is a different type of warning about strict-alia= sing > rules, likely a more serious one. Can anyone tell what a difference betwe= en > "warning: dereferencing type-punned pointer will break strict-aliasing ru= les" > and "warning: dereferencing pointer =E2=80=98ptr=E2=80=99 does break stri= ct-aliasing rules"? The latter means that when doing pointer analysis GCC pruned all=20 pointed-to objects using TBAA so the pointer ended up pointing to nothing (but still was dereferenced). The good news for you is that GCC will assume the pointer points to anything in that case, not nothing. In GCC 4.5 points-to analysis doesn't use TBAA to prune the sets anymore (because its fundamentally wrong), so the code emitting the warning was removed. Richard.