svn commit: r268137 - head/sys/sys

Bruce Evans brde at optusnet.com.au
Fri Jun 19 17:23:20 UTC 2015


On Fri, 19 Jun 2015, Dimitry Andric wrote:

> On 19 Jun 2015, at 17:02, Pedro Giffuni <pfg at freebsd.org> wrote:
>>
>>> On 19/06/2015 05:16 a.m., David Chisnall wrote:
>>>> I only just caught this (having seen the fallout from NetBSD doing the same thing in a shipping release and the pain that it’s caused):
>>>>
>>>> __weak is a reserved keyword in Objective-C, please pick another name for this.  This in cdefs.h makes it impossible to include any FreeBSD standard headers in Objective-C programs (of which we have a couple of hundred in ports) if they use any of the modern Objective-C language modes.
> ...
>> Closely related to this, we are redefining _Noreturn, which is a reserved keyword in C11.
>
> No, sys/cdefs.h has:
>
>   254  /*
>   255   * Keywords added in C11.
>   256   */
>   257
>   258  #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || defined(lint)
> [...]
>   284  #if defined(__cplusplus) && __cplusplus >= 201103L
>   285  #define _Noreturn               [[noreturn]]
>   286  #else
>   287  #define _Noreturn               __dead2
>   288  #endif
> [...]
>   320  #endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */
>
> So the whole block redefining all the _Xxx identifiers is skipped for
> C11 and higher.

I probably pointed this out incorrectly to Pedro.

All uses of _Noreturn are still broken, and also ugly.  __dead2 is the
gcc-2 compatible version of the gcc-1 compatible macro __dead.  It is
syntactically different from __dead and _Noreturn.  It must be placed
after the function parameter list instead of in the function type
declarator because old versions of gcc only accept attributes there.
__dead and presumably _Noreturn must be placed in the function type
declarator.  This is incompatible, and also uglier.

> E.g.:
>
> $ cpp -std=c99
> #include <sys/cdefs.h>
> _Noreturn void foo(void);
> ^D
> # 1 "<stdin>"
> # 1 "<built-in>" 1
> # 1 "<built-in>" 3
> # 306 "<built-in>" 3
> # 1 "<command line>" 1
> # 1 "<built-in>" 2
> # 1 "<stdin>" 2
> # 1 "/usr/include/sys/cdefs.h" 1 3 4
> # 2 "<stdin>" 2
> __attribute__((__noreturn__)) void foo(void);

Syntax error with older versions of gcc that cdefs.h is supposed to support.
Thee versions that don't support attributes in the declarator also don't
support c99, so the order can be anything with them, but this doesn't
simplify fixing the problem -- you still need massive ifdefs or ugly
declarations.

> $ cpp -std=c11
> #include <sys/cdefs.h>
> _Noreturn void foo(void);
> ^D
> # 1 "<stdin>"
> # 1 "<built-in>" 1
> # 1 "<built-in>" 3
> # 306 "<built-in>" 3
> # 1 "<command line>" 1
> # 1 "<built-in>" 2
> # 1 "<stdin>" 2
> # 1 "/usr/include/sys/cdefs.h" 1 3 4
> # 2 "<stdin>" 2
> _Noreturn void foo(void);

Correct version with ugly declarations:

__dead void
 	foo(void) __dead2;

where:
1. __dead is the gcc-1 compatible macro restored to handle the different
   spelling in C11.  Direct spellings should not be used, since they cause
   namespace bugs like the current ones for __weak.
2. __dead2 is the gcc-2 compatible macro.  It also works for later gcc's
   and clang, perhaps even in C11.
3. __dead is defined as follows:
   a. for gcc-1, either leave it undefined (to keep its current behaviour
      of breaking any use of it), or define as its gcc-1 value again.
   b. for C11, define it as _Noreturn
   c. otherwise, define it as empty
4. __dead2 is defined the same as now.  Hopefully it is just redundant of
    __dead is defined as _Noreturn for C11.
5. the style of the above is taken from 4.4BSD-Lite2, which still has __dead
    and still defines it as __volatile and still has almost no support for
    gcc-2.  From Lite2 stdlib.h:

__dead void
 	 abort __P((void));
....
__dead void
 	 exit __P((int));

   Putting __dead first messes up the formatting by requiring an extra line
   to keep the function names lined up.

When I cleaned this up in FreeBSD, the first stage was to add __dead2 while
keeping __dead in 1994, the second stage was to remove __dead from
everywhere in the source tree except cdefs.h in 1996, and the "final" stage
was to remove the definition of __dead from cdefs.h in 1998.  The current
breakage shows that this was not even the final stage.

Bruce


More information about the svn-src-head mailing list