Bug 52168 - fixinclude test failure for complex.h on netbsd
Summary: fixinclude test failure for complex.h on netbsd
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-08 09:28 UTC by Jonathan Wakely
Modified: 2014-11-16 14:29 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-11-16 00:00:00


Attachments
replace 'c' command with 'i' and 'd' (794 bytes, patch)
2012-02-09 21:31 UTC, Jonathan Wakely
Details | Diff
group the i and d functions (790 bytes, patch)
2012-02-09 21:58 UTC, Jonathan Wakely
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2012-02-08 09:28:59 UTC
Bootstrapped using the default BSD sed, awk etc.


complex.h /home/jwakely/src/full/gcc/fixincludes/tests/base/complex.h differ: char 839, line 41
*** complex.h   Wed Feb  8 10:21:00 2012
--- /home/jwakely/src/full/gcc/fixincludes/tests/base/complex.h Mon Nov  7 09:52:51 2011
***************
*** 38,43 ****
  #if defined( SOLARIS_COMPLEX_CXX_CHECK )
  #ifdef        __cplusplus
  extern "C" {
! #endif#ifdef  __cplusplus
  }
! #endif#endif  /* SOLARIS_COMPLEX_CXX_CHECK */
--- 38,45 ----
  #if defined( SOLARIS_COMPLEX_CXX_CHECK )
  #ifdef        __cplusplus
  extern "C" {
! #endif
! #ifdef        __cplusplus
  }
! #endif
! #endif  /* SOLARIS_COMPLEX_CXX_CHECK */

There were fixinclude test FAILURES
Comment 1 Richard Biener 2012-02-08 10:19:50 UTC
Weird original formatting in complex.h
Comment 2 Jonathan Wakely 2012-02-09 00:37:58 UTC
The problem is that netbsd's sed doesn't put a newline after a 'c' command, so the two 'endif' here (from fixincl.x) don't get newlines after them:

/*
 *  Fix Command Arguments for Solaris_Complex_Cxx
 */
static const char* apzSolaris_Complex_CxxPatch[] = { sed_cmd_z,
    "-e", "/#if[ \t]*!defined(__cplusplus)/c\\\n\
#ifdef\t__cplusplus\\\n\
extern \"C\" {\\\n\
#endif",
    "-e", "/#endif[ \t]*\\/\\* !defined(__cplusplus) \\*\\//c\\\n\
#ifdef\t__cplusplus\\\n\
}\\\n\
#endif",
    (char*)NULL };


With GNU sed:

$ { echo foo ; echo bar ; }  | sed '/foo/c\                              
baz'
baz                                                                           
bar

But with netbsd sed:

$ { echo foo ; echo bar ; } | sed '/foo/c\
baz'
bazbar
Comment 3 Jakub Jelinek 2012-02-09 09:20:21 UTC
This isn't the only issue we had with sed c command, see
http://gcc.gnu.org/ml/gcc-patches/2011-05/msg01110.html
And this is the only spot in fixincl that uses it.  Can't it be rewritten with without sed somehow (c_test/c_fix* ?)?
Comment 4 Jonathan Wakely 2012-02-09 12:19:38 UTC
NetBSD PR http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=45955

My analysis of the problem was incorrect and it looks as though a fix would be to put an *unescaped* \n at the end of each -e script:

 /*
  *  Fix Command Arguments for Solaris_Complex_Cxx
  */
 static const char* apzSolaris_Complex_CxxPatch[] = { sed_cmd_z,
     "-e", "/#if[ \t]*!defined(__cplusplus)/c\\\n\
 #ifdef\t__cplusplus\\\n\
 extern \"C\" {\\\n\
-#endif",
+#endif\n",
     "-e", "/#endif[ \t]*\\/\\* !defined(__cplusplus) \\*\\//c\\\n\
 #ifdef\t__cplusplus\\\n\
 }\\\n\
-#endif",
+#endif\n",
     (char*)NULL };

POSIX requires that a newline in the replacement text be escaped with \ so an unescaped newline is not part of the replacement text.  GNU and Solaris both correctly ignore an unescaped newline at the end of the script, apparently netbsd does too (but I can't test that until later today)
Comment 5 Jonathan Wakely 2012-02-09 12:24:14 UTC
(In reply to comment #4)
> netbsd does too (but I can't test that until later today)

or rather, it doesn't ignore the newline, but it does produce the expected result
Comment 6 Jonathan Wakely 2012-02-09 21:31:48 UTC
Created attachment 26633 [details]
replace 'c' command with 'i' and 'd'

this passes the tests on gnu/linux and netbsd
Comment 7 Jonathan Wakely 2012-02-09 21:58:24 UTC
Created attachment 26634 [details]
group the i and d functions

equivalent, but avoids repeating the context address by grouping the functions in braces

also passes all tests on both gnu/linux and netbsd
Comment 8 Jonathan Wakely 2012-02-09 22:03:14 UTC
priority -> minor because it doesn't really matter if a fixinclude for Solaris doesn't work on netbsd, except for causing a test faulre
Comment 9 Richard PALO 2014-11-16 06:40:59 UTC
(In reply to Jonathan Wakely from comment #8)
> priority -> minor because it doesn't really matter if a fixinclude for
> Solaris doesn't work on netbsd, except for causing a test faulre

Except that this issue is also present for solaris pkgsrc developers.

+1 for the patch