This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFA: handling of mode attribute


2009/9/26 Kai Tietz <ktietz70@googlemail.com>:
> Hello,
>
> This patch makes sure, that the attribute mode is getting associated
> with the base type (as described in documentation, too). So the mode
> attribute can be used as type-specifier in code, too (eg ?'int
> __attribute__ ((mode(DI))) value[5];' ).
> The old attribute mode handler has treating of pointer type, but if I
> read documentation I don't find a single word about this. Also I
> searched testsuite and couldn't find any example of this. To allow
> proper association of this attribute, I removed the bogus pointer type
> handling. If this is necessary for some cases I didn't found, we could
> add a special attribute (eg. ptrmode) for handling and checking this.
> The only usecase I found in gcc's source is in vmsdbgout.c:typedef
> struct fibdef* __fibdef_ptr32 __attribute__ (( mode (SI) ));
>
> So my question is, how should we handle this?
> One idea would be to add for the new behavior an new attribute name,
> something like 'base_mode'. The other would be to change this pointer
> type mode, but well it wouldn't be backward compatible any more.
>
> I attached current state of patch, plus a testcase for attribute mode used.
>
> Cheers,
> Kai
>
> --
> | ?(\_/) This is Bunny. Copy and paste
> | (='.'=) Bunny into your signature to help
> | (")_(") him gain world domination
>

In testcase I missed to replace one use of __int64 by attr_int64, so I
resent the patch

Kai

-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination
Index: gcc/gcc/c-common.c
===================================================================
--- gcc.orig/gcc/c-common.c	2009-09-23 18:36:56.000000000 +0200
+++ gcc/gcc/c-common.c	2009-09-26 14:54:58.288577700 +0200
@@ -6360,6 +6360,13 @@
   tree type = *node;
   tree ident = TREE_VALUE (args);
 
+  while (POINTER_TYPE_P (type)
+         || TREE_CODE (type) == FUNCTION_TYPE
+         || TREE_CODE (type) == METHOD_TYPE
+         || TREE_CODE (type) == ARRAY_TYPE
+         || TREE_CODE (type) == OFFSET_TYPE)
+    type = TREE_TYPE (type);
+
   *no_add_attrs = true;
 
   if (TREE_CODE (ident) != IDENTIFIER_NODE)
@@ -6452,37 +6459,18 @@
 	  return NULL_TREE;
 	}
 
-      if (POINTER_TYPE_P (type))
-	{
-	  tree (*fn)(tree, enum machine_mode, bool);
-
-	  if (!targetm.valid_pointer_mode (mode))
-	    {
-	      error ("invalid pointer mode %qs", p);
-	      return NULL_TREE;
-	    }
-
-	  if (TREE_CODE (type) == POINTER_TYPE)
-	    fn = build_pointer_type_for_mode;
-	  else
-	    fn = build_reference_type_for_mode;
-	  typefm = fn (TREE_TYPE (type), mode, false);
-	}
-      else
+      /* For fixed-point modes, we need to test if the signness of type
+	 and the machine mode are consistent.  */
+      if (ALL_FIXED_POINT_MODE_P (mode)
+	  && TYPE_UNSIGNED (type) != UNSIGNED_FIXED_POINT_MODE_P (mode))
 	{
-	  /* For fixed-point modes, we need to test if the signness of type
-	     and the machine mode are consistent.  */
-	  if (ALL_FIXED_POINT_MODE_P (mode)
-	      && TYPE_UNSIGNED (type) != UNSIGNED_FIXED_POINT_MODE_P (mode))
-	    {
-	      error ("signness of type and machine mode %qs don't match", p);
-	      return NULL_TREE;
-	    }
-	  /* For fixed-point modes, we need to pass saturating info.  */
-	  typefm = lang_hooks.types.type_for_mode (mode,
-			ALL_FIXED_POINT_MODE_P (mode) ? TYPE_SATURATING (type)
-						      : TYPE_UNSIGNED (type));
+	  error ("signness of type and machine mode %qs don't match", p);
+	  return NULL_TREE;
 	}
+      /* For fixed-point modes, we need to pass saturating info.  */
+      typefm = lang_hooks.types.type_for_mode (mode,
+	       ALL_FIXED_POINT_MODE_P (mode) ? TYPE_SATURATING (type)
+					     : TYPE_UNSIGNED (type));
 
       if (typefm == NULL_TREE)
 	{
@@ -6527,7 +6515,8 @@
 	  return NULL_TREE;
 	}
 
-      *node = typefm;
+      /* *node = typefm; */
+      *node = lang_hooks.types.reconstruct_complex_type (*node, typefm);
     }
 
   return NULL_TREE;
Index: gcc/gcc/testsuite/gcc.c-torture/execute/attribute_mode.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gcc/gcc/testsuite/gcc.c-torture/execute/attribute_mode.c	2009-09-26 15:47:45.404577700 +0200
@@ -0,0 +1,36 @@
+__extension__ typedef __SIZE_TYPE__ size_t;
+extern void abort (void);
+extern int memcmp (const void *, const void *, size_t);
+
+#define attr_int64 int __attribute__ ((mode(DI)))
+
+attr_int64
+foo (unsigned attr_int64 b)
+{
+  return ((attr_int64) b);
+}
+
+void
+bar (unsigned attr_int64 b[4])
+{
+  b[1]=0LL; b[0]=1LL; b[2]=2LL; b[3]=5LL;
+}
+
+unsigned int tab1[8] = {
+  1, 0, 0, 0, 2, 0, 5, 0
+};
+
+int
+main ()
+{
+  unsigned attr_int64 a[4];
+  if (sizeof (a) != 32)
+    abort ();
+  if (foo (1ULL) != 1LL)
+    abort ();
+  bar (a);
+  if (memcmp (a, tab1, 32) != 0)
+    abort ();
+  return 0;
+}
+

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]