public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/101480] [11/12 Regression] Miscompiled code involving operator new
Date: Mon, 11 Oct 2021 14:05:55 +0000 [thread overview]
Message-ID: <bug-101480-4-2BlOTtcKX4@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-101480-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101480
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |amacleod at redhat dot com
--- Comment #18 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #16)
> (In reply to Richard Biener from comment #14)
> ...
> > the testcase does
> >
> > m = i;
> > p = (int*) new unsigned char [sizeof (int) * m];
> >
> > for (int i = 0; i < m; i++)
> > new (p + i) int ();
> >
> > and we likely have to assume that 'new' changes 'm'.
>
> Why? Because of the flow-insensitivity of the alias analysis?
>
> m is a member of the class whose ctor has the loop above. Neither the
> enclosing object nor the member actually escapes (the operator new to which
> p is passed in the loop is the nonreplaceable placement new), so there is no
> way it can be changed.
What we see is the global variable construction function which accesses
just 'a', and yes, the call to 'new' is considered clobbering global
variables (including 'a'):
<bb 2> [local count: 1073741824]:
MEM[(struct __as_base &)&a] ={v} {CLOBBER};
a.m = 0;
_5 = operator new [] (0);
a.p = _5;
goto <bb 4>; [100.00%]
<bb 3> [local count: 8687547547]:
_7 = (long unsigned int) i_6;
_8 = _7 * 4;
_9 = _5 + _8;
MEM[(int *)_9] = 0;
i_10 = i_6 + 1;
<bb 4> [local count: 9761289362]:
# i_6 = PHI <0(2), i_10(3)>
_11 = a.m;
if (i_6 < _11)
goto <bb 3>; [89.00%]
else
goto <bb 5>; [11.00%]
<bb 5> [local count: 1073741824]:
return;
I suppose implementing the global operator new as accessing a.m would
be valid as IIRC lifetime of a starts when the CTOR is invoked, not
when it finished (otherwise the CTOR could not access the variable itself).
We somehow conclude that
_9: void * [1B, +INF] EQUIVALENCES: { } (0 elements)
possibly because it cannot be NULL (?):
extract_range_from_stmt visiting:
_5 = operator new [] (0);
Found new range for _5: void * [1B, +INF]
marking stmt to be not simulated again
(huh?)
and then the -Warray-bounds warning concludes the access is always outside
of the allocated area.
I suspect when we'd arrive at VARYING we'd not issue the warning even
when the access would always extend beyond a zero-sized allocation.
I'm going to ignore this diagnostic issue, it concerns the 'offrange'
code I'm not familiar with at all (and maybe the value-range code for
which I now have to say sth similar).
next prev parent reply other threads:[~2021-10-11 14:05 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-16 22:53 [Bug c++/101480] New: " jens.maurer at gmx dot net
2021-07-18 21:11 ` [Bug c++/101480] [11/12 Regression] " redi at gcc dot gnu.org
2021-07-18 21:11 ` redi at gcc dot gnu.org
2021-07-19 6:27 ` rguenth at gcc dot gnu.org
2021-07-19 7:26 ` jens.maurer at gmx dot net
2021-07-19 8:28 ` jakub at gcc dot gnu.org
2021-07-19 9:28 ` volker.schmidt at factset dot com
2021-07-19 10:21 ` rguenth at gcc dot gnu.org
2021-07-19 11:41 ` rguenth at gcc dot gnu.org
2021-07-19 12:43 ` redi at gcc dot gnu.org
2021-07-19 12:47 ` redi at gcc dot gnu.org
2021-07-19 12:55 ` jens.maurer at gmx dot net
2021-07-19 13:16 ` rguenther at suse dot de
2021-07-19 13:39 ` rguenth at gcc dot gnu.org
2021-07-19 13:46 ` rguenth at gcc dot gnu.org
2021-07-19 14:36 ` rguenth at gcc dot gnu.org
2021-07-28 7:07 ` rguenth at gcc dot gnu.org
2021-07-28 17:16 ` msebor at gcc dot gnu.org
2021-10-08 11:29 ` rguenth at gcc dot gnu.org
2021-10-11 14:05 ` rguenth at gcc dot gnu.org [this message]
2021-10-11 14:20 ` cvs-commit at gcc dot gnu.org
2021-10-11 14:21 ` [Bug c++/101480] [11 " rguenth at gcc dot gnu.org
2021-10-11 15:03 ` hubicka at kam dot mff.cuni.cz
2021-10-12 6:10 ` rguenth at gcc dot gnu.org
2021-10-12 12:55 ` redi at gcc dot gnu.org
2021-10-12 13:22 ` rguenth at gcc dot gnu.org
2021-11-08 12:35 ` cvs-commit at gcc dot gnu.org
2021-11-08 12:37 ` 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-101480-4-2BlOTtcKX4@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).