All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Yubin Ruan <ablacktshirt@gmail.com>
Cc: perfbook@vger.kernel.org
Subject: Re: Invalid compilation without -fno-strict-aliasing
Date: Fri, 3 Nov 2017 07:38:23 -0700	[thread overview]
Message-ID: <20171103143823.GL3624@linux.vnet.ibm.com> (raw)
In-Reply-To: <CAJYFCiNcZZeAvhLZAj=wxwuEvqGyv7QH9S5r-ehK0eYt+bmy0g@mail.gmail.com>

On Fri, Nov 03, 2017 at 10:12:48PM +0800, Yubin Ruan wrote:
> 2017-11-03 22:03 GMT+08:00 Paul E. McKenney <paulmck@linux.vnet.ibm.com>:
> > On Fri, Nov 03, 2017 at 09:33:48PM +0800, Yubin Ruan wrote:
> >> Thanks Paul,
> >>
> >> 2017-11-03 20:27 GMT+08:00 Paul E. McKenney <paulmck@linux.vnet.ibm.com>:
> >> > On Fri, Nov 03, 2017 at 09:54:15AM +0800, Yubin Ruan wrote:
> >> >> Does anyone have any idea why this thread
> >> >>
> >> >>     https://lkml.org/lkml/2003/2/25/270
> >> >
> >> > Hmmm...  This is quite the blast from the past.  Compilers have changed
> >> > a bit in the last 14 years.  Nevertheles...
> >>
> >> Unfortunately I got several old servers with GCC 3.x so I have to keep
> >> an eye on these things (and worse, I am one of those guys who like to
> >> home-brew some locking primitives...)
> >>
> >> >> is related to strict-aliasing? To me, a compiler barrier like this will fix it:
> >> >>
> >> >>     if((stream + event_len) < ends) {
> >> >>         iwe->len = event_len;
> >> >>         barrier();
> >> >>         memcpy(stream, (char *) iwe, event_len);
> >> >>         stream += event_len;
> >> >>     }
> >> >
> >> > As with many bugs, there are a number of ways to fix this one.  I suggest taking
> >> > a look at the documentation for -no-strict-alias.  This stackoverflow URL might
> >> > not be a bad place to start:
> >> >
> >> > https://stackoverflow.com/questions/23848188/strict-aliasing-rule-and-char-pointers
> >>
> >> Basically I understand what aliasing means (for the C/C++ Languages)
> >> and I know what a strict aliasing rule it is. I just cannot see why a
> >> strict aliasing rule will cause this reordering problem...
> >
> > OK.  Then please tell me why exactly you believe that strict aliasing does
> > not allow the compiler to reverse the order of the first two statements
> > in the body of the above "if" statement.
> 
> Indeed, the compiler is free to reorder those two statements and
> strict aliasing does not prevent the compiler from doing so. But, from
> my perspective, this reordering issue might just come from some other
> optimization rules (so we have to use barrier()), not because of the
> strict aliasing rule.
> 
> Hmm... am I missing anything?

When you tell gcc -no-strict-aliasing (which is a non-standard extension,
not part of the C language), the compiler is required to allow for the
fact that two pointers of different types might well reference the same
location(s).  In this case, the compiler cannot reverse the statements,
just as it would not be allowed to reverse the order of equivalent
non-pointer statements.

							Thanx, Paul


  reply	other threads:[~2017-11-03 14:38 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-03  1:54 Invalid compilation without -fno-strict-aliasing Yubin Ruan
2017-11-03 12:27 ` Paul E. McKenney
2017-11-03 13:33   ` Yubin Ruan
2017-11-03 14:03     ` Paul E. McKenney
2017-11-03 14:12       ` Yubin Ruan
2017-11-03 14:38         ` Paul E. McKenney [this message]
2017-11-03 23:26           ` Yubin Ruan
2017-11-03 23:55             ` Paul E. McKenney
2017-11-04  0:24               ` Yubin Ruan
  -- 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
2003-02-25 23:46 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
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

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=20171103143823.GL3624@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=ablacktshirt@gmail.com \
    --cc=perfbook@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.