File s390-tools-sles15sp2-18-lib-zt_common-add-STATIC_ASSERT-macro.patch of Package s390-tools.17667

Subject: [PATCH] [FEAT VS1804] lib/zt_common: add STATIC_ASSERT macro
From: Marc Hartmayer <mhartmay@linux.ibm.com>

Summary:     genprotimg: Introduce new tool for the creation of PV images
Description: genprotimg takes a kernel, host-key documents, optionally an
             initrd, optionally a file with the kernel command line, and it
             generates a single, loadable image file. The image consists of a
             concatenation of a plain text boot loader, the encrypted
             components for kernel, initrd, and cmdline, and the
             integrity-protected PV header, containing metadata necessary for
             running the guest in PV mode. It's possible to use this image file
             as a kernel for zIPL or for a direct kernel boot using QEMU.
Upstream-ID: bac3f93772bdf8618c2c9677c59569d70e4a39c0
Problem-ID:  VS1804

Upstream-Description:

             lib/zt_common: add STATIC_ASSERT macro

             Add `STATIC_ASSERT` macro that uses `_Static_assert` if available (was
             introduced with gcc 4.6, see https://gcc.gnu.org/wiki/C11Status). For
             example, this could be used for the verification of structure sizes at
             compile time.

             Acked-by: Jan Höppner <hoeppner@linux.ibm.com>
             Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
             Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>


Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
---
 include/lib/zt_common.h |    7 +++++++
 1 file changed, 7 insertions(+)

--- a/include/lib/zt_common.h
+++ b/include/lib/zt_common.h
@@ -22,6 +22,13 @@
 # define UNUSED(x) x
 #endif
 
+#ifdef STATIC_ASSERT
+#elif defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ >= 5)
+# define STATIC_ASSERT(test) _Static_assert((test), "(" #test ") failed");
+#else
+# define STATIC_ASSERT(test)
+#endif
+
 #define RELEASE_STRING	STRINGIFY (S390_TOOLS_RELEASE)
 #define TOOLS_LIBDIR	STRINGIFY (S390_TOOLS_LIBDIR)
 #define TOOLS_SYSCONFDIR STRINGIFY (S390_TOOLS_SYSCONFDIR)
openSUSE Build Service is sponsored by