mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: Documentation of memcpy and undefined behavior in memset
Date: Thu, 6 Jul 2017 13:11:01 -0400	[thread overview]
Message-ID: <20170706171101.GD1627@brightrain.aerifal.cx> (raw)
In-Reply-To: <alpine.LNX.2.20.13.1707061957580.21060@monopod.intra.ispras.ru>

On Thu, Jul 06, 2017 at 08:02:12PM +0300, Alexander Monakov wrote:
> On Thu, 6 Jul 2017, Rich Felker wrote:
> > FWIW, I think GCC may do aggressive optimization based on the
> > assumption that memcpy implies the pointer points to an object (of
> > size at least 1)
> 
> The compiler can deduce that the pointer is non-null (and that's
> fine), but otherwise I don't see what possible optimizations could
> take place. Did you have something specific in mind?

It could presumably move loads from after a branch to before. E.g.

	memcpy(q,p,0);
	if (whatever) {
		y=*p;
		...
	}
	/* y not used after here */

to:

	memcpy(q,p,0);
	y=*p;
	if (whatever) {
		...
	}
	/* y not used after here */

If p points to one past the end of an object that ends on a page
boundary, this transformation could introduce a crash.

Rich


  reply	other threads:[~2017-07-06 17:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-06 14:15 Pascal Cuoq
2017-07-06 15:52 ` Alexander Monakov
2017-07-06 16:23 ` Rich Felker
2017-07-06 17:02   ` Alexander Monakov
2017-07-06 17:11     ` Rich Felker [this message]
2017-07-06 17:17       ` Alexander Monakov
2017-07-06 17:22         ` Rich Felker
2017-07-06 17:38           ` Alexander Monakov
2017-07-06 18:13             ` Rich Felker
2017-07-06 18:52               ` Jens Gustedt
2017-07-06 19:23                 ` Szabolcs Nagy
2017-07-06 23:52                   ` Jens Gustedt
2017-07-06 19:05   ` Bartosz Brachaczek
2017-07-06 19:10     ` Leah Neukirchen
2017-07-06 19:28       ` Szabolcs Nagy
2017-07-06 16:29 ` Szabolcs Nagy

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=20170706171101.GD1627@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).