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: Make C11 _Alignof return least not greatest alignment for a type (PR c/52023)


On Thu, Dec 05, 2013 at 12:22:22PM +0100, Andreas Schwab wrote:
> "Joseph S. Myers" <joseph@codesourcery.com> writes:
> 
> > @@ -4994,6 +4997,22 @@ c_sizeof_or_alignof_type (location_t loc,
> >  	value = size_binop_loc (loc, CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
> >  				size_int (TYPE_PRECISION (char_type_node)
> >  					  / BITS_PER_UNIT));
> > +      else if (min_alignof)
> > +	{
> > +	  unsigned int align = TYPE_ALIGN (type);
> > +	  align = MIN (align, BIGGEST_ALIGNMENT);
> > +#ifdef BIGGEST_FIELD_ALIGNMENT
> > +	  align = MIN (align, BIGGEST_FIELD_ALIGNMENT);
> > +#endif
> > +	  tree field = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE,
> > +				   type);
> > +	  unsigned int field_align = align;
> > +#ifdef ADJUST_FIELD_ALIGN
> > +	  field_align = ADJUST_FIELD_ALIGN (field, field_align);
> > +#endif
> > +	  align = MIN (align, field_align);
> > +	  value = size_int (align / BITS_PER_UNIT);
> > +	}
> >        else
> >  	value = size_int (TYPE_ALIGN_UNIT (type));
> >      }
> 
> ../../gcc/c-family/c-common.c: In function âtree_node* c_sizeof_or_alignof_type(location_t, tree, bool, bool, int)â:
> ../../gcc/c-family/c-common.c:5007:9: error: unused variable âfieldâ [-Werror=unused-variable]
>     tree field = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE,

The following should fix it.

2013-12-05  Marek Polacek  <polacek@redhat.com>

c-family/
	* c-common.c (c_sizeof_or_alignof_type): Move a declaration into
	[ADJUST_FIELD_ALIGN].

--- gcc/c-family/c-common.c.mp2	2013-12-05 12:35:38.585732312 +0100
+++ gcc/c-family/c-common.c	2013-12-05 12:36:03.351820193 +0100
@@ -5004,10 +5004,10 @@ c_sizeof_or_alignof_type (location_t loc
 #ifdef BIGGEST_FIELD_ALIGNMENT
 	  align = MIN (align, BIGGEST_FIELD_ALIGNMENT);
 #endif
-	  tree field = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE,
-				   type);
 	  unsigned int field_align = align;
 #ifdef ADJUST_FIELD_ALIGN
+	  tree field = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE,
+				   type);
 	  field_align = ADJUST_FIELD_ALIGN (field, field_align);
 #endif
 	  align = MIN (align, field_align);

	Marek


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