diff mbox

[SH,committed] Fix PR 61026 sh-*-* Fails to Compile on FreeBSD

Message ID 1399105469.2451.31.camel@yam-132-YW-E178-FTW
State New
Headers show

Commit Message

Oleg Endo May 3, 2014, 8:24 a.m. UTC
On Thu, 2014-05-01 at 23:39 +0200, Oleg Endo wrote:
> 
> On May 1, 2014, at 11:17 PM, Joel Sherrill <joel.sherrill@oarcorp.com> wrote:
> 
> > 
> > On 5/1/2014 3:29 PM, Oleg Endo wrote:
> >> On 01 May 2014, at 22:08, Joel Sherrill <joel.sherrill@oarcorp.com> wrote:
> >> 
> >>> Hi
> >>> 
> >>> gcc-4.8.2 targeting sh-*-* fails to compile on
> >>> FreeBSD 10 which is using clang. I am hoping someone
> >>> has some ideas about these.
> >> Yes, I've noticed and mentioned this already a while ago:
> >> http://gcc.gnu.org/ml/gcc/2013-12/msg00036.html
> >> 
> >> 
> >>> In file included from ../../gcc-4.8.2/gcc/config/sh/sh.c:63:
> >>> In file included from /usr/include/c++/v1/sstream:174:
> >>> In file included from /usr/include/c++/v1/ostream:131:
> >>> In file included from /usr/include/c++/v1/ios:216:
> >>> In file included from /usr/include/c++/v1/__locale:15:
> >>> In file included from /usr/include/c++/v1/string:438:
> >>> In file included from /usr/include/c++/v1/cwchar:107:
> >>> In file included from /usr/include/c++/v1/cwctype:54:
> >>> /usr/include/c++/v1/cctype:51:72: error: use of undeclared identifier
> >>> 'do_not_use_isalnum_with_safe_ctype'
> >>> inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isalnum(int __c) {return
> >>> isalnum(__c);}
> >>> 
> >>> sh.c line 63 is this:
> >>> 
> >>> #include <sstream>
> >>> #include <vector>
> >>> #include <algorithm>
> >>> 
> >>> It is the only file in gcc/config/* to include sstream.  Has some
> >>> update sweep for C++ transition missed this file?
> >> Could you please try moving the std includes above any other (gcc) includes and see if it fixes the issue?  AFAIR it did it for me.
> > This seems to fix it. I am not sure why sh.c is the only file in
> > gcc/config which includes sstream though.
> 
> Because I added code to sh.c that uses stuff from sstream after the switch to C++.
> 
> > Is this a violation
> > of some new rule?
> 
> Not that I'm aware of.
> 
> > Is there a PR for this?
> > 
> > If not, I probably should file one and get the patch pushed
> > into 4.8 as well as 4.9 and the head if they need it.
> > 
> 
> If you insist on having a PR for it, please feel free.  In any case, I'll commit the 'fix' to trunk and the branches by tomorrow.

I've committed the patch below to trunk, 4.9 branch and 4.8 branch.

Cheers,
Oleg

gcc/ChangeLog:
	PR target/61026
	* config/sh/sh.c: Include stdlib headers before everything else.

Comments

Joseph Myers May 7, 2014, 4:37 p.m. UTC | #1
On Sat, 3 May 2014, Oleg Endo wrote:

> +#include <sstream>
> +#include <vector>
> +#include <algorithm>
> +
>  #include "config.h"

It's never OK to include any system headers (C or C++) before "config.h".  
config.h may define feature test macros such as _FILE_OFFSET_BITS that 
affect system headers in various ways and are only effective if defined 
before any system headers are included, and if different files in GCC are 
built with different settings of such feature test macros then they may 
expect incompatible choices of ABI for C library types.

(This is a general principle for any software using autoconf, at least if 
it uses any of the autoconf macros that can define feature test macros - 
which GCC does - not just for GCC.)
diff mbox

Patch

Index: gcc/config/sh/sh.c
===================================================================
--- gcc/config/sh/sh.c	(revision 210027)
+++ gcc/config/sh/sh.c	(working copy)
@@ -19,6 +19,10 @@ 
 along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
+#include <sstream>
+#include <vector>
+#include <algorithm>
+
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
@@ -70,10 +74,6 @@ 
 #include "pass_manager.h"
 #include "context.h"
 
-#include <sstream>
-#include <vector>
-#include <algorithm>
-
 int code_for_indirect_jump_scratch = CODE_FOR_indirect_jump_scratch;
 
 /* These are some macros to abstract register modes.  */