From patchwork Mon Mar 21 23:23:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Meissner X-Patchwork-Id: 87849 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id EA259B6F74 for ; Tue, 22 Mar 2011 10:24:21 +1100 (EST) Received: (qmail 13591 invoked by alias); 21 Mar 2011 23:24:13 -0000 Received: (qmail 13510 invoked by uid 22791); 21 Mar 2011 23:24:11 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL, BAYES_00, NO_DNS_FOR_FROM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from e6.ny.us.ibm.com (HELO e6.ny.us.ibm.com) (32.97.182.146) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 21 Mar 2011 23:24:03 +0000 Received: from d01dlp02.pok.ibm.com (d01dlp02.pok.ibm.com [9.56.224.85]) by e6.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p2LMxj7f009853 for ; Mon, 21 Mar 2011 18:59:45 -0400 Received: from d01relay07.pok.ibm.com (d01relay07.pok.ibm.com [9.56.227.147]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 835446E8036 for ; Mon, 21 Mar 2011 19:24:01 -0400 (EDT) Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay07.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p2LNO0F52723916 for ; Mon, 21 Mar 2011 19:24:00 -0400 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p2LNO0s0013291 for ; Mon, 21 Mar 2011 20:24:00 -0300 Received: from hungry-tiger.westford.ibm.com (dyn9033037078.westford.ibm.com [9.33.37.78]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p2LNO0R7013285; Mon, 21 Mar 2011 20:24:00 -0300 Received: by hungry-tiger.westford.ibm.com (Postfix, from userid 500) id 9C75FF7D0E; Mon, 21 Mar 2011 19:23:59 -0400 (EDT) Date: Mon, 21 Mar 2011 19:23:59 -0400 From: Michael Meissner To: gcc-patches@gcc.gnu.org, dje.gcc@gmail.com Subject: [PATCH, 4.7] Fix PR 48226, Allow Iterator::vector vector on powerpc with VSX Message-ID: <20110321232359.GA1378@hungry-tiger.westford.ibm.com> Mail-Followup-To: Michael Meissner , gcc-patches@gcc.gnu.org, dje.gcc@gmail.com MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Content-Scanned: Fidelis XPS MAILER X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 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 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 PR target/48226 * gcc.target/powerpc/pr48226.c: New file. 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)