From patchwork Fri Mar 18 23:26:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Meissner X-Patchwork-Id: 87590 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 35B32B6F2B for ; Sat, 19 Mar 2011 10:27:19 +1100 (EST) Received: (qmail 28264 invoked by alias); 18 Mar 2011 23:27:17 -0000 Received: (qmail 28255 invoked by uid 22791); 18 Mar 2011 23:27:16 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL, BAYES_00, NO_DNS_FOR_FROM, TW_FN, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from e3.ny.us.ibm.com (HELO e3.ny.us.ibm.com) (32.97.182.143) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 18 Mar 2011 23:27:01 +0000 Received: from d01dlp01.pok.ibm.com (d01dlp01.pok.ibm.com [9.56.224.56]) by e3.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p2IN6Yeg003773 for ; Fri, 18 Mar 2011 19:06:34 -0400 Received: from d01relay05.pok.ibm.com (d01relay05.pok.ibm.com [9.56.227.237]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 20BF338C8038 for ; Fri, 18 Mar 2011 19:26:55 -0400 (EDT) Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay05.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p2INQxM2231560 for ; Fri, 18 Mar 2011 19:26:59 -0400 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p2INQwh5020313 for ; Fri, 18 Mar 2011 20:26:58 -0300 Received: from hungry-tiger.westford.ibm.com (dyn9033037078.westford.ibm.com [9.33.37.78]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p2INQwAn020308; Fri, 18 Mar 2011 20:26:58 -0300 Received: by hungry-tiger.westford.ibm.com (Postfix, from userid 500) id B7E75F7BB7; Fri, 18 Mar 2011 19:26:57 -0400 (EDT) Date: Fri, 18 Mar 2011 19:26:57 -0400 From: Michael Meissner To: gcc-patches@gcc.gnu.org, dje.gcc@gmail.com, uweigand@de.ibm.com, jakub@redhat.com, tromey@redhat.com, joseph@codesourcery.com, rth@redhat.com, jason@redhat.com, mark@codesourcery.com, nathan@codesourcery.com Subject: [PATCH, 4.7] PR 48192, Make conditional macros not defined for #ifdef Message-ID: <20110318232657.GA11627@hungry-tiger.westford.ibm.com> Mail-Followup-To: Michael Meissner , gcc-patches@gcc.gnu.org, dje.gcc@gmail.com, uweigand@de.ibm.com, jakub@redhat.com, tromey@redhat.com, joseph@codesourcery.com, rth@redhat.com, jason@redhat.com, mark@codesourcery.com, nathan@codesourcery.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 makes conditional macros that are used in the PowerPC and SPU ports not be 'defined' for the #ifdef, #ifndef, and #if defined(...) tests. The way the PowerPC and SPU uses conditional macros is provide conditional keywords to support the vector systen (i.e. if the next token after vector is not bool, pixel, or a standard type, the vector macro is not expanded). Some users have run into this when compiling for Power7, which enables the Altivec support by default in code fragments like: #ifndef bool #define bool char #endif On the powerpc if you compile with -mcpu=power7, the #ifndef test does not succeed, because 'bool' is defined as a macro, it never defines bool to be char and a syntax error will come up. I bootstraped 4.7 and tested that the 3 PowerPC conditional macros are not defined. Is this ok to install in 4.7? I would like to backport this to 4.6, 4.5 and maybe 4.4. Are there objections to backporting it? [libcpp] 2011-03-18 Michael Meissner PR preprocessor/48192 * directives.c (do_ifdef): Do not consider conditional macros as being defined. (do_ifndef): Ditto. * expr.c (parse_defined): Ditto. [gcc/testsuite] 2011-03-18 Michael Meissner PR preprocessor/48192 * gcc.target/powerpc/pr48192.c: New file. Index: libcpp/directives.c =================================================================== --- libcpp/directives.c (revision 171162) +++ libcpp/directives.c (working copy) @@ -1819,7 +1819,12 @@ do_ifdef (cpp_reader *pfile) if (node) { - skip = node->type != NT_MACRO; + /* Do not treat conditional macros as being defined. This is due to + the powerpc and spu ports using conditional macros for 'vector', + 'bool', and 'pixel' to act as conditional keywords. This messes + up tests like #ifndef bool. */ + skip = (node->type != NT_MACRO + || ((node->flags & NODE_CONDITIONAL) != 0)); _cpp_mark_macro_used (node); if (!(node->flags & NODE_USED)) { @@ -1860,7 +1865,12 @@ do_ifndef (cpp_reader *pfile) if (node) { - skip = node->type == NT_MACRO; + /* Do not treat conditional macros as being defined. This is due to + the powerpc and spu ports using conditional macros for 'vector', + 'bool', and 'pixel' to act as conditional keywords. This messes + up tests like #ifndef bool. */ + skip = (node->type == NT_MACRO + && ((node->flags & NODE_CONDITIONAL) == 0)); _cpp_mark_macro_used (node); if (!(node->flags & NODE_USED)) { Index: libcpp/expr.c =================================================================== --- libcpp/expr.c (revision 171162) +++ libcpp/expr.c (working copy) @@ -720,10 +720,15 @@ parse_defined (cpp_reader *pfile) pfile->state.prevent_expansion--; + /* Do not treat conditional macros as being defined. This is due to the + powerpc and spu ports using conditional macros for 'vector', 'bool', and + 'pixel' to act as conditional keywords. This messes up tests like #ifndef + bool. */ result.unsignedp = false; result.high = 0; result.overflow = false; - result.low = node && node->type == NT_MACRO; + result.low = (node && node->type == NT_MACRO + && (node->flags & NODE_CONDITIONAL) == 0); return result; } Index: gcc/testsuite/gcc.target/powerpc/pr48192.c =================================================================== --- gcc/testsuite/gcc.target/powerpc/pr48182.c (revision 0) +++ gcc/testsuite/gcc.target/powerpc/pr48182.c (revision 0) @@ -0,0 +1,49 @@ +/* { dg-do compile } */ +/* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */ +/* { dg-require-effective-target powerpc_vsx_ok } */ +/* { dg-options "-O3 -mcpu=power7 -std=gnu89" } */ + +/* Make sure that the conditional macros vector, bool, and pixel are not + considered as being defined. */ + +#ifdef bool +#error "bool is considered defined" +#endif + +#ifdef vector +#error "vector is considered defined" +#endif + +#ifdef pixel +#error "pixel is condsidered defined" +#endif + +#if defined(bool) +#error "bool is considered defined" +#endif + +#if defined(vector) +#error "vector is considered defined" +#endif + +#if defined(pixel) +#error "pixel is condsidered defined" +#endif + +#ifndef bool +#else +#error "bool is considered defined" +#endif + +#ifndef vector +#else +#error "vector is considered defined" +#endif + +#ifndef pixel +#else +#error "pixel is condsidered defined" +#endif + +#define bool long double +bool pixel = 0;