--- gcc/objc/encoding.c 2018/04/24 18:13:39 1.1.1.1 +++ gcc/objc/encoding.c 2018/04/24 18:20:13 1.1.1.2 @@ -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) @@ -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 */ } @@ -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,10 +277,7 @@ 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); } /*