public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexander Monakov <amonakov@ispras.ru>
To: Richard Biener <richard.guenther@gmail.com>
Cc: exactlywb@ispras.ru, gcc-patches@gcc.gnu.org
Subject: Re: [RFC PATCH] Detecting lifetime-dse issues via Valgrind
Date: Tue, 21 Nov 2023 10:52:18 +0300 (MSK)	[thread overview]
Message-ID: <53557793-8cc8-1240-2848-09b4895e96c9@ispras.ru> (raw)
In-Reply-To: <207796F2-6AA2-4976-B0FD-50A08B8A56E4@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1273 bytes --]


On Mon, 13 Nov 2023, Richard Biener wrote:

> > Ideally we'd position it such that more locals are put in SSA form,
> > but not too late to miss some UB, right? Perhaps after first pass_ccp?
> 
> I guess it’s worth experimenting.  Even doing it right before RTL expansion
> might work.  Note if you pick ccp you have to use a separate place for -O0

While Daniil is experimenting with this, I want to raise my concern about
attempting this instrumentation too late. Consider the main thing we are
trying to catch:

	// inlined operator new:
	this->foo = 42;
	// inlined constructor:
	*this = { CLOBBER };
	// caller:
	int tmp = this->foo;
	return tmp;

Our instrumentation adds

	__valgrind_make_mem_undefined(this, sizeof *this);

immediately after the clobber.

I am concerned that if GCC ever learns to leave out the following access
to 'this->foo', leaving tmp uninitialized, we will end up with:

	this->foo = 42;
	*this = { CLOBBER };
	__valgrind_make_mem_undefined(this, sizeof *this);
	int tmp(D);
	return tmp(D); // uninitialized

and Valgrind will not report anything since the invalid load is optimized out.

With early instrumentation such optimization is not going to happen, since the
builtin may modify *this.

Is my concern reasonable?

Thanks.
Alexander

  reply	other threads:[~2023-11-21  7:52 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-24 14:11 exactlywb
2023-11-11 22:25 ` [RFC PATCH] Detecting lifetime-dse issues via Valgrind [PR66487] Sam James
2023-11-12  9:00   ` Alexander Monakov
2023-11-12  9:05     ` Sam James
2023-11-12 22:53       ` Sam James
2023-11-15  9:58         ` Daniil Frolov
2023-11-11 22:26 ` [RFC PATCH] Detecting lifetime-dse issues via Valgrind Arsen Arsenović
2023-11-12  8:07   ` Alexander Monakov
2023-11-13 12:00 ` Richard Biener
2023-11-13 14:29   ` Alexander Monakov
2023-11-13 16:25     ` Richard Biener
2023-11-21  7:52       ` Alexander Monakov [this message]
2023-11-21  7:59         ` Alexander Monakov
2023-11-21  8:02           ` Richard Biener
2023-11-21  8:56             ` Alexander Monakov
2023-11-21  9:40               ` Richard Biener
2023-11-21 21:42 ` Hans-Peter Nilsson

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=53557793-8cc8-1240-2848-09b4895e96c9@ispras.ru \
    --to=amonakov@ispras.ru \
    --cc=exactlywb@ispras.ru \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).