[PATCH] OFFSET_TYPE and vector_size attribute (PR c++/34914)

Jakub Jelinek jakub@redhat.com
Tue Jan 22 17:19:00 GMT 2008


Hi!

As shown on the testcase, g++ ATM parses
__attribute__((vector_size (8))) int A::* p;
as vector of OFFSET_TYPE elements, which doesn't match documentation
(OFFSET_TYPE is really not an integral type or floating scalar type).

Attached are two alternative patches, one rejects it, the other (suggested
by Andrew) instead handles it similarly to pointers, arrays etc., so
the vector_size applies to the inner type and this is a pointer to data
member with int vector type.  The first was just briefly tested, the latter
patch has been bootstrapped/regtested on x86_64-linux.

Ok for trunk (which one)?

	Jakub
-------------- next part --------------
2008-01-22  Jakub Jelinek  <jakub@redhat.com>

	PR c++/34914
	* c-common.c (handle_vector_size_attribute): Only allow
	integral, scalar float and fixed point types.

	* g++.dg/ext/vector10.C: New test.

--- gcc/c-common.c.jj	2008-01-04 19:08:18.000000000 +0100
+++ gcc/c-common.c	2008-01-22 11:35:57.000000000 +0100
@@ -6037,9 +6037,9 @@ handle_vector_size_attribute (tree *node
   /* Get the mode of the type being modified.  */
   orig_mode = TYPE_MODE (type);
 
-  if (TREE_CODE (type) == RECORD_TYPE
-      || TREE_CODE (type) == UNION_TYPE
-      || TREE_CODE (type) == VECTOR_TYPE
+  if ((!INTEGRAL_TYPE_P (type)
+       && !SCALAR_FLOAT_TYPE_P (type)
+       && !FIXED_POINT_TYPE_P (type))
       || (!SCALAR_FLOAT_MODE_P (orig_mode)
 	  && GET_MODE_CLASS (orig_mode) != MODE_INT
 	  && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode))
--- gcc/testsuite/g++.dg/ext/vector10.C.jj	2008-01-22 11:42:02.000000000 +0100
+++ gcc/testsuite/g++.dg/ext/vector10.C	2008-01-22 11:34:55.000000000 +0100
@@ -0,0 +1,11 @@
+// PR c++/34914
+// { dg-do compile }
+
+struct A { int x; };
+
+void
+foo ()
+{
+  int A::*p __attribute ((vector_size (8)));	// { dg-error "invalid vector type for attribute" }
+  p == 0;
+}
-------------- next part --------------
2008-01-22  Jakub Jelinek  <jakub@redhat.com>

	PR c++/34914
	* c-common.c (handle_vector_size_attribute): Only allow
	integral, scalar float and fixed point types.  Handle OFFSET_TYPE
	the same way as pointer, array etc. types.
	* tree.c (reconstruct_complex_type): Handle OFFSET_TYPE.

	* g++.dg/ext/vector10.C: New test.

--- gcc/c-common.c.jj	2008-01-04 19:08:18.000000000 +0100
+++ gcc/c-common.c	2008-01-22 13:16:54.000000000 +0100
@@ -6031,15 +6031,16 @@ handle_vector_size_attribute (tree *node
   while (POINTER_TYPE_P (type)
 	 || TREE_CODE (type) == FUNCTION_TYPE
 	 || TREE_CODE (type) == METHOD_TYPE
-	 || TREE_CODE (type) == ARRAY_TYPE)
+	 || TREE_CODE (type) == ARRAY_TYPE
+	 || TREE_CODE (type) == OFFSET_TYPE)
     type = TREE_TYPE (type);
 
   /* Get the mode of the type being modified.  */
   orig_mode = TYPE_MODE (type);
 
-  if (TREE_CODE (type) == RECORD_TYPE
-      || TREE_CODE (type) == UNION_TYPE
-      || TREE_CODE (type) == VECTOR_TYPE
+  if ((!INTEGRAL_TYPE_P (type)
+       && !SCALAR_FLOAT_TYPE_P (type)
+       && !FIXED_POINT_TYPE_P (type))
       || (!SCALAR_FLOAT_MODE_P (orig_mode)
 	  && GET_MODE_CLASS (orig_mode) != MODE_INT
 	  && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode))
--- gcc/tree.c.jj	2008-01-22 10:46:20.000000000 +0100
+++ gcc/tree.c	2008-01-22 13:19:09.000000000 +0100
@@ -7631,6 +7631,11 @@ reconstruct_complex_type (tree type, tre
 	     inner,
 	     TREE_CHAIN (TYPE_ARG_TYPES (type)));
     }
+  else if (TREE_CODE (type) == OFFSET_TYPE)
+    {
+      inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
+      outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
+    }
   else
     return bottom;
 
--- gcc/testsuite/g++.dg/ext/vector10.C.jj	2008-01-22 11:42:02.000000000 +0100
+++ gcc/testsuite/g++.dg/ext/vector10.C	2008-01-22 13:45:25.000000000 +0100
@@ -0,0 +1,11 @@
+// PR c++/34914
+// { dg-do compile }
+
+struct A { int __attribute ((vector_size (8))) x; };
+
+void
+foo ()
+{
+  __attribute ((vector_size (8))) int A::*p;
+  p == 0;
+}


More information about the Gcc-patches mailing list