PR 89864 - gcc fails to build/bootstrap with XCode 10.2

2019-04-03 Thread Erik Schnetter
Fixinclude the header file  that incorrectly uses the C-only
_Atomic keyword when compiled as C++. Apply the same work-around for two
GCC source files that transitively use this header file.

Index: fixincludes/inclhack.def
===
--- fixincludes/inclhack.def (revision 270127)
+++ fixincludes/inclhack.def (working copy)
@@ -1298,6 +1298,36 @@ fix = {
 };

 /*
+ *  macOS 10.14.4  uses the C _Atomic keyword in C++ code.
+ */
+fix = {
+hackname  = darwin_ucred__Atomic;
+mach  = "*-*-darwin18.5.*";
+files = sys/ucred.h;
+select= "_Atomic";
+
+c_fix = wrap;
+
+c_fix_arg = <<- _EOArg_
+
+ #if defined(__cplusplus) && __cplusplus >= 201103L
+ #  define _Atomic volatile
+ #endif
+
+ _EOArg_;
+
+c_fix_arg = <<- _EOArg_
+
+ #if defined(__cplusplus) && __cplusplus >= 201103L
+ #  undef _Atomic
+ #endif
+
+ _EOArg_;
+
+test_text = "#include \n";
+};
+
+/*
  *  For the AAB_darwin7_9_long_double_funcs fix to be useful,
  *  you have to not use "" includes.
  */
Index: gcc/config/darwin-driver.c
===
--- gcc/config/darwin-driver.c (revision 270127)
+++ gcc/config/darwin-driver.c (working copy)
@@ -27,7 +27,15 @@ along with GCC; see the file COPYING3.
 #include "diagnostic-core.h"

 #ifndef CROSS_DIRECTORY_STRUCTURE
+#if defined(__cplusplus) && __cplusplus >= 201103L
+// This is safe because it applies only to struct ucred, which is
+// not actually used by gcc.
+#define _Atomic volatile
+#endif
 #include 
+#if defined(__cplusplus) && __cplusplus >= 201103L
+#undef _Atomic
+#endif
 #include "xregex.h"

 static char *
Index: libsanitizer/sanitizer_common/sanitizer_mac.cc
===
--- libsanitizer/sanitizer_common/sanitizer_mac.cc (revision 270127)
+++ libsanitizer/sanitizer_common/sanitizer_mac.cc (working copy)
@@ -67,7 +67,13 @@ extern "C" {
 #include 
 #include 
 #include 
+#if defined(__cplusplus) && __cplusplus >= 201103L
+#  define _Atomic volatile
+#endif
 #include 
+#if defined(__cplusplus) && __cplusplus >= 201103L
+#  undef _Atomic
+#endif
 #include 
 #include 
 #include 


-- 
Erik Schnetter 
http://www.perimeterinstitute.ca/personal/eschnetter/


Re: PR 89864 - gcc fails to build/bootstrap with XCode 10.2

2019-04-04 Thread Erik Schnetter
On Thu, Apr 4, 2019 at 3:11 AM Iain Sandoe  wrote:

> Hi Eric,
>
> Thanks for working on this!
>
> > On 4 Apr 2019, at 04:00, Erik Schnetter  wrote:
> >
> > Fixinclude the header file  that incorrectly uses the C-only
> > _Atomic keyword when compiled as C++. Apply the same work-around for two
> > GCC source files that transitively use this header file.
>
> 1/
> If the fix-include is doing the right thing, then there should be no need
> for a
> workaround in any GCC file including it.
>
> Perhaps the wrap needs to be around the (SDK) header(s) that is/are
> including ?
>
> (so if   is including , then the wrap needs to
> be in that
> file, not in the GCC files that use it).
>

Okay, that's good to know. I will update the patch accordingly.

2/
> I’m somewhat unhappy that this will hack around the problem and silently do
> something that can’t work properly in any case that we started to use the
> field/struct.  What didn’t work about your proposed substitution of the
> appropriate
> c++  stuff?
>

What doesn't work was that this requires changing . If only
 can be changed, then it is not possible to replace _Atomic
ulong by _Atomic(ulong) (adding parentheses). I'll try fixincluding both
files.

-erik

-- 
Erik Schnetter 
http://www.perimeterinstitute.ca/personal/eschnetter/