This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C patch] Fix non-regression part of PR29092


Not having this extension at gnu99 was a deliberate decision, in recognition of how C99's compound literals differ from the old GNU "constructor expressions" extension; that is, the compound literal is a temporary object and you wouldn't allow such initialization with a named object instead of a compound literal as initializer.

However, this decision was for structure and union types and different considerations may apply for vector types which aren't in the standard at all.

If so, here is a patch that does this -- actually this is how I had solved the problem first, and then decided it was too much of a hack...


I had already bootstrapped this patch on i686-pc-linux-gnu before posting the other one.

Paolo
2006-09-26  Paolo Bonzini  <bonzini@gnu.org>

	* c-typeck.c (digest_init): Always allow initializing vectors that
	have static storage duration with compound literals.

2006-09-26  Paolo Bonzini  <bonzini@gnu.org>

	* gcc.dg/simd-6.c: UnXFAIL.

--- c-typeck.c	(revision 116745)
+++ c-typeck.c	(working copy)
@@ -4699,12 +4699,14 @@ digest_init (tree type, tree init, bool 
 	   conversion.  */
 	inside_init = convert (type, inside_init);
 
-      if (require_constant && !flag_isoc99
+      if (require_constant
+	  && (code == VECTOR_TYPE || !flag_isoc99)
 	  && TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR)
 	{
 	  /* As an extension, allow initializing objects with static storage
 	     duration with compound literals (which are then treated just as
-	     the brace enclosed list they contain).  */
+	     the brace enclosed list they contain).  Also allow this for
+	     vectors, as we can only assign them with compound literals.  */
 	  tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init);
 	  inside_init = DECL_INITIAL (decl);
 	}
--- testsuite/gcc.dg/simd-6.c	2006-09-26 09:23:54.000000000 +0200
+++ testsuite/gcc.dg/simd-6.c	2006-09-26 11:58:33.000000000 +0200
@@ -3,5 +3,5 @@
 
 /* Ensure that we don't need a typedef to initialize a vector type.  */
 #define vector __attribute__ ((vector_size (8)))
-vector char x = (vector char) {1,2,3,4,5,6,7,8}; /* { dg-bogus "initializer" "" { xfail *-*-* } } */
+vector char x = (vector char) {1,2,3,4,5,6,7,8}; /* { dg-bogus "initializer" "" } */
 vector char y = (vector short) {1,2,3,4}; /* { dg-error "initializer" } */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]