unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: [Emacs-diffs] master 6cd5678: Clarify compiler-pacifier in frame.c
Date: Tue, 27 Aug 2019 05:05:33 -0700	[thread overview]
Message-ID: <632b7c28-63d2-d400-bfff-096258d76d9a@cs.ucla.edu> (raw)
In-Reply-To: <83ftlmewy7.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 2142 bytes --]

Eli Zaretskii wrote:

> Do you have a guess why GCC might get lost in that code?

Sure, lots of guesses. GCC may have a limit on how many variables it's willing 
to analyze before it gives up. Or maybe it has a limit on the complexity of the 
mask being used. Or maybe it's just using range and oddity analyses and that 
works only up to two-bit masks. (I should say that GCC is "lost" only in the 
sense that it's issuing bogus warnings; it's still generating correct code.)

To illustrate, please see the attached file maybe-uninitialized.c. When I 
compile it with 'gcc -O2 -Wmaybe-uninitialized -S maybe-uninitialized.c' on 
Fedora 30 x86-64, GCC warns that w, x, and y might be used uninitialized in 
bar4. It doesn't warn about h in bar4 even though h is initialized using the 
same strategy as the others. GCC also doesn't warn about bar2's locals even 
though bar 2 uses the same strategy as bar4. All the warnings GCC issues are 
false alarms, and these false alarms come from bar4 (with 4 variables) rather 
than from bar2 (with only 2).

>>> And how should GCC know that?
>>
>> GCC could use the same sort of reasoning I used.
> 
> Which reasoning is that?  You haven't presented your reasoning for
> XParseGeometry, AFAICT.  You presented reasoning for some other code,
> which you consider similar.

I presented the reasoning GCC's bogus warning about XParseGeometry's caller in 
this earlier email:

https://lists.gnu.org/r/emacs-devel/2019-08/msg00531.html

If that presentation wasn't clear enough I can go into it in more detail; just 
let me know which parts weren't clear. Perhaps maybe-uninitialized.c will help 
explain things too.

> UNINIT is for you to be able to use your tools of choice, and
> perhaps also to cater to your personal stylistic preferences.

It's not just me using those tools. And UNINIT is not my stylistic preference: I 
don't like using UNINIT and when variables need not be initialized I'd rather 
just not initialize them (this is the longstanding tradition in GNU and UNIX 
code). The only reason for UNINIT is that it's more useful for preventing and 
catching bugs than its alternatives are.

[-- Attachment #2: maybe-uninitialized.c --]
[-- Type: text/x-csrc, Size: 932 bytes --]

extern int v;
extern int bar2 (void);
extern int bar4 (void);

int v;

static int
foo2 (int *x, int *y)
{
  int mask = 0;
  if (v & 1)
    {
      mask = 1;
      *x = v;
    }
  if (v & 2)
    {
      mask |= 2;
      *y = v;
    }
  return mask;
}

int
bar2 (void)
{
  int sum = 0;
  int x, y;
  int mask = foo2 (&x, &y);
  if (mask & 1)
    sum += x;
  if (mask & 2)
    sum += y;
  return sum;
}

static int
foo4 (int *x, int *y, int *w, int *h)
{
  int mask = 0;
  if (v & 1)
    {
      mask = 1;
      *x = v;
    }
  if (v & 2)
    {
      mask |= 2;
      *y = v;
    }
  if (v & 4)
    {
      mask |= 4;
      *w = v;
    }
  if (v & 8)
    {
      mask |= 8;
      *h = v;
    }
  return mask;
}

int
bar4 (void)
{
  int sum = 0;
  int x, y, w, h;
  int mask = foo4 (&x, &y, &w, &h);
  if (mask & 1)
    sum += x;
  if (mask & 2)
    sum += y;
  if (mask & 4)
    sum += w;
  if (mask & 8)
    sum += h;
  return sum;
}

  reply	other threads:[~2019-08-27 12:05 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-24  6:14 [Emacs-diffs] master 6cd5678: Clarify compiler-pacifier in frame.c Eli Zaretskii
2019-08-25  0:52 ` Paul Eggert
2019-08-25  7:13   ` Eli Zaretskii
2019-08-26  6:34     ` Paul Eggert
2019-08-26  7:54       ` Eli Zaretskii
2019-08-26  8:15         ` Paul Eggert
2019-08-26  9:47           ` Eli Zaretskii
2019-08-26 15:21             ` Óscar Fuentes
2019-08-26 16:13               ` Eli Zaretskii
2019-08-26 18:20                 ` Óscar Fuentes
2019-08-26 18:39                   ` Eli Zaretskii
2019-08-26 19:09                     ` Paul Eggert
2019-08-26 19:15                     ` Óscar Fuentes
2019-08-26 19:33                       ` Eli Zaretskii
2019-08-26 19:49                         ` Óscar Fuentes
2019-08-26 22:33                         ` Paul Eggert
2019-08-27  6:12                           ` Eli Zaretskii
2019-08-27  7:28                             ` Paul Eggert
2019-08-27  8:02                               ` Eli Zaretskii
2019-08-27  9:28                                 ` Paul Eggert
2019-08-27 10:15                                   ` Eli Zaretskii
2019-08-27 12:05                                     ` Paul Eggert [this message]
2019-08-27 12:43                                       ` Eli Zaretskii
2019-08-26 18:50             ` Paul Eggert
2019-08-26 18:56               ` Eli Zaretskii
2019-08-26 23:17             ` Richard Stallman

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://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=632b7c28-63d2-d400-bfff-096258d76d9a@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).