Subject: bug#75451: scratch/igc: Enable CHECK_STRUCTS

From: Pip Cet <[email-masked]>
Date: Mon, 20 Jan 2025 09:00:12 +0000

Gerd Möllmann <[email-masked]> writes:

> Pip Cet <[email-masked]> writes:
>
>>> Thanks, that's helpful.  Based on the above, I came up with the attached
>>> patch for pdumper.c.
>>
>> Let's introduce macros for the different cases, and use the same macro
>> in the same case, until GCC offers a fix.
>
> Pretty please not more macros.

Why not?  We need to distinguish "default case reached for some enum
values" and "default case reached only for non-enum values, warn if it's
reached for enum values".

I'm still not sure what the best way of expressing those two different
semantics of default labels is, and I don't think we should put the
"switch" or "default" in a macro, but it would involve some macros
because it relies on compiler features not always available (and #pragma
is horrible and shouldn't be used).

Think something like

enum ABC abc = whatever;

switch (abc)
  {
    case A:
    case B:
      handle();
      break;
    default:
      prove_or_warn (!in_enum (abc, enum ABC));
  }

in_enum would verify that a value is one of the enumerated values rather
than an invalid one.  prove_or_warn would produce a compiler warning if
its argument isn't __builtin_constant_p and true.  (The usual way to
make GCC do that is to call an undefined extern symbol if the argument
is false; if it's provably true, GCC won't try to link against the
symbol).

The problem is that it wouldn't work with "-O0", which makes
__builtin_constant_p useless.

But that's a minor change we need to make anyway: right now, "make"
builds Emacs just once and we look at the compiler warnings from that
run.  With the static analyzer and things like that, we need a separate
make target for extra compiler warnings.  (We should run this by
default, of course).

(That would also solve the texinfo/@xref problem: texinfo apparently
cannot generate the warning, so let's make that new target check for
invalid @xrefs using some simple Elisp).

Pip