diff mbox

RFA: PATCHes to accept C99 designated initializer syntax in C++

Message ID 4E271AE3.3030301@redhat.com
State New
Headers show

Commit Message

Jason Merrill July 20, 2011, 6:13 p.m. UTC
The first patch adjusts the C++ front end's current support for the old 
GNU designated initializer syntax to support the C99 syntax as well.

The second patch adjusts recog.h/genoutput.c to use a new macro 
HAVE_DESIGNATED_UNION_INITIALIZERS instead of 
HAVE_DESIGNATED_INITIALIZERS because with the above change, the uses 
there work with the C++ compiler, but the uses in dwarf2asm.c still 
don't because they involve out-of-order initialization.

I'm applying the first patch to trunk.  Is the second patch OK as well, 
or should use of designated initializers in recog.h wait until the C++ 
front end supports the dwarf2asm.c use as well?

Jason

Comments

Jakub Jelinek July 20, 2011, 7:14 p.m. UTC | #1
On Wed, Jul 20, 2011 at 02:13:55PM -0400, Jason Merrill wrote:
> The first patch adjusts the C++ front end's current support for the
> old GNU designated initializer syntax to support the C99 syntax as
> well.

Thanks.

> The second patch adjusts recog.h/genoutput.c to use a new macro
> HAVE_DESIGNATED_UNION_INITIALIZERS instead of
> HAVE_DESIGNATED_INITIALIZERS because with the above change, the uses
> there work with the C++ compiler, but the uses in dwarf2asm.c still
> don't because they involve out-of-order initialization.
> 
> I'm applying the first patch to trunk.  Is the second patch OK as
> well, or should use of designated initializers in recog.h wait until
> the C++ front end supports the dwarf2asm.c use as well?

I think it is fine to start using it now, if the C++ front end gets support
even for more complicated designated initializers, we can revert that
second patch (if it happens during 4.7 timeframe).

BTW, optabs.c up to 4.5 was also using:
#if GCC_VERSION >= 4000 && HAVE_DESIGNATED_INITIALIZERS
__extension__ struct convert_optab_d convert_optab_table[COI_MAX]
  = { [0 ... COI_MAX - 1].handlers[0 ... NUM_MACHINE_MODES - 1]
        [0 ... NUM_MACHINE_MODES - 1].insn_code
      = CODE_FOR_nothing };
#else
/* init_convert_optab will do runtime initialization otherwise.  */
struct convert_optab_d convert_optab_table[COI_MAX];
#endif
haven't looked exactly with what 4.6 replaced this with and if it
wasn't just because C++ doesn't support designated initializers.

	Jakub
Richard Biener July 21, 2011, 8:36 a.m. UTC | #2
On Wed, 20 Jul 2011, Jason Merrill wrote:

> The first patch adjusts the C++ front end's current support for the old GNU
> designated initializer syntax to support the C99 syntax as well.
> 
> The second patch adjusts recog.h/genoutput.c to use a new macro
> HAVE_DESIGNATED_UNION_INITIALIZERS instead of HAVE_DESIGNATED_INITIALIZERS
> because with the above change, the uses there work with the C++ compiler, but
> the uses in dwarf2asm.c still don't because they involve out-of-order
> initialization.
> 
> I'm applying the first patch to trunk.  Is the second patch OK as well, or
> should use of designated initializers in recog.h wait until the C++ front end
> supports the dwarf2asm.c use as well?

The 2nd patch is ok as well, it fixes a memory usage regression introduced
by building with C++.

Thanks,
Richard.
diff mbox

Patch

commit 351d098c503777d9c48906cecb97293b572a558b
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Jul 20 14:09:55 2011 -0400

    	* system.h (HAVE_DESIGNATED_UNION_INITIALIZERS): New.
    	* recog.h (struct insn_data_d): Check it instead of
    	HAVE_DESIGNATED_INITIALIZERS.
    	* genoutput.c (output_insn_data): Likewise.

diff --git a/gcc/genoutput.c b/gcc/genoutput.c
index 621439f..bc41b7b 100644
--- a/gcc/genoutput.c
+++ b/gcc/genoutput.c
@@ -340,7 +340,7 @@  output_insn_data (void)
       switch (d->output_format)
 	{
 	case INSN_OUTPUT_FORMAT_NONE:
-	  printf ("#if HAVE_DESIGNATED_INITIALIZERS\n");
+	  printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
 	  printf ("    { 0 },\n");
 	  printf ("#else\n");
 	  printf ("    { 0, 0, 0 },\n");
@@ -351,7 +351,7 @@  output_insn_data (void)
 	    const char *p = d->template_code;
 	    char prev = 0;
 
-	    printf ("#if HAVE_DESIGNATED_INITIALIZERS\n");
+	    printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
 	    printf ("    { .single =\n");
 	    printf ("#else\n");
 	    printf ("    {\n");
@@ -372,7 +372,7 @@  output_insn_data (void)
 		++p;
 	      }
 	    printf ("\",\n");
-	    printf ("#if HAVE_DESIGNATED_INITIALIZERS\n");
+	    printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
 	    printf ("    },\n");
 	    printf ("#else\n");
 	    printf ("    0, 0 },\n");
@@ -380,14 +380,14 @@  output_insn_data (void)
 	  }
 	  break;
 	case INSN_OUTPUT_FORMAT_MULTI:
-	  printf ("#if HAVE_DESIGNATED_INITIALIZERS\n");
+	  printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
 	  printf ("    { .multi = output_%d },\n", d->code_number);
 	  printf ("#else\n");
 	  printf ("    { 0, output_%d, 0 },\n", d->code_number);
 	  printf ("#endif\n");
 	  break;
 	case INSN_OUTPUT_FORMAT_FUNCTION:
-	  printf ("#if HAVE_DESIGNATED_INITIALIZERS\n");
+	  printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
 	  printf ("    { .function = output_%d },\n", d->code_number);
 	  printf ("#else\n");
 	  printf ("    { 0, 0, output_%d },\n", d->code_number);
diff --git a/gcc/recog.h b/gcc/recog.h
index cce1321..71dfe2a 100644
--- a/gcc/recog.h
+++ b/gcc/recog.h
@@ -286,7 +286,7 @@  struct insn_operand_data
 struct insn_data_d
 {
   const char *const name;
-#if HAVE_DESIGNATED_INITIALIZERS
+#if HAVE_DESIGNATED_UNION_INITIALIZERS
   union {
     const char *single;
     const char *const *multi;
diff --git a/gcc/system.h b/gcc/system.h
index e02cbcd..ce027b2 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -500,6 +500,12 @@  extern int vsnprintf(char *, size_t, const char *, va_list);
    && !defined(__cplusplus))
 #endif
 
+#if !defined(HAVE_DESIGNATED_UNION_INITIALIZERS)
+#define HAVE_DESIGNATED_UNION_INITIALIZERS \
+  (((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L)) \
+   && (!defined(__cplusplus) || (GCC_VERSION >= 4007)))
+#endif
+
 #if HAVE_SYS_STAT_H
 # include <sys/stat.h>
 #endif