From owner-cvs-src@FreeBSD.ORG Sat Mar 4 22:52:27 2006 Return-Path: X-Original-To: cvs-src@FreeBSD.org Delivered-To: cvs-src@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5C17016A420; Sat, 4 Mar 2006 22:52:27 +0000 (GMT) (envelope-from mux@freebsd.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0CE1543D48; Sat, 4 Mar 2006 22:52:27 +0000 (GMT) (envelope-from mux@freebsd.org) Received: by elvis.mu.org (Postfix, from userid 1920) id F105E1A4E61; Sat, 4 Mar 2006 14:52:26 -0800 (PST) Date: Sat, 4 Mar 2006 23:52:26 +0100 From: Maxime Henrion To: Joseph Koshy Message-ID: <20060304225226.GS55746@elvis.mu.org> References: <200603031854.k23IsXeJ062568@repoman.freebsd.org> <20060304154259.8A7BE16A422@hub.freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060304154259.8A7BE16A422@hub.freebsd.org> User-Agent: Mutt/1.4.2.1i Cc: cvs-src@FreeBSD.org, src-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/sys/sys queue.h X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Mar 2006 22:52:27 -0000 Joseph Koshy wrote: > > > mux 2006-03-03 18:54:33 UTC > > > > FreeBSD src repository > > > > Modified files: > > sys/sys queue.h > > Log: > > Cast the pointer to void * before casting it back to struct type * in > > STAILQ_LAST. This quiets a warning from GCC about increased required > > alignment for the cast. > > > > Idea from: cognet > > Doesn't this trade a compile time warning for a runtime fault on those > architectures where alignment matters? It doesn't, or the STAILQ_LAST macro simply wouldn't work on those architectures, and we know it does work. > Which code triggers this warning? > > 274 #define STAILQ_LAST(head, type, field) \ > 275 (STAILQ_EMPTY((head)) ? \ > 276 NULL : \ > 277 ((struct type *) \ > 278 ((char *)((head)->stqh_last) - __offsetof(struct type, field)))) It is apparently the cast to char * that makes GCC unhappy, because we later cast back to struct type * which has different alignment constraints than char *, obviously. We cannot just remove the cast to char * since it is needed to perform pointer arithmetic. I have no idea why a simple cast to void * is sufficient to shut him up but I'm not going to complain :-). > I can't see how this code would trigger a warning in normal usage. Well, write a snippet of code that uses STAILQ_LAST and try to compile it with -O2 and WARNS=6 on alpha and see by yourself. Or look at the last tinderbox failure e-mails for alpha. Cheers, Maxime