--- gcc/objc/encoding.c 2018/04/24 18:13:39 1.1 +++ gcc/objc/encoding.c 2018/04/24 18:26:49 1.1.1.3 @@ -1,7 +1,6 @@ /* Encoding of types for Objective C. - Copyright (C) 1993 Free Software Foundation, Inc. - -Author: Kresten Krab Thorup + Copyright (C) 1993, 1995 Free Software Foundation, Inc. + Contributed by Kresten Krab Thorup This file is part of GNU CC. @@ -17,7 +16,8 @@ GNU General Public License for more deta You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ /* As a special exception, if you link this library with files compiled with GCC to produce an executable, this does not cause @@ -35,6 +35,10 @@ the Free Software Foundation, 675 Mass A ({ typeof(X) __x = (X), __y = (Y); \ (__x < __y ? __x : __y); }) +#define ROUND(V, A) \ + ({ typeof(V) __v=(V); typeof(A) __a=(A); \ + __a*((__v+__a-1)/__a); }) + static inline int atoi (const char* str) @@ -60,7 +64,7 @@ objc_sizeof_type(const char* type) break; case _C_CLASS: - return sizeof(Class*); + return sizeof(Class); break; case _C_SEL: @@ -99,6 +103,14 @@ objc_sizeof_type(const char* type) return sizeof(unsigned long); break; + case _C_FLT: + return sizeof(float); + break; + + case _C_DBL: + return sizeof(double); + break; + case _C_PTR: case _C_ATOM: case _C_CHARPTR: @@ -118,11 +130,10 @@ objc_sizeof_type(const char* type) int acc_size = 0; int align; while (*type != _C_STRUCT_E && *type++ != '='); /* skip "=" */ - while (*type != _C_STRUCT_E); + while (*type != _C_STRUCT_E) { align = objc_alignof_type (type); /* padd to alignment */ - if ((acc_size % align) != 0) - acc_size += align - (acc_size % align); + acc_size = ROUND (acc_size, align); acc_size += objc_sizeof_type (type); /* add component size */ type = objc_skip_typespec (type); /* skip component */ } @@ -160,7 +171,7 @@ objc_alignof_type(const char* type) break; case _C_CLASS: - return __alignof__(Class*); + return __alignof__(Class); break; case _C_SEL: @@ -199,6 +210,14 @@ objc_alignof_type(const char* type) return __alignof__(unsigned long); break; + case _C_FLT: + return __alignof__(float); + break; + + case _C_DBL: + return __alignof__(double); + break; + case _C_ATOM: case _C_CHARPTR: return __alignof__(char*); @@ -244,11 +263,7 @@ objc_aligned_size (const char* type) { int size = objc_sizeof_type (type); int align = objc_alignof_type (type); - - if ((size % align) != 0) - return size + align - (size % align); - else - return size; + return ROUND (size, align); } /* @@ -262,15 +277,12 @@ objc_promoted_size (const char* type) int size = objc_sizeof_type (type); int wordsize = sizeof (void*); - if ((size % wordsize) != 0) - return size + wordsize - (size % wordsize); - else - return size; + return ROUND (size, wordsize); } /* Skip type qualifiers. These may eventually precede typespecs - occuring in method prototype encodings. + occurring in method prototype encodings. */ inline const char*