From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2199 invoked by alias); 18 Mar 2012 09:32:35 -0000 Received: (qmail 2190 invoked by uid 22791); 18 Mar 2012 09:32:35 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_GM 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; Sun, 18 Mar 2012 09:32:22 +0000 From: "pluto at agmk dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug other/52609] -Wstrict-aliasing / missed diagnostics Date: Sun, 18 Mar 2012 12:53:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: other X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pluto at agmk dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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: 2012-03/txt/msg01475.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52609 --- Comment #2 from Pawel Sikora 2012-03-18 09:32:03 UTC --- (In reply to comment #1) > >accessing unsigned* via float* looks buggy > > It does not have to be if the original argument was originally of type float. > Aliasing is not about type of pointers but the type which is used to access and > such. ok, here's an updated testcase: $ cat alias-bug.c unsigned buffer[1]; float bug1( unsigned u ) { buffer[0]=u; return *(float*)(&buffer[0]); // warning. } float bug2( unsigned u ) { buffer[0]=u; float* ptr=(float*)&buffer[0]; return *ptr; // missed strict aliasing warning. } gcc repots warning only for bug1() and misses warning for bug2(): $ gcc -Wall -Wstrict-aliasing=3 -O2 alias-bug.c -c alias-bug.c: In function 'bug1': alias-bug.c:6:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]