arehbein has submitted this change. (
https://gerrit.osmocom.org/c/libosmo-netif/+/34445?usp=email )
Change subject: ipa: Don't break strict aliasing rule
......................................................................
ipa: Don't break strict aliasing rule
Somehow gcc doesn't always warn about this rule being broken.
We are breaking the strict aliasing rule here and libosmo-netif
currently does not make use of the '-fno-strict-aliasing' flag.
It's possible that this has also been causing nondeterministic
timestamps in libosmo-netif stream tests every once in a while.
Related: OS#6164, OS#5753
Change-Id: Ibed543cdfcdda8c0256ce7d8818ff96d6d46e9b0
---
M include/osmocom/netif/ipa.h
1 file changed, 30 insertions(+), 1 deletion(-)
Approvals:
pespin: Looks good to me, approved
laforge: Looks good to me, but someone else must approve
Jenkins Builder: Verified
diff --git a/include/osmocom/netif/ipa.h b/include/osmocom/netif/ipa.h
index 1923253..7826895 100644
--- a/include/osmocom/netif/ipa.h
+++ b/include/osmocom/netif/ipa.h
@@ -23,7 +23,19 @@
uint8_t proto_ext;
} __attribute__ ((packed));
-#define OSMO_IPA_MSGB_CB(__msg) ((struct osmo_ipa_msgb_cb *)&((__msg)->cb[0]))
+
+/* We don't just cast to 'struct osmo_ipa_msgb_cb *', because that would
+ * break the strict aliasing rule. Casting to a reference to a union with
+ * a compatible struct member seems to be allowed, though, see:
+ * N1570 Committee Draft — April 12, 2011 ISO/IEC 9899:201x,
+ * Section 6.5, §7 */
+#define OSMO_IPA_MSGB_CB(__msg) (&((( \
+ union { \
+ unsigned long cb; \
+ struct osmo_ipa_msgb_cb _cb; \
+ } \
+ *)&((__msg)->cb[0]))->_cb))
+
#define osmo_ipa_msgb_cb_proto(__x) OSMO_IPA_MSGB_CB(__x)->proto
#define osmo_ipa_msgb_cb_proto_ext(__x) OSMO_IPA_MSGB_CB(__x)->proto_ext
--
To view, visit
https://gerrit.osmocom.org/c/libosmo-netif/+/34445?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: Ibed543cdfcdda8c0256ce7d8818ff96d6d46e9b0
Gerrit-Change-Number: 34445
Gerrit-PatchSet: 7
Gerrit-Owner: arehbein <arehbein(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: arehbein <arehbein(a)sysmocom.de>
Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de>
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged