diff options
author | Philip Withnall <withnall@endlessm.com> | 2018-12-21 13:09:57 +0000 |
---|---|---|
committer | Philip Withnall <withnall@endlessm.com> | 2018-12-21 13:09:57 +0000 |
commit | b7d2eeed17c0db62b8f034b453c22cfceae2ae23 (patch) | |
tree | 6188cb46945785b3b368e4e303f7f1b806a9df16 /glib | |
parent | ea0da960ab2f57a95ba61eef5b0e0c64ad38d484 (diff) | |
download | glib-b7d2eeed17c0db62b8f034b453c22cfceae2ae23.tar.gz |
gmacros: Don’t use __alignof__ in G_ALIGNOF implementation
It has different semantics from _Alignof and our G_STRUCT_OFFSET
fallback. See the comments in the diff for details.
Signed-off-by: Philip Withnall <withnall@endlessm.com>
https://gitlab.gnome.org/GNOME/glib/issues/1055
Diffstat (limited to 'glib')
-rw-r--r-- | glib/docs.c | 7 | ||||
-rw-r--r-- | glib/gmacros.h | 6 |
2 files changed, 10 insertions, 3 deletions
diff --git a/glib/docs.c b/glib/docs.c index 30f6e6a56..9e5269236 100644 --- a/glib/docs.c +++ b/glib/docs.c @@ -1870,11 +1870,16 @@ * G_ALIGNOF * @a: a type-name * - * Return the minimum alignment required by the platform ABI for values of the given + * Return the minimal alignment required by the platform ABI for values of the given * type. The address of a variable or struct member of the given type must always be * a multiple of this alignment. For example, most platforms require int variables * to be aligned at a 4-byte boundary, so `G_ALIGNOF (int)` is 4 on most platforms. * + * Note this is not necessarily the same as the value returned by GCC’s + * `__alignof__` operator, which returns the preferred alignment for a type. + * The preferred alignment may be a stricter alignment than the minimal + * alignment. + * * Since: 2.60 */ diff --git a/glib/gmacros.h b/glib/gmacros.h index f8db7e83b..2f3d84746 100644 --- a/glib/gmacros.h +++ b/glib/gmacros.h @@ -406,12 +406,14 @@ #endif /* Provide G_ALIGNOF alignment macro. + * + * Note we cannot use the gcc __alignof__ operator here, as that returns the + * preferred alignment rather than the minimal alignment. See + * https://gitlab.gnome.org/GNOME/glib/merge_requests/538/diffs#note_390790. */ #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__cplusplus) #define G_ALIGNOF(type) _Alignof (type) -#elif defined(__GNUC__) -#define G_ALIGNOF(type) (__alignof__ (type)) #else #define G_ALIGNOF(type) (G_STRUCT_OFFSET (struct { char a; type b; }, b)) #endif |