Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Feb 2020 20:01:31 +0100
From:      Dimitry Andric <dimitry@andric.com>
To:        Mateusz Guzik <mjguzik@gmail.com>
Cc:        Kyle Evans <kevans@freebsd.org>, Ian Lepore <ian@freebsd.org>, svn-src-head <svn-src-head@freebsd.org>, svn-src-all <svn-src-all@freebsd.org>, src-committers <src-committers@freebsd.org>
Subject:   Re: svn commit: r358248 - head/sys/vm
Message-ID:  <6D39FAD8-E581-42A8-97B4-EE63800D78A4@andric.com>
In-Reply-To: <CAGudoHHg5R0zOc7RYge36roz%2B3C_sSRZcsyXC55W0yAyQpuuBA@mail.gmail.com>
References:  <202002221620.01MGK46E072303@repo.freebsd.org> <a3b2125de10d214d6e422d183f1fdc7e0e38e014.camel@freebsd.org> <CACNAnaHZnrqRv9J-B7XRCc7eN7Hkccf1R-7e36LiAXvZR4etVw@mail.gmail.com> <CAGudoHHg5R0zOc7RYge36roz%2B3C_sSRZcsyXC55W0yAyQpuuBA@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--Apple-Mail=_4EE71C4E-25DB-4EEE-BBA3-0EE610EB99DD
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii

On 22 Feb 2020, at 17:44, Mateusz Guzik <mjguzik@gmail.com> wrote:
>=20
> On 2/22/20, Kyle Evans <kevans@freebsd.org> wrote:
>> On Sat, Feb 22, 2020 at 10:25 AM Ian Lepore <ian@freebsd.org> wrote:
>>>=20
>>> On Sat, 2020-02-22 at 16:20 +0000, Kyle Evans wrote:
>>>> Author: kevans
>>>> Date: Sat Feb 22 16:20:04 2020
>>>> New Revision: 358248
>>>> URL: https://svnweb.freebsd.org/changeset/base/358248
>>>>=20
>>>> Log:
>>>>  vm_radix: prefer __builtin_unreachable() to an unreachable panic()
>>>>=20
>>>>  This provides the needed hint to GCC and offers an annotation for
>>>> readers to
>>>>  observe that it's in-fact impossible to hit this point. We'll get =
hit
>>>> with a
>>>>  a -Wswitch error if the enum applicable to the switch above were =
to
>>>> get
>>>>  expanded without the new value(s) being handled.
>>>>=20
>>>> Modified:
>>>>  head/sys/vm/vm_radix.c
>>>>=20
>>>> Modified: head/sys/vm/vm_radix.c
>>>> =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
>>>> --- head/sys/vm/vm_radix.c    Sat Feb 22 13:23:27 2020        =
(r358247)
>>>> +++ head/sys/vm/vm_radix.c    Sat Feb 22 16:20:04 2020        =
(r358248)
>>>> @@ -208,8 +208,7 @@ vm_radix_node_load(smrnode_t *p, enum
>>>> vm_radix_access
>>>>      case SMR:
>>>>              return (smr_entered_load(p, vm_radix_smr));
>>>>      }
>>>> -     /* This is unreachable, silence gcc. */
>>>> -     panic("vm_radix_node_get: Unknown access type");
>>>> +     __unreachable();
>>>> }
>>>>=20
>>>> static __inline void
>>>=20
>>> What does __unreachable() do if the code ever becomes reachable?  =
Like
>>> if a new enum value is added and this switch doesn't get updated?
>>>=20
>>=20
>> __unreachable doesn't help here, but the compiler will error out on
>> the switch() if all enum values aren't addressed and there's no
>> default: case.
>>=20
>> IMO, compilers could/should become smart enough to error if there's =
an
>> explicit __builtin_unreachable() and they can trivially determine =
that
>> all paths will terminate before this, independent of -Werror=3Dswitch*.=

>> _______________________________________________
>=20
> I think this is way too iffy, check this program:
>=20
>=20
> #include <stdio.h>
>=20
> int
> main(void)
> {
>=20
> 	__builtin_unreachable();
> 	printf("test\n");
> }
>=20
> Neither clang nor gcc warn about this and both stop code generation
> past the statement.

Indeed, that is exactly the intent.  See:

=
https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_005f_005fbui=
ltin_005funreachable

"If control flow reaches the point of the __builtin_unreachable, the
program is undefined. It is useful in situations where the compiler
cannot deduce the unreachability of the code."

E.g. this is *not* meant as a way to enforce the program to abort at
runtime, if the supposedly unreachable part is actually reached.

For this purpose, one should use an abort() or panic() function call,
with such functions being annotated to never return.

-Dimitry


--Apple-Mail=_4EE71C4E-25DB-4EEE-BBA3-0EE610EB99DD
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename=signature.asc
Content-Type: application/pgp-signature;
	name=signature.asc
Content-Description: Message signed with OpenPGP

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.2

iF0EARECAB0WIQR6tGLSzjX8bUI5T82wXqMKLiCWowUCXlF6iwAKCRCwXqMKLiCW
o+LFAKDkDeedeFuXnYA+mz0c6EBY9BQHiACgz5xy6bzXcWSFVoj8uqYyquFHfkk=
=tmbs
-----END PGP SIGNATURE-----

--Apple-Mail=_4EE71C4E-25DB-4EEE-BBA3-0EE610EB99DD--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6D39FAD8-E581-42A8-97B4-EE63800D78A4>