Re: gcc -Wimplicit-fallthrough and pg_unreachable

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Chapman Flack <chap(at)anastigmatix(dot)net>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: gcc -Wimplicit-fallthrough and pg_unreachable
Date: 2020-11-28 16:48:17
Message-ID: 784601.1606582097@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Chapman Flack <chap(at)anastigmatix(dot)net> writes:
> I noticed in CI builds of PL/Java with PG 13 that -Wimplicit-fallthrough=3
> in pg_config's CFLAGS was causing some switch case fallthrough warnings
> after an elog(ERROR. [1]

Yeah, I can replicate this here (gcc 8.3.1 on RHEL8). My recollection
is that we saw this when trialling -Wimplicit-fallthrough, and determined
that the hack used to teach the compiler that elog(ERROR) doesn't return
fails to prevent -Wimplicit-fallthrough warnings even though it does work
for other purposes. Using this test case:

int
foo(int p)
{
int x;

switch (p)
{
case 0:
x = 1;
break;
case 1:
elog(ERROR, "bogus");
break;
case 2:
x = 2;
break;
default:
x = 3;
}

return x;
}

I do not get a warning about x being possibly uninitialized (so it
knows elog(ERROR) doesn't return?), but without the "break" after
elog() I do get a fallthrough warning (so it doesn't know that?).

Seems like a minor gcc bug; no idea if anyone's complained to them.
I think we've found other weak spots in -Wimplicit-fallthrough's
coverage though, so it's not one of gcc's best areas.

As illustrated here, I'd just add a "break" rather than
"pg_unreachable()", but that's a matter of taste.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrey Lepikhov 2020-11-28 17:21:17 Re: Removing unneeded self joins
Previous Message Chapman Flack 2020-11-28 16:10:59 gcc -Wimplicit-fallthrough and pg_unreachable