From 052ed480a62812eddf517b1f233aaab629b8deb6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 14 Dec 2022 09:31:28 +0100 Subject: [PATCH] platform: fix "-Wcast-align" warning on i686 in nmp_object_ref() With gcc-12.2.1-4.fc37 on i686 we get: ./src/libnm-platform/nmp-object.h: In function 'nmp_object_ref': ./src/libnm-platform/nmp-object.h:626:12: error: cast increases required alignment of target type [-Werror=cast-align] 626 | return (const NMPObject *) nm_dedup_multi_obj_ref((const NMDedupMultiObj *) obj); | ^ cc1: all warnings being treated as errors Work around that be increasing the alignment of NMDedupMultiObj. It has no downsides, because we usually put a NMDedupMultiObj in heap allocated memory, which is already suitably aligned. Or we put it on the stack, where wasting a few bytes for the alignment doesn't matter. We basically never embed NMDedupMultiObj in an array where the increase of alignment would waste additional space. --- src/libnm-glib-aux/nm-dedup-multi.h | 4 +++- src/libnm-platform/nmp-object.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libnm-glib-aux/nm-dedup-multi.h b/src/libnm-glib-aux/nm-dedup-multi.h index 09b4a11e63..87a2b81583 100644 --- a/src/libnm-glib-aux/nm-dedup-multi.h +++ b/src/libnm-glib-aux/nm-dedup-multi.h @@ -37,6 +37,8 @@ typedef enum _NMDedupMultiIdxMode { /*****************************************************************************/ +#define _NMDedupMultiObj_Align (MAX(_nm_alignof(void *), _nm_alignof(gint64))) + struct _NMDedupMultiObj { union { NMObjBaseInst parent; @@ -44,7 +46,7 @@ struct _NMDedupMultiObj { }; NMDedupMultiIndex *_multi_idx; guint _ref_count; -}; +} _nm_align(_NMDedupMultiObj_Align); struct _NMDedupMultiObjClass { NMObjBaseClass parent; diff --git a/src/libnm-platform/nmp-object.h b/src/libnm-platform/nmp-object.h index 5f98deeda4..4901ebcba3 100644 --- a/src/libnm-platform/nmp-object.h +++ b/src/libnm-platform/nmp-object.h @@ -427,7 +427,7 @@ struct _NMPObject { NMPlatformMptcpAddr mptcp_addr; NMPObjectMptcpAddr _mptcp_addr; }; -}; +} _nm_alignas(NMDedupMultiObj); /*****************************************************************************/