zsh-workers
 help / color / mirror / code / Atom feed
From: Vincent Lefevre <vincent@vinc17.net>
To: zsh-workers@zsh.org
Subject: Re: [PATCH 2/2] Fix two C nits
Date: Tue, 19 Jun 2018 16:38:34 +0200	[thread overview]
Message-ID: <20180619143834.GA17383@zira.vinc17.org> (raw)
In-Reply-To: <20180619141321eucas1p194af5292bb4f5030e0536c500ef9c6c5~5lTSLcvNm0521405214eucas1p1I@eucas1p1.samsung.com>

On 2018-06-19 15:13:19 +0100, Peter Stephenson wrote:
> On Tue, 19 Jun 2018 15:46:29 +0200
> Vincent Lefevre <vincent@vinc17.net> wrote:
> > On 2018-06-18 10:22:41 +0100, Peter Stephenson wrote:
> > > On Sat, 16 Jun 2018 01:04:27 +0000
> > > Eitan Adler <lists@eitanadler.com> wrote:  
> > > > - avoid returning from a function that will never return
> > > >
> > > > diff --git a/Src/exec.c b/Src/exec.c
> > > > index d44527841..b36bcef64 100644
> > > > --- a/Src/exec.c
> > > > +++ b/Src/exec.c
> > > > @@ -4954,7 +4954,6 @@ getpipe(char *cmd, int nullexec)
> > > >      execode(prog, 0, 1, out ? "outsubst" : "insubst");
> > > >      cmdpop();
> > > >      _exit(lastval);
> > > > -    return 0;
> > > >  }  
> >
> > The _exit function is non-standard.
> 
> That means from the basic C point of view it's not safe simply to remove
> the return.  We are not in the game of guessing what the compiler knows.

It's safe because whether the "return 0;" line is here or not, this
will not change the behavior since this line is not reachable (even
if the compiler doesn't know this).

If the compiler doesn't know that _exit never returns, it will
typically add an instruction corresponding to the "return 0;",
but this instruction will never be executed. If the "return 0;"
is removed, then the compiler will not add such an instruction,
but may add a "jump" (which, again, will never be executed) and
this may also prevent some optimizations in the code that follows
(because the compiler would think that code that follows may also
be reached from this "if" block).

In short, the presence or not of the "return 0;" may have an effect
on the generated code (good or bad, this is potentially unknown),
but the behavior will remain the same.

> Anything we *can* detect about the compiler / configuration is
> fair game for improvement, however...

FYI, _exit is a builtin in GCC (according to the manual), so that
GCC necessarily knows and the presence or not of "return 0;" should
be equivalent.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


  reply	other threads:[~2018-06-19 14:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20180616021439epcas4p327f4346b40d9e10d94ce055058fe0d71@epcas4p3.samsung.com>
2018-06-16  1:04 ` Eitan Adler
2018-06-18  9:22   ` Peter Stephenson
2018-06-19  5:31     ` Eitan Adler
2018-06-19 13:46     ` Vincent Lefevre
2018-06-19 14:13       ` Peter Stephenson
2018-06-19 14:38         ` Vincent Lefevre [this message]
2018-06-19 15:59           ` Peter Stephenson

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=20180619143834.GA17383@zira.vinc17.org \
    --to=vincent@vinc17.net \
    --cc=zsh-workers@zsh.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).