1*c5535c91SAndrew GeisslerFrom d55b6b1fa87700f3eae3a29522972d2e7be7d53e Mon Sep 17 00:00:00 2001 2*c5535c91SAndrew GeisslerFrom: Khem Raj <raj.khem@gmail.com> 3*c5535c91SAndrew GeisslerDate: Sat, 14 Jan 2023 10:11:35 -0800 4*c5535c91SAndrew GeisslerSubject: [PATCH] use _Alignof to avoid UB in ALIGNOF 5*c5535c91SAndrew Geissler 6*c5535c91SAndrew GeisslerWG14 N2350 clearly says that it is an UB having type definitions 7*c5535c91SAndrew Geisslerwithin "offsetof" [1]. Clang 16+ has started diagnosing it [2]. 8*c5535c91SAndrew GeisslerThis patch changes the implementation of macro 9*c5535c91SAndrew Geissler"ALIGNOF" to builtin "_Alignof" to avoid undefined behavior. 10*c5535c91SAndrew Geissler 11*c5535c91SAndrew Geissler_Alignof() return the ABI required minimum alignment. 12*c5535c91SAndrew Geissler 13*c5535c91SAndrew Geissler[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm 14*c5535c91SAndrew Geissler[2] https://reviews.llvm.org/D133574 15*c5535c91SAndrew Geissler 16*c5535c91SAndrew GeisslerUpstream-Status: Submitted [https://gitlab.freedesktop.org/xorg/lib/libxcb/-/merge_requests/42] 17*c5535c91SAndrew GeisslerSigned-off-by: Khem Raj <raj.khem@gmail.com> 18*c5535c91SAndrew Geissler--- 19*c5535c91SAndrew Geissler src/c_client.py | 3 +-- 20*c5535c91SAndrew Geissler 1 file changed, 1 insertion(+), 2 deletions(-) 21*c5535c91SAndrew Geissler 22*c5535c91SAndrew Geisslerdiff --git a/src/c_client.py b/src/c_client.py 23*c5535c91SAndrew Geisslerindex fd256f0..4e48f13 100644 24*c5535c91SAndrew Geissler--- a/src/c_client.py 25*c5535c91SAndrew Geissler+++ b/src/c_client.py 26*c5535c91SAndrew Geissler@@ -288,7 +288,6 @@ def c_open(self): 27*c5535c91SAndrew Geissler _c('#include "%s.h"', _ns.header) 28*c5535c91SAndrew Geissler 29*c5535c91SAndrew Geissler _c('') 30*c5535c91SAndrew Geissler- _c('#define ALIGNOF(type) offsetof(struct { char dummy; type member; }, member)') 31*c5535c91SAndrew Geissler 32*c5535c91SAndrew Geissler if _ns.is_ext: 33*c5535c91SAndrew Geissler for (n, h) in self.direct_imports: 34*c5535c91SAndrew Geissler@@ -1266,7 +1265,7 @@ def _c_serialize_helper_fields(context, self, 35*c5535c91SAndrew Geissler count += 1 36*c5535c91SAndrew Geissler 37*c5535c91SAndrew Geissler code_lines.append( 38*c5535c91SAndrew Geissler- '%s xcb_align_to = ALIGNOF(%s);' 39*c5535c91SAndrew Geissler+ '%s xcb_align_to = _Alignof(%s);' 40*c5535c91SAndrew Geissler % (space, 41*c5535c91SAndrew Geissler 'char' 42*c5535c91SAndrew Geissler if field.c_field_type == 'void' or field.type.is_switch 43*c5535c91SAndrew Geissler-- 44*c5535c91SAndrew Geissler2.39.0 45*c5535c91SAndrew Geissler 46