5855 fix __RESTRICT_KYWD to support the correct keyword with c++

Review Request #36 — Created April 17, 2015 and submitted

risto3
illumos-gate
5855
51b86d3...
general

5855 fix __RESTRICT_KYWD to support the correct keyword with c++

<added 19/04/2015>
I believe the description should reflect now the fact that these are rectifications
to what gnu C does in fix-includes for c++ purposes. This permits the same with
non g++/clang++ compilers such as sunstudio CC.

Perhaps:
5855 update posix_spawn[p] with rectified __RESTRICT_KYWD enabling 'restrict' semantics for both C and C++

The gate (on illumos-omnios) builds clean, lint-clean and shadow-compiler clean.

I've tested with both Sun C++ 5.9 SunOS_i386 Patch 124864-12 2009/04/21
and Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21

I've also bootstrapped gcc (primarily 4.9.x now without my patch) and it swallows the good version just fine
as expected.

[update 2/07/2015]
I was mistaken, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61649 still needs to commit otherwise the
#ifdef __cplusplus
...
clause is doubled causing warnings, so I've asked again for a commit of the patches provided to gcc.

  • 1
  • 0
  • 1
  • 1
  • 3
Description From Last Updated
Do C++ compilers define _STDC_C99 ?? This doesn't look like should work, unless they do, and if they do that ... gdamore gdamore
gdamore
  1. 
      
  2. usr/src/uts/common/sys/feature_tests.h (Diff revision 1)
     
     

    Do C++ compilers define _STDC_C99 ?? This doesn't look like should work, unless they do, and if they do that would be surprising.

    I'm highly skeptical that this is the right behavior. It doesn't look like it should be harmful, assuming that a C++ compiler declares itself to support C99 and actually supports the restrict keyword.

    The bug needs to have a clearer description of what problem you are actually trying to solve here. There are references to multiple compilers, and "fixed behavior", but what is the wrong behavior, and what is the correct behavior?

    1. They do (erroneously), make that define. We've had to fix bullshit related to that before. There's history here in #2941

      The other problem we've had with C++ and restrict is that the placement of restrict is differently standardized between C and C++. This is what screwed up the standards prototype of posix_spawn.

             int posix_spawn(pid_t *restrict pid, const char *restrict path,
                  const posix_spawn_file_actions_t *file_actions,
                  const posix_spawnattr_t *restrict attrp,
                  char *const argv[restrict], char *const envp[restrict]);
      

      C++ doesn't allow that definition of argv and envp.
      I'm somewhat worried this change will re-introduce that problem.

    2. Indeed! I found https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49347
      which is probably why I don't see the issue with gcc (using the either patch with the solaris headers).

      BTW, I find NetBSD did the following:
      /
      * Spawn routines

      /
      int posix_spawn(pid_t * __restrict, const char * __restrict,
      const posix_spawn_file_actions_t
      , const posix_spawnattr_t * __restrict,
      char * const __restrict, char * const __restrict);
      int posix_spawnp(pid_t * __restrict, const char * __restrict,
      const posix_spawn_file_actions_t , const posix_spawnattr_t * __restrict,
      char * const
      __restrict, char * const *__restrict);

      FreeBSD does:
      /
      * Spawn routines

      * XXX both arrays should be __restrict, but this does not work when GCC
      * is invoked with -std=c99.
      /
      int posix_spawn(pid_t * __restrict, const char * __restrict,
      const posix_spawn_file_actions_t
      , const posix_spawnattr_t * __restrict,
      char * const [], char * const []);
      int posix_spawnp(pid_t * __restrict, const char * __restrict,
      const posix_spawn_file_actions_t *, const posix_spawnattr_t * __restrict,
      char * const [], char * const []);

      NetBSD's approach seems reasonable. FreeBSD's would work as well...

      Too bad the Open Group didn't consider the c++ issue.

      Back to the biz, the gate (for me) seems to build crystal clean with shadow compiling on and with lint.
      I guess I can only see if there are some [test] programs using, e.g. posix_spawn

    3. shit, markdown... sorry. guess we can't edit the entry here, I meant to fix the references
      and add that the tests are primarily for studio.

    4. BTW, with the updated patch providing what fixincl initially did to modify spawn.h,
      gcc correctly passes through to native now as expected.
      Therefore, two headers initially fixed up by gcc are now clean natively for both these issues.
      I don't do bulk builds, but am pushing 1K packages in building pkgsrc with no perceived issue.

  3. 
      
risto3
risto3
risto3
igork
  1. Ship It!
  2. 
      
risto3
jeffpc
  1. 
      
  2. usr/src/uts/common/sys/feature_tests.h (Diff revision 3)
     
     

    I'd remove the space between # and define - to be consistent.

    1. Hi Josef, as I mention in the block comment preceding, the space is needed to FOIL fixincludes when building gcc.

      Otherwise it forks up the definition. CSTYLE is dealt with via the inline comment.
      I proposed upstream gcc a patch to add a line of context but it falls on deaf ears
      (my suspicion is that illumos is not considered in the same light as Solaris, unfortunately).

  3. 
      
jeffpc
  1. 
      
  2. usr/src/uts/common/sys/feature_tests.h (Diff revision 3)
     
     

    Oh, I see... I thought that was talking about the presence of the #define not the specific whitespacing. Since the whitespace is important, I think it wouldn't be the worst thing to make the comment more... eye catching. How about moving that sentence closer to the strange looking #define? E.g.,

    ...
    #else
    /*
     * NOTE: The whitespace between the # and define is significant.  It foils gcc's fixincludes from defining a dedundant 'restrict'.
     */
     *
    /* CSTYLED */
    # define _RESTRICT_KYWD restrict
    #endif
    
  3. 
      
risto3
jeffpc
  1. Ship It!
  2. 
      
risto3
Review request changed

Status: Closed (submitted)

Change Summary:

commit 10a6478a64c986fe8b918521951c9068ed5588fe

Loading...