public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "peter at int19h dot net" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/97976] Optimization relating to NULL pointer assumptions in gcc 9.1
Date: Wed, 25 Nov 2020 19:46:07 +0000	[thread overview]
Message-ID: <bug-97976-4-Awf9kFqK4W@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-97976-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97976

--- Comment #7 from Peter Bisroev <peter at int19h dot net> ---
Thank you for your response Jonathan.

If you have a minute, could you please clarify a few things. I have been
talking about this behavior with a few colleagues and we are all slightly
confused by the same issue. So I think the answers here can definitely help a
few people besides myself.

>It is undefined to decrement a pointer "before" the start of an object

I am sorry, but I am not sure where I am doing this? For example, lets say I am
accessing raw memory on an embedded system and I have bytes 0, 1, 1, 1 at
addresses 0, 1, 2 and 3 respectively. I know this is a trivial example and
makes no sense on x86 arch (almost, in real mode maybe). So if I call
containsBackwardsSafe(p, 2) with p == 3, shouldn't I get back -1? I guess it
all depends on what is the "object" in this context. Conceivably some other
function could have mapped that memory at that address on that system and
passed the pointer to containsBackwardsSafe() function. In that case wouldn't
the responsibility of "object" be up to the system and not the compiler?

I have also just tried going through C11 draft
(http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf) to try to find
relevant standard sections that would describe this behavior. I have read
through sections:
* 6.2.5 Types (specifically paragraphs 14 and 20)
* 6.3.2.3 Pointers
* 6.5.3.1 Prefix increment and decrement operators
* 6.5.6 Additive operators (specifically paragraphs 7, 8 and 9)
* 6.5.16.2 Compound assignment

And I cannot seem to find relevant information that forbids pointer decrement
as  shown in containsBackwardsSafe() or containsBackwards() from the last
comment. If you could point me to the right section of the standard it would be
incredibly helpful. I am sure I must be missing something obvious.

Once again, thank you for your time and help on this.

Regards,
--peter

  parent reply	other threads:[~2020-11-25 19:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-24 22:08 [Bug c++/97976] New: Optimization regression in 10.1 for lambda passed as template argument peter at int19h dot net
2020-11-24 22:14 ` [Bug c++/97976] " pinskia at gcc dot gnu.org
2020-11-24 22:24 ` peter at int19h dot net
2020-11-25  4:40 ` peter at int19h dot net
2020-11-25  8:25 ` [Bug c++/97976] Optimization relating to NULL pointer assumptions in gcc 9.1 rguenth at gcc dot gnu.org
2020-11-25 16:43 ` peter at int19h dot net
2020-11-25 18:18 ` redi at gcc dot gnu.org
2020-11-25 19:46 ` peter at int19h dot net [this message]
2020-11-25 23:55 ` redi at gcc dot gnu.org
2020-11-26  0:20 ` redi at gcc dot gnu.org
2020-11-26  1:37 ` peter at int19h dot net
2020-11-26 10:08 ` redi at gcc dot gnu.org
2020-11-26 10:09 ` redi 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-97976-4-Awf9kFqK4W@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).