From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23100 invoked by alias); 21 Nov 2009 22:48:20 -0000 Received: (qmail 23024 invoked by uid 48); 21 Nov 2009 22:48:05 -0000 Date: Sat, 21 Nov 2009 22:48:00 -0000 Subject: [Bug c/42136] New: Inconsistent strict-aliasing warning with cast from char[] X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "astrange at ithinksw dot com" 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: 2009-11/txt/msg01817.txt.bz2 Source: typedef union u { unsigned i; unsigned short s[2]; unsigned char c[4]; } u; char c[4] __attribute__((aligned)); short s[2] __attribute__((aligned)); int f1() { return ((union u*)s)->i; } int f2() { return ((union u*)c)->i; } Using gcc 4.5: > gcc -O3 -fstrict-aliasing -Wall -S wstrict_aliasing_char.c wstrict_aliasing_char.c: In function 'f2': wstrict_aliasing_char.c:13:17: warning: dereferencing type-punned pointer will break strict-aliasing rules I would expect either both or neither of the functions to warn, since pointer casting to unions is given in the manual as something that violates strict-aliasing, although gcc doesn't seem to actually take advantage of this. Instead, it looks like the warning is hardcoded to apply to a cast from char (c-common.c:1746 in r1554411): alias_set_type set1 = get_alias_set (TREE_TYPE (TREE_OPERAND (expr, 0))); alias_set_type set2 = get_alias_set (TREE_TYPE (type)); if (set1 != set2 && set2 != 0 && (set1 == 0 || !alias_sets_conflict_p (set1, set2))) { warning (OPT_Wstrict_aliasing, "dereferencing type-punned " "pointer will break strict-aliasing rules"); return true; } This came up during some x264 work, but it's taken care of now with some __attribute__((may_alias)). -- Summary: Inconsistent strict-aliasing warning with cast from char[] Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: astrange at ithinksw dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42136