public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "amonakov at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug sanitizer/110799] [tsan] False positive due to -fhoist-adjacent-loads
Date: Wed, 26 Jul 2023 06:55:03 +0000 [thread overview]
Message-ID: <bug-110799-4-JUhPELjaFU@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110799-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110799
--- Comment #9 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #7)
> Can you elaborate on what you consider a correct approach?
I think this optimization is incorrect and should be active only under -Ofast.
I can offer two arguments. First, even without considering correctness,
breaking TSan and Helgrind is a substantial QoI issue and we should consider
shielding -O2 users from that (otherwise they'll discover it the hard way,
curse at us, stick -fno-hoist-adjacent-loads in their build system and consider
switching to another compiler).
Second, I can upgrade the initial example to an actual miscompilation. The
upgrade is based on two considerations: the optimization works on
possibly-trapping accesses, and relies on types of memory references to decide
if it's safe, but it runs late where the types are not what they were in the C
source. Hence, the following example:
struct S {
int a;
};
struct M {
int a, b;
};
int f(struct S *p, int c, int d)
{
int r;
if (c)
if (d)
r = p->a;
else
r = ((struct M*)p)->a;
else
r = ((struct M*)p)->b;
return r;
}
is miscompiled to
f:
mov eax, DWORD PTR [rdi+4]
test esi, esi
cmovne eax, DWORD PTR [rdi]
ret
even though the original program never accesses beyond struct S if 'c && d'.
Phi-opt incorrectly performs hoisting after PRE collapses 'if (d) ... else
...'.
next prev parent reply other threads:[~2023-07-26 6:55 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-25 7:03 [Bug sanitizer/110799] New: " vries at gcc dot gnu.org
2023-07-25 10:02 ` [Bug sanitizer/110799] " rguenth at gcc dot gnu.org
2023-07-25 10:08 ` vries at gcc dot gnu.org
2023-07-25 10:19 ` jakub at gcc dot gnu.org
2023-07-25 13:42 ` rguenther at suse dot de
2023-07-25 14:09 ` amonakov at gcc dot gnu.org
2023-07-25 21:48 ` vries at gcc dot gnu.org
2023-07-25 21:59 ` vries at gcc dot gnu.org
2023-07-26 6:37 ` rguenther at suse dot de
2023-07-26 6:55 ` amonakov at gcc dot gnu.org [this message]
2023-07-26 6:56 ` rguenther at suse dot de
2023-07-26 7:05 ` rguenther at suse dot de
2023-07-26 7:18 ` jakub at gcc dot gnu.org
2023-07-26 9:42 ` cvs-commit at gcc dot gnu.org
2023-07-26 10:07 ` rguenth at gcc dot gnu.org
2023-07-27 10:34 ` cvs-commit at gcc dot gnu.org
2023-07-31 8:15 ` amonakov at gcc dot gnu.org
2023-07-31 8:29 ` rguenth at gcc dot gnu.org
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=bug-110799-4-JUhPELjaFU@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.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 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).