[PATCH] Allow vector bool even after #include <stdbool.h>

Jakub Jelinek jakub@redhat.com
Tue May 5 06:29:00 GMT 2009


Hi!

#include <stdbool.h>
#include <altivec.h>

vector bool int a;

doesn't work anymore with GCC 4.4+.  While in C++ bool is a keyword
and thus there are no such issues, stdbool.h (as mandated by ISO C++)
defines bool to _Bool and therefore vector isn't expanded to __vector.
I'd say it is desirable to make ISO C99 code use stdbool.h bool types
and altivec vector bool.  The disadvantage is that also explicit
vector _Bool int a;
is accepted, but I'd say it is worth it.

The following patch implements it, bootstrapped/regtested on powerpc64-linux
(regtested both -m32 and -m64), ok for trunk/4.4?

2009-05-05  Jakub Jelinek  <jakub@redhat.com>

	PR target/40017
	* config/rs6000/rs6000-c.c (_Bool_keyword): New variable.
	(altivec_categorize_keyword, init_vector_keywords,
	rs6000_cpu_cpp_builtins): Define _Bool as conditional macro
	similar to bool.

	* gcc.target/powerpc/altivec-types-1.c: Don't expect error for
	__vector _Bool.
	* gcc.target/powerpc/altivec-30.c: New test.
	* gcc.target/powerpc/altivec-31.c: New test.

--- gcc/config/rs6000/rs6000-c.c.jj	2009-05-04 21:46:12.537836926 +0200
+++ gcc/config/rs6000/rs6000-c.c	2009-05-04 21:51:59.205837205 +0200
@@ -91,6 +91,7 @@ static GTY(()) tree __pixel_keyword;
 static GTY(()) tree pixel_keyword;
 static GTY(()) tree __bool_keyword;
 static GTY(()) tree bool_keyword;
+static GTY(()) tree _Bool_keyword;
 
 /* Preserved across calls.  */
 static tree expand_bool_pixel;
@@ -111,6 +112,9 @@ altivec_categorize_keyword (const cpp_to
       if (ident == C_CPP_HASHNODE (bool_keyword))
 	return C_CPP_HASHNODE (__bool_keyword);
 
+      if (ident == C_CPP_HASHNODE (_Bool_keyword))
+	return C_CPP_HASHNODE (__bool_keyword);
+
       return ident;
     }
 
@@ -141,6 +145,9 @@ init_vector_keywords (void)
 
   bool_keyword = get_identifier ("bool");
   C_CPP_HASHNODE (bool_keyword)->flags |= NODE_CONDITIONAL;
+
+  _Bool_keyword = get_identifier ("_Bool");
+  C_CPP_HASHNODE (_Bool_keyword)->flags |= NODE_CONDITIONAL;
 }
 
 /* Called to decide whether a conditional macro should be expanded.
@@ -295,6 +302,7 @@ rs6000_cpu_cpp_builtins (cpp_reader *pfi
 	  builtin_define ("vector=vector");
 	  builtin_define ("pixel=pixel");
 	  builtin_define ("bool=bool");
+	  builtin_define ("_Bool=_Bool");
 	  init_vector_keywords ();
 
 	  /* Enable context-sensitive macros.  */
--- gcc/testsuite/gcc.target/powerpc/altivec-types-1.c.jj	2009-05-04 21:41:23.000000000 +0200
+++ gcc/testsuite/gcc.target/powerpc/altivec-types-1.c	2009-05-05 08:06:36.045597859 +0200
@@ -24,6 +24,7 @@ __vector unsigned vuj;
 __vector signed vsj;
 __vector __bool vbj;
 __vector float vf;
+__vector _Bool vb;
 
 /* These should be rejected as invalid AltiVec types.  */
 
@@ -37,7 +38,6 @@ __vector signed long long int vslli;	/* 
 __vector __bool long long int vblli;	/* { dg-error "AltiVec types" "" } */
 __vector double vd1;			/* { dg-error "AltiVec types" "" } */
 __vector long double vld;		/* { dg-error "AltiVec types" "" } */
-__vector _Bool vb;			/* { dg-error "AltiVec types" "" } */
 __vector _Complex float vcf;		/* { dg-error "AltiVec types" "" } */
 __vector _Complex double vcd;		/* { dg-error "AltiVec types" "" } */
 __vector _Complex long double vcld;	/* { dg-error "AltiVec types" "" } */
--- gcc/testsuite/gcc.target/powerpc/altivec-30.c.jj	2009-05-04 21:51:59.206835660 +0200
+++ gcc/testsuite/gcc.target/powerpc/altivec-30.c	2009-05-05 08:08:20.816832745 +0200
@@ -0,0 +1,32 @@
+/* { dg-do compile { target powerpc*-*-* } } */
+/* { dg-require-effective-target powerpc_altivec_ok } */
+/* { dg-options "-maltivec" } */
+
+#include <stdbool.h>
+#include <altivec.h>
+
+#define f0(type) void x0##type (vector bool type x) { }
+f0 (int)
+
+#define f1(v, type) void x1##type (v bool type x) { }
+f1 (vector, int)
+
+#define f2(b, type) void x2##type (vector b type x) { }
+f2 (bool, int)
+
+#define f3(v, b, type) void x3##type (v b type x) { }
+f3 (vector, bool, int)
+
+#define f4(v, b, type) void x4##type (v type b x) { }
+f4 (vector, bool, int)
+
+#define B bool
+#define I int
+#define BI bool int
+#define VBI vector bool int
+
+vector bool int a;
+vector B int b;
+vector B I c;
+vector BI d;
+VBI e;
--- gcc/testsuite/gcc.target/powerpc/altivec-31.c.jj	2009-05-04 21:51:59.207834115 +0200
+++ gcc/testsuite/gcc.target/powerpc/altivec-31.c	2009-05-05 08:08:39.445987612 +0200
@@ -0,0 +1,29 @@
+/* { dg-do compile { target powerpc*-*-* } } */
+/* { dg-require-effective-target powerpc_altivec_ok } */
+/* { dg-options "-maltivec" } */
+
+#define f0(type) void x0##type (vector _Bool type x) { }
+f0 (int)
+
+#define f1(v, type) void x1##type (v _Bool type x) { }
+f1 (vector, int)
+
+#define f2(b, type) void x2##type (vector b type x) { }
+f2 (_Bool, int)
+
+#define f3(v, b, type) void x3##type (v b type x) { }
+f3 (vector, _Bool, int)
+
+#define f4(v, b, type) void x4##type (v type b x) { }
+f4 (vector, _Bool, int)
+
+#define B _Bool
+#define I int
+#define BI _Bool int
+#define VBI vector _Bool int
+
+vector _Bool int a;
+vector B int b;
+vector B I c;
+vector BI d;
+VBI e;

	Jakub



More information about the Gcc-patches mailing list