[Bug middle-end/107498] Wrong optimization leads to unaligned access when compiling OpenLDAP

jrtc27 at jrtc27 dot com gcc-bugzilla@gcc.gnu.org
Tue Nov 1 17:04:26 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107498

--- Comment #2 from Jessica Clarke <jrtc27 at jrtc27 dot com> ---
#define mp_lower        mp_pb.pb.pb_lower
#define mp_upper        mp_pb.pb.pb_upper
#define mp_pages        mp_pb.pb_pages
        union {
                struct {
                        indx_t          pb_lower;               /**< lower
bound of free space */
                        indx_t          pb_upper;               /**< upper
bound of free space */
                } pb;
                uint32_t        pb_pages;       /**< number of overflow pages
*/
        } mp_pb;

That's the code. GCC is perfectly ok to optimise that to do a 32-bit load. If
it has an alignment fault that's OpenLDAP's problem, the uint32_t there means
it must be 32-bit aligned if you don't want UB.


More information about the Gcc-bugs mailing list