Messages in this thread | | | From | David Laight <> | Subject | RE: [PATCH] x86/fpu: use __alignof__ to avoid UB in TYPE_ALIGN | Date | Tue, 27 Sep 2022 08:20:39 +0000 |
| |
From: YingChi Long > Sent: 26 September 2022 14:18 > > Seems GCC __alignof__ is not evaluated to the minimum alignment of some > TYPE, and depends on fields of the struct. > > > Notably I think 'long long' has 4 byte alignment on i386 and some other > > 32bit archs. > > C11 _Alignof matches in the case (see godbolt link below). How about > switch to _Alignof?
__alignof__() returns the preferred alignment, not the minimal one. So one i386 it returns 8 for 'long long' rather than 4.
Using alignof(struct{long long x;}) does give the required 4. (as does _Alignof()).
See https://godbolt.org/z/13xTYYd11
David
- Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
| |