From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19566 invoked by alias); 26 Jul 2005 23:52:44 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 19542 invoked by uid 22791); 26 Jul 2005 23:52:39 -0000 Received: from smtp.gentoo.org (HELO smtp.gentoo.org) (134.68.220.30) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Tue, 26 Jul 2005 23:52:39 +0000 Received: from cp237988-a.mill1.nb.home.nl ([84.29.209.70] helo=[192.168.1.66]) by smtp.gentoo.org with esmtpa (Exim 4.43) id 1DxZDx-0003rH-E3 for gcc-help@gcc.gnu.org; Tue, 26 Jul 2005 23:52:37 +0000 Message-ID: <42E6CE1E.3080200@gentoo.org> Date: Tue, 26 Jul 2005 23:52:00 -0000 From: =?UTF-8?B?SGFyYWxkIHZhbiBExLNr?= User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716) MIME-Version: 1.0 To: gcc-help@gcc.gnu.org Subject: -fstrict-aliasing, -Wstrict-aliasing=2, and indirect conversions Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2005-07/txt/msg00290.txt.bz2 Hello, int main() { int a = 1; short *b = (short *) (char *) &a; *b = 2; return a; } This simple program returns 1 when compiled with -O2 -fstrict-aliasing, and 2 when compiled with -O2 -fno-strict-aliasing. It does not produce any warnings with -Wstrict-aliasing=2. According to the documentation: `-Wstrict-aliasing=2' This option is only active when `-fstrict-aliasing' is active. It warns about all code which might break the strict aliasing rules that the compiler is using for optimization. This warning catches all cases, but it will also give a warning for some ambiguous cases that are safe. Is this a bug? If so, what is the bug? Is the warning missing, or is the optimization invalid? And are there any alternative options that really catch every aliasing problem? I'm using gcc 4.0.1 on i686-pc-linux-gnu. Thanks in advance for any replies.