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]

Patch: __alignof__(void) -> most strict alignment


hi,
This patch changes the (currently unspecified) behaviour of the gcc
extension __alignof__(void). It currently returns 1, this changes it to
return the value BIGGEST_ALIGNMENT / BITS_PER_UNIT, i.e. the most strict
alignment required on the target. Such a value is needed in, for
instance, memory allocators.

It patches both gcc and g++. Two test files (c and c++ are attached).

Feedback (http://www.cygnus.com/ml/egcs/1998-Sep/0468.html) about the
desirability/usefulness of this was mixed. I have, however a partial fix
for the exception handling running out of memory problem
(http://www.cygnus.com/ml/egcs-bugs/1998-Sep/0229.html), which makes use
of this patch. I'll submit that one when
a) this one is installed, or definititely not going to be
b) I've got an FSF copyright assignment sorted out

nathan
-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
      You can up the bandwidth, but you can't up the speed of light      
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk
gcc/ChangeLog

Wed Sep  9 18:07:04 BST 1998  Nathan Sidwell  <nathan@acm.org>

	* c-typeck.c (c_alignof): Return maximum alignment for void type.
	* extend.texi: Document it

gcc/cp/ChangeLog

Wed Sep  9 18:07:04 BST 1998  Nathan Sidwell  <nathan@acm.org>

	* typeck.c (c_alignof): Return maximum alignment for void type.

Index: gcc/extend.texi
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/extend.texi,v
retrieving revision 1.10
diff -b -c -3 -p -r1.10 extend.texi
*** extend.texi	1998/07/06 22:30:12	1.10
--- extend.texi	1998/09/09 17:06:57
*************** Some machines never actually require ali
*** 1766,1771 ****
--- 1766,1774 ----
  data type even at an odd addresses.  For these machines, @code{__alignof__}
  reports the @emph{recommended} alignment of a type.
  
+ When the operand of @code{__alignof__} is void, the maximum alignment for
+ the target is returned.
+ 
  When the operand of @code{__alignof__} is an lvalue rather than a type, the
  value is the largest alignment that the lvalue is known to have.  It may
  have this alignment as a result of its data type, or because it is part of
Index: gcc/c-typeck.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-typeck.c,v
retrieving revision 1.18
diff -b -c -3 -p -r1.18 c-typeck.c
*** c-typeck.c	1998/06/19 22:27:35	1.18
--- c-typeck.c	1998/09/09 17:07:03
*************** c_alignof (type)
*** 907,913 ****
    if (code == FUNCTION_TYPE)
      return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
  
!   if (code == VOID_TYPE || code == ERROR_MARK)
      return size_int (1);
  
    return size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
--- 907,916 ----
    if (code == FUNCTION_TYPE)
      return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
  
!   if (code == VOID_TYPE)
!     return size_int (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
! 
!   if (code == ERROR_MARK)
      return size_int (1);
  
    return size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
Index: gcc/cp/typeck.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/typeck.c,v
retrieving revision 1.86.2.3
diff -b -c -3 -p -r1.86.2.3 typeck.c
*** typeck.c	1998/07/18 11:06:04	1.86.2.3
--- typeck.c	1998/09/09 17:07:11
*************** c_alignof (type)
*** 1557,1563 ****
    if (code == FUNCTION_TYPE || code == METHOD_TYPE)
      return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
  
!   if (code == VOID_TYPE || code == ERROR_MARK)
      return size_int (1);
  
    /* C++: this is really correct!  */
--- 1557,1566 ----
    if (code == FUNCTION_TYPE || code == METHOD_TYPE)
      return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
  
!   if (code == VOID_TYPE)
!     return size_int (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
! 
!   if (code == ERROR_MARK)
      return size_int (1);
  
    /* C++: this is really correct!  */
#include <stdio.h>

int main()
{
  printf("char %d int %d long double %d void %d\n",
    __alignof__(char), __alignof__(int), __alignof__(long double), __alignof__(void));
  return 0;
}
#include <stdio.h>

template<class T> unsigned fn(){return __alignof__(T);};

int main()
{
  printf("char %d int %d void %d\n",
      __alignof__(char), __alignof__(int), __alignof__(void));
  printf("char %d int %d void %d\n",
      fn<char>(), fn<int>(), fn<void>());
  return 0;
}

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