public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Include gmp.h from system.h to fix PR54659
@ 2012-12-21 11:50 Richard Biener
  2012-12-21 12:18 ` Eric Botcazou
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Biener @ 2012-12-21 11:50 UTC (permalink / raw)
  To: gcc-patches; +Cc: ebotcazou, laurent


The following patch includes gmp.h from system.h (where it belongs,
as a system header).  This makes sure the libintl kludge we put in
place with --disable-nls doesn't wreck the gmp header (well, hopefully,
earlier fix to be reverted?).

This runs into issues with Ada which basically does (ugh)

#ifdef __cplusplus
extern "C" {
#endif

#include "system.h"

#endif __cplusplus
}
#endif

which of course wrecks any system header doing __cplusplus
conditional stuff (such as gmp.h including iosfwd).  The patch
un-kludges this by wrapping system.h inside extern "C++" when
compiling with the C++ frontend.

But - really - Ada people - can you fix that on your side please?
(CCed people doing r176210)

Go frontend is left untouched (it also includes gmp.h)

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Comments?  Ok?(!?)

Thanks,
Richard.

2012-12-21  Richard Biener  <rguenther@suse.de>

	PR bootstrap/54659
	* system.h: Wrap inside extern "C++" when __cplusplus.  Include gmp.h.
	* tree-ssa-loop-niter.c: Do not include gmp.h here.
	* double-int.h: Likewise.
	* realmpfr.h: Likewise.

	fortran/
	* gfortran.h: Do not include gmp.h here.

Index: gcc/system.h
===================================================================
*** gcc/system.h	(revision 194659)
--- gcc/system.h	(working copy)
*************** along with GCC; see the file COPYING3.
*** 24,29 ****
--- 24,34 ----
  #ifndef GCC_SYSTEM_H
  #define GCC_SYSTEM_H
  
+ /* Undo extern "C" wrappings done by including files (Ada).  */
+ #ifdef __cplusplus
+ extern "C++" {
+ #endif
+ 
  /* We must include stdarg.h before stdio.h.  */
  #include <stdarg.h>
  
*************** extern int vsnprintf(char *, size_t, con
*** 638,643 ****
--- 643,650 ----
  #include <dlfcn.h>
  #endif
  
+ #include <gmp.h>
+ 
  /* Get libiberty declarations.  */
  #include "libiberty.h"
  
*************** helper_const_non_const_cast (const char
*** 1051,1054 ****
--- 1058,1065 ----
  #define DEBUG_VARIABLE
  #endif
  
+ #ifdef __cplusplus
+ }
+ #endif
+ 
  #endif /* ! GCC_SYSTEM_H */
Index: gcc/tree-ssa-loop-niter.c
===================================================================
*** gcc/tree-ssa-loop-niter.c	(revision 194659)
--- gcc/tree-ssa-loop-niter.c	(working copy)
*************** along with GCC; see the file COPYING3.
*** 38,44 ****
  #include "flags.h"
  #include "diagnostic-core.h"
  #include "tree-inline.h"
- #include "gmp.h"
  
  #define SWAP(X, Y) do { affine_iv *tmp = (X); (X) = (Y); (Y) = tmp; } while (0)
  
--- 38,43 ----
Index: gcc/double-int.h
===================================================================
*** gcc/double-int.h	(revision 194659)
--- gcc/double-int.h	(working copy)
*************** along with GCC; see the file COPYING3.
*** 20,29 ****
  #ifndef DOUBLE_INT_H
  #define DOUBLE_INT_H
  
- #ifndef GENERATOR_FILE
- #include <gmp.h>
- #endif
- 
  /* A large integer is currently represented as a pair of HOST_WIDE_INTs.
     It therefore represents a number with precision of
     2 * HOST_BITS_PER_WIDE_INT bits (it is however possible that the
--- 20,25 ----
Index: gcc/fortran/gfortran.h
===================================================================
*** gcc/fortran/gfortran.h	(revision 194659)
--- gcc/fortran/gfortran.h	(working copy)
*************** gfc_intrinsic_sym;
*** 1699,1705 ****
     EXPR_COMPCALL   Function (or subroutine) call of a procedure pointer
  		   component or type-bound procedure.  */
  
- #include <gmp.h>
  #include <mpfr.h>
  #include <mpc.h>
  #define GFC_RND_MODE GMP_RNDN
--- 1699,1704 ----
Index: gcc/realmpfr.h
===================================================================
*** gcc/realmpfr.h	(revision 194659)
--- gcc/realmpfr.h	(working copy)
***************
*** 22,28 ****
  #ifndef GCC_REALGMP_H
  #define GCC_REALGMP_H
  
- #include <gmp.h>
  #include <mpfr.h>
  #include <mpc.h>
  #include "real.h"
--- 22,27 ----

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Include gmp.h from system.h to fix PR54659
  2012-12-21 11:50 [PATCH] Include gmp.h from system.h to fix PR54659 Richard Biener
@ 2012-12-21 12:18 ` Eric Botcazou
  2012-12-21 12:23   ` Richard Biener
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Botcazou @ 2012-12-21 12:18 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches, laurent

[-- Attachment #1: Type: text/plain, Size: 627 bytes --]

> This runs into issues with Ada which basically does (ugh)
> 
> #ifdef __cplusplus
> extern "C" {
> #endif
> 
> #include "system.h"
> 
> #endif __cplusplus
> }
> #endif
> 
> which of course wrecks any system header doing __cplusplus
> conditional stuff (such as gmp.h including iosfwd).  The patch
> un-kludges this by wrapping system.h inside extern "C++" when
> compiling with the C++ frontend.
> 
> But - really - Ada people - can you fix that on your side please?
> (CCed people doing r176210)

Like so?  I cannot believe that all this fuss was about moving 3 lines within 
less than a dozen of files...

-- 
Eric Botcazou

[-- Attachment #2: terribly_difficult_ada_patch.diff --]
[-- Type: text/x-patch, Size: 7252 bytes --]

Index: targext.c
===================================================================
--- targext.c	(revision 194632)
+++ targext.c	(working copy)
@@ -35,10 +35,6 @@
     Note that, in order to have access to the TARGET_* macros used below,
     the file must be compiled with IN_GCC defined, even for the library.  */
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #ifdef IN_RTS
 #include "tconfig.h"
 #include "tsystem.h"
@@ -57,6 +53,10 @@ extern "C" {
 #define TARGET_EXECUTABLE_SUFFIX ""
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 const char *__gnat_target_object_extension = TARGET_OBJECT_SUFFIX;
 const char *__gnat_target_executable_extension = TARGET_EXECUTABLE_SUFFIX;
 const char *__gnat_target_debuggable_extension = TARGET_EXECUTABLE_SUFFIX;
Index: raise.c
===================================================================
--- raise.c	(revision 194632)
+++ raise.c	(working copy)
@@ -32,10 +32,6 @@
 /* Shared routines to support exception handling.  __gnat_unhandled_terminate
    is shared between all exception handling mechanisms.  */
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #ifdef IN_RTS
 #include "tconfig.h"
 #include "tsystem.h"
@@ -47,6 +43,10 @@ extern "C" {
 #include "adaint.h"
 #include "raise.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*  Wrapper to builtin_longjmp.  This is for the compiler eh only, as the sjlj
     runtime library interfaces directly to the intrinsic.  We can't yet do
     this for the compiler itself, because this capability relies on changes
Index: argv.c
===================================================================
--- argv.c	(revision 194632)
+++ argv.c	(working copy)
@@ -42,10 +42,6 @@
    main program, and these routines are accessed from the
    Ada.Command_Line.Environment package.  */
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #ifdef IN_RTS
 #include "tconfig.h"
 #include "tsystem.h"
@@ -57,6 +53,10 @@ extern "C" {
 
 #include "adaint.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* argc and argv of the main program are saved under gnat_argc and gnat_argv,
    envp of the main program is saved under gnat_envp.  */
 
Index: seh_init.c
===================================================================
--- seh_init.c	(revision 194632)
+++ seh_init.c	(working copy)
@@ -32,10 +32,6 @@
 /*  This unit contains support for SEH (Structured Exception Handling).
     Right now the only implementation is for Win32.  */
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #ifdef IN_RTS
 #include "tconfig.h"
 #include "tsystem.h"
@@ -50,6 +46,10 @@ extern "C" {
 
 #include "raise.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* Addresses of exception data blocks for predefined exceptions. */
 extern struct Exception_Data constraint_error;
 extern struct Exception_Data numeric_error;
Index: env.c
===================================================================
--- env.c	(revision 194632)
+++ env.c	(working copy)
@@ -29,10 +29,6 @@
  *                                                                          *
  ****************************************************************************/
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #ifdef IN_RTS
 #include "tconfig.h"
 #include "tsystem.h"
@@ -76,6 +72,10 @@ extern "C" {
 #include "system.h"
 #endif /* IN_RTS */
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #if defined (__APPLE__)
 #include <crt_externs.h>
 #endif
Index: init.c
===================================================================
--- init.c	(revision 194632)
+++ init.c	(working copy)
@@ -38,10 +38,6 @@
     installed by this file are used to catch the resulting signals that come
     from these probes failing (i.e. touching protected pages).  */
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /* This file should be kept synchronized with 2sinit.ads, 2sinit.adb,
    s-init-ae653-cert.adb and s-init-xi-sparc.adb.  All these files implement
    the required functionality for different targets.  */
@@ -71,6 +67,10 @@ extern "C" {
 #include "adaint.h"
 #include "raise.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 extern void __gnat_raise_program_error (const char *, int);
 
 /* Addresses of exception data blocks for predefined exceptions.  Tasking_Error
Index: initialize.c
===================================================================
--- initialize.c	(revision 194632)
+++ initialize.c	(working copy)
@@ -34,10 +34,6 @@
     in a separate file/object so that users can replace it easily.
     The default implementation should be null on most targets.  */
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /* The following include is here to meet the published VxWorks requirement
    that the __vxworks header appear before any other include.  */
 #ifdef __vxworks
@@ -57,6 +53,10 @@ extern "C" {
 
 #include "raise.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /******************************************/
 /* __gnat_initialize (NT-mingw32 Version) */
 /******************************************/
Index: exit.c
===================================================================
--- exit.c	(revision 194632)
+++ exit.c	(working copy)
@@ -29,10 +29,6 @@
  *                                                                          *
  ****************************************************************************/
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #ifdef __alpha_vxworks
 #include "vxWorks.h"
 #endif
@@ -48,6 +44,10 @@ extern "C" {
 
 #include "adaint.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* Routine used by Ada.Command_Line.Set_Exit_Status.  */
 
 int gnat_exit_status = 0;
Index: adaint.c
===================================================================
--- adaint.c	(revision 194632)
+++ adaint.c	(working copy)
@@ -34,10 +34,6 @@
    package Osint.  Many of the subprograms in OS_Lib import standard
    library calls directly. This file contains all other routines.  */
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #ifdef __vxworks
 
 /* No need to redefine exit here.  */
@@ -107,6 +103,10 @@ extern "C" {
 #include "version.h"
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #if defined (__MINGW32__)
 
 #if defined (RTX)
Index: cio.c
===================================================================
--- cio.c	(revision 194632)
+++ cio.c	(working copy)
@@ -29,10 +29,6 @@
  *                                                                          *
  ****************************************************************************/
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #ifdef IN_RTS
 #include "tconfig.h"
 #include "tsystem.h"
@@ -44,6 +40,10 @@ extern "C" {
 
 #include "adaint.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* Don't use macros on GNU/Linux since they cause incompatible changes between
    glibc 2.0 and 2.1 */
 #ifdef linux
Index: cstreams.c
===================================================================
--- cstreams.c	(revision 194632)
+++ cstreams.c	(working copy)
@@ -31,10 +31,6 @@
 
 /* Routines required for implementing routines in Interfaces.C.Streams.  */
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #ifdef __vxworks
 #include "vxWorks.h"
 #endif
@@ -50,6 +46,10 @@ extern "C" {
 
 #include "adaint.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #ifdef VMS
 #include <unixlib.h>
 #endif

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Include gmp.h from system.h to fix PR54659
  2012-12-21 12:18 ` Eric Botcazou
@ 2012-12-21 12:23   ` Richard Biener
  2012-12-21 12:33     ` Eric Botcazou
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Biener @ 2012-12-21 12:23 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: gcc-patches, laurent

On Fri, 21 Dec 2012, Eric Botcazou wrote:

> > This runs into issues with Ada which basically does (ugh)
> > 
> > #ifdef __cplusplus
> > extern "C" {
> > #endif
> > 
> > #include "system.h"
> > 
> > #endif __cplusplus
> > }
> > #endif
> > 
> > which of course wrecks any system header doing __cplusplus
> > conditional stuff (such as gmp.h including iosfwd).  The patch
> > un-kludges this by wrapping system.h inside extern "C++" when
> > compiling with the C++ frontend.
> > 
> > But - really - Ada people - can you fix that on your side please?
> > (CCed people doing r176210)
> 
> Like so?  I cannot believe that all this fuss was about moving 3 lines within 
> less than a dozen of files...

The patch looks fine to me (though it's not 100% obvious to me as not only
system headers are now no longer in extern "C" - which is why I simply
tried the un-wrapping).  So, if you think that's ok please commit it.

It certainly helps not to rely on compilers handling nested extern "foo"
correctly ...

Thanks,
Richard.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Include gmp.h from system.h to fix PR54659
  2012-12-21 12:23   ` Richard Biener
@ 2012-12-21 12:33     ` Eric Botcazou
  2012-12-21 13:03       ` Richard Biener
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Botcazou @ 2012-12-21 12:33 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches, laurent

> The patch looks fine to me (though it's not 100% obvious to me as not only
> system headers are now no longer in extern "C" - which is why I simply
> tried the un-wrapping).  So, if you think that's ok please commit it.

Done.

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Include gmp.h from system.h to fix PR54659
  2012-12-21 12:33     ` Eric Botcazou
@ 2012-12-21 13:03       ` Richard Biener
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Biener @ 2012-12-21 13:03 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: gcc-patches, laurent

On Fri, 21 Dec 2012, Eric Botcazou wrote:

> > The patch looks fine to me (though it's not 100% obvious to me as not only
> > system headers are now no longer in extern "C" - which is why I simply
> > tried the un-wrapping).  So, if you think that's ok please commit it.
> 
> Done.

Thanks.

Richard.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-12-21 13:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-21 11:50 [PATCH] Include gmp.h from system.h to fix PR54659 Richard Biener
2012-12-21 12:18 ` Eric Botcazou
2012-12-21 12:23   ` Richard Biener
2012-12-21 12:33     ` Eric Botcazou
2012-12-21 13:03       ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).