bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org, Paul Eggert <eggert@cs.ucla.edu>
Subject: Re: [PATCH 1/4] localename: -Wtautological-pointer-compare
Date: Sun, 15 Jan 2023 23:03:09 +0100	[thread overview]
Message-ID: <2228043.iJkMF17ckq@nimes> (raw)
In-Reply-To: <ca725b9f-b97d-815d-5c1d-a6851a0021b1@cs.ucla.edu>

Hi Paul,

> My confusion arose partly because I am accustomed to languages where the 
> distinction between null and non-null pointers is checked statically and 
> reliably, and I keep forgetting that with C, GCC and Clang are only poor 
> approximations to that

Oh, now I understand. May I guess the language: Haskell, OCaml, TypeScript,
Rust?

> - though I hope the approximations are slowly getting better.

Still it will take a lot of time. The following steps need to happen:
  1. Standards need to define a notation for declaring a non-null type value,
     non-null argument, or non-null return value. (Partially done.)
  2. Compilers need to diagnose places where a non-null declaration could be
     added, like they do for function attributes __pure__ and __const__.
  3. Developers need to add such declarations to their .h files.
Then only such static checking can happen, without producing floods of
diagnostics that developers would discard.

> Also, in my experience the debugger doesn't always point to the exact 
> line of the abort(). For example, if there are two abort() calls in the 
> same function they are routinely coalesced.

True :( I should have mentioned to compile with "-g -O0", not just "-g".

> To give a different example: I wouldn't bother with the following code 
> (where M and N are int arguments to a function):
> 
>      if (n == 0)
>        abort ();
>      if (n == -1 && m < -INT_MAX)
>        abort ();
>      return m / n;
> 
> and would instead write this:
> 
>      return m / n;
> 
> as the user and debugging experiences are similar and the shorter form 
> simplifies code maintenance.

Unfortunately, this is an excellent example for a portability problem:
The division yields a SIGFPE on x86, x86_64, alpha, m68k, and s390/s390x
CPU, but not on other architectures.

> Sure, the longer form is safer for oddball 
> platforms, but it's not worth the aggravation.

Some distros feel differently. I have such code in GNU gettext, and
optimize away the entry checks on platforms where I know it yields a SIGFPE.
And some distros disabled these optimizations, i.e. enabled the entry checks
always...

Bruno





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

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-13 20:17 [PATCH 1/4] localename: -Wtautological-pointer-compare Paul Eggert
2023-01-13 20:17 ` [PATCH 2/4] Don’t use alloc_size with xlclang 16.1 Paul Eggert
2023-01-13 20:17 ` [PATCH 3/4] assert-h: fix configure comment-out Paul Eggert
2023-01-13 20:17 ` [PATCH 4/4] assert-h: suppress xlclang 16.1 false alarms Paul Eggert
2023-01-13 22:59 ` [PATCH 1/4] localename: -Wtautological-pointer-compare Bruno Haible
2023-01-13 23:36   ` Paul Eggert
2023-01-14 11:00     ` Bruno Haible
2023-01-15  3:02       ` Paul Eggert
2023-01-15 22:03         ` Bruno Haible [this message]
2023-01-16  0:15           ` Paul Eggert

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

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2228043.iJkMF17ckq@nimes \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=eggert@cs.ucla.edu \
    /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).