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]

patch: MODE attribute (was Re: altivec very broken)


the following code does not work because the mode attribute is broken. 
the mode attribute is currently working on decls not types:
    
    int __attribute__((mode(V4SI))) x, y;
    
    __builtin_altivec_vadduwm (x, y);
    
gcc gets confused and x and y end up being ints, not V4SI's.
    
however, this works:

	typedef int __attribute__((mode((V4SI))) vecint;
	vecint x, y;
	__builtin_altivec_vadduwm (x, y);

when i implemented the vector_size attribute, i noticed mode() was
working on decls, not types.  i should've fixed it then.

here is a patch.

also: the mode attribute was also calling layout_decl.  i removed this
because decl_attributes (the caller) already re-lays the decl thanks to
my previous patch to attribs.c.

i have included an altivec test, but if anyone can come up with a non
altivec way of triggering this, let me know.  it would be nice to have a
generic test, not a ppc one.  be that as it may, it's still broken.

i'm running 2 sets of tests for other patches now, so my testing tree is
unusable.  i'll test tommorrow.

ok to install provided no regressions?

2001-12-09  Aldy Hernandez  <aldyh@redhat.com>

	* gcc.dg/altivec-4.c: New.

	* attribs.c (c_common_attribute_table): Swap decl_req and type_req
	for the mode attribute.
	(handle_mode_attribute): Handle types, not decls.

Index: attribs.c
===================================================================
RCS file: /cvs/uberbaum/gcc/attribs.c,v
retrieving revision 1.6
diff -c -p -r1.6 attribs.c
*** attribs.c	2001/12/07 18:49:16	1.6
--- attribs.c	2001/12/10 05:04:04
*************** static const struct attribute_spec c_com
*** 120,126 ****
  			      handle_constructor_attribute },
    { "destructor",             0, 0, true,  false, false,
  			      handle_destructor_attribute },
!   { "mode",                   1, 1, true,  false, false,
  			      handle_mode_attribute },
    { "section",                1, 1, true,  false, false,
  			      handle_section_attribute },
--- 120,126 ----
  			      handle_constructor_attribute },
    { "destructor",             0, 0, true,  false, false,
  			      handle_destructor_attribute },
!   { "mode",                   1, 1, false,  true, false,
  			      handle_mode_attribute },
    { "section",                1, 1, true,  false, false,
  			      handle_section_attribute },
*************** handle_mode_attribute (node, name, args,
*** 761,768 ****
       int flags ATTRIBUTE_UNUSED;
       bool *no_add_attrs;
  {
!   tree decl = *node;
!   tree type = TREE_TYPE (decl);
  
    *no_add_attrs = true;
  
--- 761,767 ----
       int flags ATTRIBUTE_UNUSED;
       bool *no_add_attrs;
  {
!   tree type = *node;
  
    *no_add_attrs = true;
  
*************** handle_mode_attribute (node, name, args,
*** 786,792 ****
  	  p = newp;
  	}
  
!       /* Give this decl a type with the specified mode.
  	 First check for the special modes.  */
        if (! strcmp (p, "byte"))
  	mode = byte_mode;
--- 785,791 ----
  	  p = newp;
  	}
  
!       /* Change this type to have a type with the specified mode.
  	 First check for the special modes.  */
        if (! strcmp (p, "byte"))
  	mode = byte_mode;
*************** handle_mode_attribute (node, name, args,
*** 805,816 ****
  					     TREE_UNSIGNED (type))))
  	error ("no data type for mode `%s'", p);
        else
! 	{
! 	  TREE_TYPE (decl) = type = typefm;
! 	  DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = 0;
! 	  if (TREE_CODE (decl) != FIELD_DECL)
! 	    layout_decl (decl, 0);
! 	}
      }
  
    return NULL_TREE;
--- 804,811 ----
  					     TREE_UNSIGNED (type))))
  	error ("no data type for mode `%s'", p);
        else
! 	*node = typefm;
!         /* No need to layout the type here.  The caller should do this.  */
      }
  
    return NULL_TREE;
Index: testsuite/gcc.dg/altivec-4.c
===================================================================
RCS file: altivec-4.c
diff -N altivec-4.c
*** /dev/null	Tue May  5 13:32:27 1998
--- altivec-4.c	Sun Dec  9 21:04:04 2001
***************
*** 0 ****
--- 1,10 ----
+ /* { dg-do compile { target powerpc-*-* } } */
+ /* { dg-options "-maltivec -O0 -Wall" } */
+ 
+ int __attribute__((mode(V4SI))) x, y;
+ 
+ void
+ b()
+ {
+   __builtin_altivec_vadduwm (x, y);
+ }


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