public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
To: gcc-patches@gcc.gnu.org
Cc: rep.dot.nop@gmail.com, ian@airs.com, charlet@adacore.com
Subject: Re: [PATCH][stage1] Remove conditionals around free()
Date: Wed, 1 Mar 2023 23:54:58 +0100	[thread overview]
Message-ID: <20230301235458.57ea642f@nbbrfq> (raw)
In-Reply-To: <20230301225859.37ce4646@nbbrfq>

On Wed, 1 Mar 2023 22:58:59 +0100
Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote:

> On Wed, 1 Mar 2023 22:28:56 +0100
> Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote:
> 
> > Remarks:
> > 1) We should do this in if-conversion (?) on our own.
> >    I suppose. Independently of -fdelete-null-pointer-checks  
> 
> and iff we can prove that ptr was NULL when passed to free(ptr) then we
> can elide the call, of course. Likewise for realloc(ptr, 0), obviously.
> [or reallocarray -- yikes -- if nmemb == 0 || size == 0]
> 
> But that would probably be a ranger call in DCE, i guess. Didn't look.
> thanks,

And, if under C, we rule out validity of a life ptr as a return value of
malloc(0),
---8<---
 If size is 0, either:

A null pointer shall be returned [CX] [Option Start]  and errno may be set to an implementation-defined value, [Option End] or

A pointer to the allocated space shall be returned. The application shall ensure that the pointer is not used to access an object.
---8<---
Where CX == "Extension to the ISO C standard" 
https://pubs.opengroup.org/onlinepubs/9699919799/help/codes.html#CX

then one might be baffled that malloc(0) still is underspecified or
at least unpleasantly specified WRT realloc(NULL,0) after all these
years in the wild.

The exact quote from CX is
---8<---
[CX] [Option Start] Extension to the ISO C standard [Option End]
The functionality described is an extension to the ISO C standard. Application developers may make use of an extension as it is supported on all POSIX.1-2017-conforming systems.

With each function or header from the ISO C standard, a statement to the effect that "any conflict is unintentional" is included. That is intended to refer to a direct conflict. POSIX.1-2017 acts in part as a profile of the ISO C standard, and it may choose to further constrain behaviors allowed to vary by the ISO C standard. Such limitations and other compatible differences are not considered conflicts, even if a CX mark is missing. The markings are for information only.

Where additional semantics apply to a function or header, the material is identified by use of the CX margin legend.

---8<---
So, what in the end this all gives is IMHO that natural stuff like valid
C or C++ can only borderline elide any of these calls which hinders
everyone and helps nobody for real IMHO. Doesn't it.

That's how conceptually devirt does it's thing for just a very
particular flavour of the family and rightfully leaves the rest alone,
which really is a pity IMHO.

But that's enough as far as an unfounded rant goes for today and should
probably be addressed elsewhere either way.

So, please remind me, why, again, does C do it's life ptr thing, short
of an optimisation barrier?

thanks,

  reply	other threads:[~2023-03-01 22:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-01 21:28 Bernhard Reutner-Fischer
2023-03-01 21:58 ` Bernhard Reutner-Fischer
2023-03-01 22:54   ` Bernhard Reutner-Fischer [this message]
2023-03-01 22:59 ` Andrew Pinski
2023-03-01 23:52   ` Bernhard Reutner-Fischer
2023-03-02  0:39     ` Andrew Pinski
2023-03-02  0:07 ` Steve Kargl
2023-03-02  1:23   ` Jerry D
2023-03-03 23:11     ` Bernhard Reutner-Fischer
2023-03-03 23:32       ` Iain Sandoe
2023-03-04  3:14         ` Jerry D
2023-03-24  6:30           ` NightStrike
2023-05-08  6:01   ` Bernhard Reutner-Fischer
2023-03-02  3:23 ` Ian Lance Taylor
2023-03-04 10:15 ` Janne Blomqvist
2023-03-22  7:21   ` Eric Gallager
2023-03-08 21:56 ` Thomas Schwinge

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=20230301235458.57ea642f@nbbrfq \
    --to=rep.dot.nop@gmail.com \
    --cc=charlet@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ian@airs.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).