]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[libc] Make static_assert() available via assert.h
authorMichael Brown <mcb30@ipxe.org>
Tue, 16 Jan 2024 12:23:02 +0000 (12:23 +0000)
committerMichael Brown <mcb30@ipxe.org>
Tue, 16 Jan 2024 13:35:08 +0000 (13:35 +0000)
Expose static_assert() via assert.h and migrate link-time assertions
to build-time assertions where possible.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/drivers/infiniband/arbel.c
src/drivers/infiniband/hermon.c
src/image/script.c
src/include/assert.h
src/net/aoe.c

index 293c1b64743ea546395ada7b2db91140384d4dbb..24c0b53b0905e7b264df42ebffda9e0b829c5208 100644 (file)
@@ -545,8 +545,8 @@ static int arbel_mad ( struct ib_device *ibdev, union ib_mad *mad ) {
        union arbelprm_mad mad_ifc;
        int rc;
 
-       linker_assert ( sizeof ( *mad ) == sizeof ( mad_ifc.mad ),
-                       mad_size_mismatch );
+       /* Sanity check */
+       static_assert ( sizeof ( *mad ) == sizeof ( mad_ifc.mad ) );
 
        /* Copy in request packet */
        memcpy ( &mad_ifc.mad, mad, sizeof ( mad_ifc.mad ) );
index c09baf7aeb38ef1c7802a0fb9f058e642d9c6782..6fc7d8bd40dd083164fe94128a1a2a2a862d36d4 100644 (file)
@@ -779,8 +779,8 @@ static int hermon_mad ( struct ib_device *ibdev, union ib_mad *mad ) {
        union hermonprm_mad mad_ifc;
        int rc;
 
-       linker_assert ( sizeof ( *mad ) == sizeof ( mad_ifc.mad ),
-                       mad_size_mismatch );
+       /* Sanity check */
+       static_assert ( sizeof ( *mad ) == sizeof ( mad_ifc.mad ) );
 
        /* Copy in request packet */
        memcpy ( &mad_ifc.mad, mad, sizeof ( mad_ifc.mad ) );
index 49b356403a5eed09bed584f968eb6c9457d52407..9e8566bc5f90c26055f3cb393fb0bf0c090fd104 100644 (file)
@@ -219,8 +219,7 @@ static int script_exec ( struct image *image ) {
 static int script_probe ( struct image *image ) {
        static const char ipxe_magic[] = "#!ipxe";
        static const char gpxe_magic[] = "#!gpxe";
-       linker_assert ( sizeof ( ipxe_magic ) == sizeof ( gpxe_magic ),
-                       magic_size_mismatch );
+       static_assert ( sizeof ( ipxe_magic ) == sizeof ( gpxe_magic ) );
        char test[ sizeof ( ipxe_magic ) - 1 /* NUL */
                   + 1 /* terminating space */];
 
index dd71fa7137c3fbbb5139424b82b4d52c04e54b31..6d0531801f89d9eb32dfcc3a01baea6822d4c540 100644 (file)
@@ -55,6 +55,15 @@ assert_printf ( const char *fmt, ... ) asm ( "printf" );
                }                                                            \
        } while ( 0 )
 
+/**
+ * Assert a condition at build time
+ *
+ * If the compiler cannot prove that the condition is true, the build
+ * will fail with an error message.
+ */
+#undef static_assert
+#define static_assert(x) _Static_assert( x, #x )
+
 /**
  * Assert a condition at link-time.
  *
index e785e8979afcc6249d097a35f3d7b7d703e3d117..dba4f51b5890043f332a346fe822618b6af97299 100644 (file)
@@ -374,7 +374,7 @@ static void aoecmd_ata_cmd ( struct aoe_command *aoecmd,
        struct aoeata *aoeata = &aoehdr->payload[0].ata;
 
        /* Sanity check */
-       linker_assert ( AOE_FL_DEV_HEAD == ATA_DEV_SLAVE, __fix_ata_h__ );
+       static_assert ( AOE_FL_DEV_HEAD == ATA_DEV_SLAVE );
        assert ( len == ( sizeof ( *aoehdr ) + sizeof ( *aoeata ) +
                          command->data_out_len ) );