arehbein submitted this change.
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(-)
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 change 34445. To unsubscribe, or for help writing mail filters, visit settings.