diff mbox series

[4/6] m4: Define alignof_slot using _Alignof when using C11 or newer

Message ID 20230115185153.2277534-4-raj.khem@gmail.com
State Accepted, archived
Commit 6ab48834cfe852f7bc9a0fe412ff80de216f8247
Headers show
Series [1/6] libxcb: Fixed c2x standard undefined behaviour | expand

Commit Message

Khem Raj Jan. 15, 2023, 6:51 p.m. UTC
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 meta/recipes-devtools/m4/m4-1.4.19.inc        |  1 +
 ...lot-using-_Alignof-when-using-C11-or.patch | 49 +++++++++++++++++++
 2 files changed, 50 insertions(+)
 create mode 100644 meta/recipes-devtools/m4/m4/0001-Define-alignof_slot-using-_Alignof-when-using-C11-or.patch
diff mbox series

Patch

diff --git a/meta/recipes-devtools/m4/m4-1.4.19.inc b/meta/recipes-devtools/m4/m4-1.4.19.inc
index 6ee9742277..c098a4077e 100644
--- a/meta/recipes-devtools/m4/m4-1.4.19.inc
+++ b/meta/recipes-devtools/m4/m4-1.4.19.inc
@@ -9,6 +9,7 @@  inherit autotools texinfo ptest gettext
 SRC_URI = "${GNU_MIRROR}/m4/m4-${PV}.tar.gz \
            file://ac_config_links.patch \
            file://0001-sigsegv-Fix-build-on-ppc-musl.patch \
+           file://0001-Define-alignof_slot-using-_Alignof-when-using-C11-or.patch \
            "
 SRC_URI:append:class-target = " file://run-ptest \
                                 file://serial-tests-config.patch \
diff --git a/meta/recipes-devtools/m4/m4/0001-Define-alignof_slot-using-_Alignof-when-using-C11-or.patch b/meta/recipes-devtools/m4/m4/0001-Define-alignof_slot-using-_Alignof-when-using-C11-or.patch
new file mode 100644
index 0000000000..8757abd7a0
--- /dev/null
+++ b/meta/recipes-devtools/m4/m4/0001-Define-alignof_slot-using-_Alignof-when-using-C11-or.patch
@@ -0,0 +1,49 @@ 
+From b0fd3a58354b1f5ead891907979dfd3dd36840d5 Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Sat, 14 Jan 2023 14:55:03 -0800
+Subject: [PATCH] Define alignof_slot using _Alignof when using C11 or newer
+
+WG14 N2350 made very clear that it is an UB having type definitions
+within "offsetof" [1]. This patch enhances the implementation of macro
+alignof_slot to use builtin "_Alignof" to avoid undefined behavior on
+when using std=c11 or newer
+
+clang 16+ has started to flag this [2]
+
+Fixes build when using -std >= gnu11 and using clang16+ [3]
+
+[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm
+[2] https://reviews.llvm.org/D133574
+[3] https://public-inbox.org/bug-gnulib/20230114232744.215167-1-raj.khem@gmail.com/T/#u
+
+Upstream-Status: Backport [https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=2d404c7dd974cc65f894526f4a1b76bc1dcd8d82]
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ lib/alignof.h | 2 ++
+ 1 file changed, 2 insertions(+)
+
+--- a/lib/alignof.h
++++ b/lib/alignof.h
+@@ -18,19 +18,19 @@
+ #define _ALIGNOF_H
+ 
+ #include <stddef.h>
++#include "stdalign.h"
+ 
+ /* alignof_slot (TYPE)
+    Determine the alignment of a structure slot (field) of a given type,
+    at compile time.  Note that the result depends on the ABI.
+-   This is the same as alignof (TYPE) and _Alignof (TYPE), defined in
+-   <stdalign.h> if __alignof_is_defined is 1.
++   This is the same as alignof (TYPE).
+    Note: The result cannot be used as a value for an 'enum' constant,
+    due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
+ #if defined __cplusplus
+   template <class type> struct alignof_helper { char __slot1; type __slot2; };
+ # define alignof_slot(type) offsetof (alignof_helper<type>, __slot2)
+ #else
+-# define alignof_slot(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
++# define alignof_slot(type) alignof (type)
+ #endif
+ 
+ /* alignof_type (TYPE)