From owner-freebsd-current@FreeBSD.ORG Sun Nov 12 15:12:35 2006 Return-Path: X-Original-To: current@freebsd.org Delivered-To: freebsd-current@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2DE1616A40F; Sun, 12 Nov 2006 15:12:35 +0000 (UTC) (envelope-from keramida@freebsd.org) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5EC1B43D66; Sun, 12 Nov 2006 15:12:30 +0000 (GMT) (envelope-from keramida@freebsd.org) Received: from kobe.laptop (host155-42.pool8174.interbusiness.it [81.74.42.155] (may be forged)) (authenticated bits=128) by igloo.linux.gr (8.13.8/8.13.8/Debian-2) with ESMTP id kACFC3Kj002654 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sun, 12 Nov 2006 17:12:09 +0200 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.13.8/8.13.8) with ESMTP id kACFBqkf003046; Sun, 12 Nov 2006 16:11:54 +0100 (CET) (envelope-from keramida@freebsd.org) Received: (from keramida@localhost) by kobe.laptop (8.13.8/8.13.8/Submit) id kACFBpBo003045; Sun, 12 Nov 2006 16:11:51 +0100 (CET) (envelope-from keramida@freebsd.org) Date: Sun, 12 Nov 2006 16:11:51 +0100 From: Giorgos Keramidas To: Ruslan Ermilov Message-ID: <20061112151150.GA2988@kobe.laptop> References: <20061112133929.9194773068@freebsd-current.sentex.ca> <20061112140010.GA47660@rambler-co.ru> <20061112142710.GE91556@wombat.fafoe.narf.at> <20061112133929.9194773068@freebsd-current.sentex.ca> <20061112140010.GA47660@rambler-co.ru> <20061112144230.GC2331@kobe.laptop> <20061112145151.GC49703@rambler-co.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20061112145151.GC49703@rambler-co.ru> X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (score=-2.463, required 5, autolearn=not spam, BAYES_00 -2.60, FORGED_RCVD_HELO 0.14, UNPARSEABLE_RELAY 0.00) X-Hellug-MailScanner-From: keramida@freebsd.org X-Spam-Status: No Cc: arm@freebsd.org, current@freebsd.org Subject: Re: [head tinderbox] failure on arm/arm X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Nov 2006 15:12:35 -0000 On 2006-11-12 17:51, Ruslan Ermilov wrote: > On Sun, Nov 12, 2006 at 03:42:30PM +0100, Giorgos Keramidas wrote: > > On 2006-11-12 17:00, Ruslan Ermilov wrote: > > > %%% > > > $ cat a.c > > > struct foo { > > > char x; > > > }; > > > > > > struct foo * > > > bubu(char *s) > > > { > > > > > > return (struct foo *)s; > > > } > > > $ cc -c -Wcast-align a.c > > > a.c: In function `bubu': > > > a.c:9: warning: cast increases required alignment of target type > > > %%% > > > > > > (None of other supported architecutes see the issue here.) > > > > You can't cast any random (char *) pointer to a pointer of a type which > > is (potentially) larger than 1 byte. It's the same sort of warning you > > will get if you try to: > > > > char ch[] = "\x00\x00\x00\x00"; > > char *p = &(ch[0]); > > unsigned long *lptr = (unsigned long *)p; > > > > You cannot guarantee that `ch' is stored in an address that is properly > > aligned for (unsigned long), and this is what GCC warns about here. > > No, your example I perfectly understand but it is completely different. > Note that the first (and only) member in my structure is "char", so it > doesn't need to be more than sizeof(char) aligned. Ah, but the tricky part is that inside bubu() there is no knowledge that `s' may be properly aligned for a (struct foo *) pointer. All the compiler knows is that it is a (char *), possibly misaligned for any pointer whose object has a size > 1. > > On 2006-11-12 15:27, Stefan Farfeleder wrote: > > > What is sizeof(struct foo)? If it's > 1 it makes sense. > > > > Exactly :) > > Still doesn't make much sense to me. If all structure members are chars > (like is the case with "struct ar_hdr" from which GCC complains > about, and in my example, the required alignment shouldn't be more than > sizeof(char). What am I missing? You are missing that inside bubu() the compiler 'believes' that: * The `s' pointer is (char *)-aligned. * The sizeof(struct foo) is >1. * You are trying to assign `s' (with it's possibly misaligned value) to the `return value' place, whose type is (at least, as far as the compiler knows) is (struct foo *). That may break alignment assumptions the compiler is making inside bubu(), especially about the `s' pointer, hence the warning. - Giorgos