From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21195 invoked by alias); 10 Nov 2004 02:41:02 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 21098 invoked from network); 10 Nov 2004 02:40:56 -0000 Received: from unknown (HELO smtp3.libero.it) (193.70.192.127) by sourceware.org with SMTP; 10 Nov 2004 02:40:56 -0000 Received: from localhost (172.16.1.84) by smtp3.libero.it (7.0.027-DD01) id 4178F14A00497F52; Wed, 10 Nov 2004 03:40:54 +0100 Received: from bagio (151.41.185.70) by smtp2.libero.it (7.0.027-DD01) id 40CB2A0805D69021; Wed, 10 Nov 2004 03:41:22 +0100 Message-ID: <2dd501c4c6cf$079a7730$46b92997@bagio> From: "Giovanni Bajo" To: "Anders Torger" Cc: References: <200411092023.46209.torger@ludd.luth.se> Subject: Re: No warning when breaking strict-aliasing rules despite -Wstrict-aliasing Date: Wed, 10 Nov 2004 02:41:00 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at libero.it serv5 X-SW-Source: 2004-11/txt/msg01216.txt.bz2 List-Id: Anders Torger wrote: > I found a case where GCC does not warn even with > -Wstrict-aliasing, but makes incorrect asm code anyway. > unsigned long > hash(void *key) > { > unsigned long long u[1]; > u[0] = *(unsigned long long *)key; > return ((unsigned long *)u)[0] ^ ((unsigned long *)u)[1]; > } There is absolutely no guarantee that we always generate a warning for every possible type-aliasing violation. For instance, if you passed the pointer to a double as "key" to this function, we could not possibly find it out and emit a warning. Nonetheless, there is a problem here: we could easily emit a warning on this line: > return ((unsigned long *)u)[0] ^ ((unsigned long *)u)[1]; but we do not. The problem appears to be in c-typeck.c, in build_c_cast(): if (TREE_CODE (type) == POINTER_TYPE && TREE_CODE (otype) == POINTER_TYPE && TREE_CODE (expr) == ADDR_EXPR && DECL_P (TREE_OPERAND (expr, 0)) && flag_strict_aliasing && warn_strict_aliasing && !VOID_TYPE_P (TREE_TYPE (type))) The code only warns for expressions like "(cast*)&decl", but "(cast*)array_decl" is also something to warn about. This is a possible enhancement. Would you please file a bug report in Bugzilla about this? Thanks, Giovanni Bajo