* [PATCH, 4.7] PR 48192, Make conditional macros not defined for #ifdef
@ 2011-03-18 23:27 Michael Meissner
2011-03-20 20:08 ` Mark Mitchell
0 siblings, 1 reply; 3+ messages in thread
From: Michael Meissner @ 2011-03-18 23:27 UTC (permalink / raw)
To: gcc-patches, dje.gcc, uweigand, jakub, tromey, joseph, rth,
jason, mark, nathan
[-- Attachment #1: Type: text/plain, Size: 1462 bytes --]
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 <meissner@linux.vnet.ibm.com>
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 <meissner@linux.vnet.ibm.com>
PR preprocessor/48192
* gcc.target/powerpc/pr48192.c: New file.
--
Michael Meissner, IBM
5 Technology Place Drive, M/S 2757, Westford, MA 01886-3141, USA
meissner@linux.vnet.ibm.com fax +1 (978) 399-6899
[-- Attachment #2: gcc-power7.patch229b --]
[-- Type: text/plain, Size: 3192 bytes --]
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;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH, 4.7] PR 48192, Make conditional macros not defined for #ifdef
2011-03-18 23:27 [PATCH, 4.7] PR 48192, Make conditional macros not defined for #ifdef Michael Meissner
@ 2011-03-20 20:08 ` Mark Mitchell
2011-03-20 23:36 ` Joseph S. Myers
0 siblings, 1 reply; 3+ messages in thread
From: Mark Mitchell @ 2011-03-20 20:08 UTC (permalink / raw)
To: Michael Meissner, gcc-patches, dje.gcc, uweigand, jakub, tromey,
joseph, rth, jason, nathan
On 3/18/2011 4:26 PM, Michael Meissner wrote:
> 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.
I think that's a desirable change, from a language semantics point of
view, but I would defer to Joseph on this issue; he has a much more
comprehensive understanding of the C preprocessing rules than I do.
> I would like to backport this to 4.6, 4.5 and maybe 4.4. Are there objections
> to backporting it?
I have no objection to a backport.
Thank you,
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH, 4.7] PR 48192, Make conditional macros not defined for #ifdef
2011-03-20 20:08 ` Mark Mitchell
@ 2011-03-20 23:36 ` Joseph S. Myers
0 siblings, 0 replies; 3+ messages in thread
From: Joseph S. Myers @ 2011-03-20 23:36 UTC (permalink / raw)
To: Mark Mitchell
Cc: Michael Meissner, gcc-patches, dje.gcc, uweigand, jakub, tromey,
rth, jason, nathan
On Sun, 20 Mar 2011, Mark Mitchell wrote:
> On 3/18/2011 4:26 PM, Michael Meissner wrote:
>
> > 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.
>
> I think that's a desirable change, from a language semantics point of
> view, but I would defer to Joseph on this issue; he has a much more
> comprehensive understanding of the C preprocessing rules than I do.
The argument for the change makes sense to me (in terms of what code is
likely to do when testing for a macro being defined); this is outside the
scope of the standard in any case.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-03-20 23:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-18 23:27 [PATCH, 4.7] PR 48192, Make conditional macros not defined for #ifdef Michael Meissner
2011-03-20 20:08 ` Mark Mitchell
2011-03-20 23:36 ` Joseph S. Myers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).