use _Alignof to avoid UB in ALIGNOF
WG14 N2350 clearly says that it is an UB having type definitions within "offsetof" [1]. Clang 16+ has started diagnosing it [2]. This patch changes the implementation of macro "ALIGNOF" to builtin "_Alignof" to avoid undefined behavior. _Alignof() return the ABI required minimum alignment. [1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm [2] https://reviews.llvm.org/D133574 Signed-off-by: Khem Raj <raj.khem@gmail.com>
This commit is contained in:
parent
3333d5bde8
commit
6fec74429f
|
@ -288,7 +288,6 @@ def c_open(self):
|
||||||
_c('#include "%s.h"', _ns.header)
|
_c('#include "%s.h"', _ns.header)
|
||||||
|
|
||||||
_c('')
|
_c('')
|
||||||
_c('#define ALIGNOF(type) offsetof(struct { char dummy; type member; }, member)')
|
|
||||||
|
|
||||||
if _ns.is_ext:
|
if _ns.is_ext:
|
||||||
for (n, h) in self.direct_imports:
|
for (n, h) in self.direct_imports:
|
||||||
|
@ -1266,7 +1265,7 @@ def _c_serialize_helper_fields(context, self,
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
code_lines.append(
|
code_lines.append(
|
||||||
'%s xcb_align_to = ALIGNOF(%s);'
|
'%s xcb_align_to = _Alignof(%s);'
|
||||||
% (space,
|
% (space,
|
||||||
'char'
|
'char'
|
||||||
if field.c_field_type == 'void' or field.type.is_switch
|
if field.c_field_type == 'void' or field.type.is_switch
|
||||||
|
|
Loading…
Reference in New Issue