public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Horst von Brand <vonbrand@inf.utfsm.cl>,
	Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>,
	jt@hpl.hp.com,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: Invalid compilation without -fno-strict-aliasing
Date: Wed, 26 Feb 2003 17:22:13 -0500	[thread overview]
Message-ID: <20030226172213.O3910@devserv.devel.redhat.com> (raw)
In-Reply-To: <20030226205754.GA29466@nevyn.them.org>; from dan@debian.org on Wed, Feb 26, 2003 at 03:57:54PM -0500

On Wed, Feb 26, 2003 at 03:57:54PM -0500, Daniel Jacobowitz wrote:
> > > > > 	if((stream + event_len) < ends) {
> > > > > 		iwe->len = event_len;
> > > > > 		memcpy(stream, (char *) iwe, event_len);
> > > > > 		stream += event_len;
> > > > > 	}
> > > > > 	return stream;

> > > > The compiler is free to assume char *stream and struct iw_event *iwe
> > > > point to separate areas of memory, due to strict aliasing.

No.

> Stream is not the same storage as iwe, so this is hardly the issue. 
> Writes to stream don't affect iwe.  The problem was the assignment to
> iwe->len being moved after the access, according to the report.

GCC can do that with -fstrict-aliasing:
All calls to this inline function are done with constant event_len.
E.g. in case of event_len = IW_EV_UINT_LEN, memcpy macro expands to
__constant_memcpy which does:
                        *(unsigned long *)to = *(const unsigned long *)from;
                        *(1+(unsigned long *)to) = *(1+(const unsigned long *)from);
iwe->len is unsigned short and the code writes the value as
unsigned short (iwe->len = 8) and then reads the same memory as unsigned
long (something = *(const unsigned long *)(char *)iwe). But those two types
cannot alias and thus gcc can reorder them.

To fix that, __constant_memcpy would have to access the data through
union, ir you could as well forget about __constant_memcpy and use
__builtin_memcpy where gcc will take care about the constant copying.

	Jakub

  reply	other threads:[~2003-02-26 22:12 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-25 23:46 Invalid compilation without -fno-strict-aliasing Jean Tourrilhes
2003-02-26 15:38 ` Horst von Brand
2003-02-26 16:04   ` Falk Hueffner
2003-02-26 20:47     ` Horst von Brand
2003-02-26 20:57       ` Daniel Jacobowitz
2003-02-26 22:22         ` Jakub Jelinek [this message]
2003-02-27 19:30           ` Linus Torvalds
2003-02-27 19:45             ` Daniel Jacobowitz
2003-02-27 20:00               ` Linus Torvalds
2003-02-27 20:35                 ` Daniel Jacobowitz
2003-02-27 20:38                   ` Linus Torvalds
2003-02-27 23:55                     ` H. Peter Anvin
2003-03-01  8:29                     ` Anton Blanchard
2003-02-26 17:22   ` Jean Tourrilhes
2003-02-26 21:07     ` Horst von Brand
2003-02-27  4:41       ` Daniel Phillips
2003-02-26 17:26 ` Linus Torvalds
  -- strict thread matches above, loose matches on Subject: below --
2003-02-26  4:33 Albert Cahalan
2003-02-26 17:20 ` Jean Tourrilhes
2003-02-26 18:23   ` Richard B. Johnson
2003-02-26 19:22     ` Daniel Jacobowitz
2003-02-26 19:40       ` Richard B. Johnson
2003-02-26 19:42         ` Daniel Jacobowitz
2003-02-26 20:19           ` Richard B. Johnson
2003-02-26 21:30             ` Albert Cahalan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030226172213.O3910@devserv.devel.redhat.com \
    --to=jakub@redhat.com \
    --cc=falk.hueffner@student.uni-tuebingen.de \
    --cc=jt@hpl.hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vonbrand@inf.utfsm.cl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox