diff mbox

[4.7] Fix PR 48226, Allow Iterator::vector vector on powerpc with VSX

Message ID 20110321232359.GA1378@hungry-tiger.westford.ibm.com
State New
Headers show

Commit Message

Michael Meissner March 21, 2011, 11:23 p.m. UTC
This patch fixes a problem discovered by compiling the boost libraries with VSX
enabled.  In the middle of a template is the code:

	namespace boost
	{
	  // ...
	  template <typename Iterator>
	  struct apply
	  {
	    // ...
	    typedef typename Iterator::vector vector;
	    // ...
	  };
	}

The conditional keyword 'vector' is being handled by rs6000_macro_to_expand,
and it wants to peek at the next keyword.  If the next keyword is also vector,
rs6000_macro_to_expand will be called recursively, and the expansion of vector
into vector will be lost.

I have boostrapped the following patch and it fixes the problem, and causes no
regressions in the make check out.  Is this ok to install in the trunk?  I
would also like to backport this to the 4.6 branch (after the 4.6 release) and
the 4.5 branch which also have the same problem.

[gcc]
2011-03-21  Michael Meissner  <meissner@linux.vnet.ibm.com>

	PR target/48226
	* config/rs6000/rs6000-c.c (rs6000_macro_to_expand): If we see a
	vector when peeking at the next token for vector, don't expand the
	keywords.

[gcc/testsuite]
2011-03-21  Michael Meissner  <meissner@linux.vnet.ibm.com>

	PR target/48226
	* gcc.target/powerpc/pr48226.c: New file.
diff mbox

Patch

Index: gcc/testsuite/gcc.target/powerpc/pr48226.c
===================================================================
--- gcc/testsuite/gcc.target/powerpc/pr48226.c	(revision 0)
+++ gcc/testsuite/gcc.target/powerpc/pr48226.c	(revision 0)
@@ -0,0 +1,14 @@ 
+/* { dg-do compile } */
+/* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-O3 -mcpu=power7" } */
+
+/* The bug shows up if you compile with -maltivec or -mcpu=power7, due to one
+   of the vector's being eliminated due to rs6000_macro_to_expand being called
+   recursively.  */
+
+struct vector {
+  float v[4];
+};
+
+struct vector vector = { 1.0, 2.0, 3.0, 4.0 };
Index: gcc/config/rs6000/rs6000-c.c
===================================================================
--- gcc/config/rs6000/rs6000-c.c	(revision 171246)
+++ gcc/config/rs6000/rs6000-c.c	(working copy)
@@ -182,7 +182,10 @@  rs6000_macro_to_expand (cpp_reader *pfil
 	  expand_this = C_CPP_HASHNODE (__vector_keyword);
 	  expand_bool_pixel = __bool_keyword;
 	}
-      else if (ident)
+      /* The boost libraries have code with Iterator::vector vector in it.  If
+	 we allow the normal handling, this module will be called recursively,
+	 and the vector will be skipped.; */
+      else if (ident && (ident != C_CPP_HASHNODE (__vector_keyword)))
 	{
 	  enum rid rid_code = (enum rid)(ident->rid_code);
 	  if (ident->type == NT_MACRO)