Replace *CTASSERT() with _Static_assert()

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #12993
This commit is contained in:
наб 2022-01-21 18:01:55 +01:00 committed by Brian Behlendorf
parent 7ada752a93
commit c70bb2f610
11 changed files with 72 additions and 66 deletions

View File

@ -1228,9 +1228,9 @@ dump_bpobj(objset_t *os, uint64_t object, void *data, size_t size)
char bytes[32], comp[32], uncomp[32];
/* make sure the output won't get truncated */
CTASSERT(sizeof (bytes) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (comp) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (uncomp) >= NN_NUMBUF_SZ);
_Static_assert(sizeof (bytes) >= NN_NUMBUF_SZ, "bytes truncated");
_Static_assert(sizeof (comp) >= NN_NUMBUF_SZ, "comp truncated");
_Static_assert(sizeof (uncomp) >= NN_NUMBUF_SZ, "uncomp truncated");
if (bpop == NULL)
return;
@ -1655,7 +1655,7 @@ dump_metaslab_stats(metaslab_t *msp)
int free_pct = range_tree_space(rt) * 100 / msp->ms_size;
/* max sure nicenum has enough space */
CTASSERT(sizeof (maxbuf) >= NN_NUMBUF_SZ);
_Static_assert(sizeof (maxbuf) >= NN_NUMBUF_SZ, "maxbuf truncated");
zdb_nicenum(metaslab_largest_allocatable(msp), maxbuf, sizeof (maxbuf));
@ -2490,7 +2490,7 @@ dump_dsl_dir(objset_t *os, uint64_t object, void *data, size_t size)
char nice[32];
/* make sure nicenum has enough space */
CTASSERT(sizeof (nice) >= NN_NUMBUF_SZ);
_Static_assert(sizeof (nice) >= NN_NUMBUF_SZ, "nice truncated");
if (dd == NULL)
return;
@ -2548,10 +2548,12 @@ dump_dsl_dataset(objset_t *os, uint64_t object, void *data, size_t size)
char blkbuf[BP_SPRINTF_LEN];
/* make sure nicenum has enough space */
CTASSERT(sizeof (used) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (compressed) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (uncompressed) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (unique) >= NN_NUMBUF_SZ);
_Static_assert(sizeof (used) >= NN_NUMBUF_SZ, "used truncated");
_Static_assert(sizeof (compressed) >= NN_NUMBUF_SZ,
"compressed truncated");
_Static_assert(sizeof (uncompressed) >= NN_NUMBUF_SZ,
"uncompressed truncated");
_Static_assert(sizeof (unique) >= NN_NUMBUF_SZ, "unique truncated");
if (ds == NULL)
return;
@ -2622,7 +2624,7 @@ dump_bptree(objset_t *os, uint64_t obj, const char *name)
dmu_buf_t *db;
/* make sure nicenum has enough space */
CTASSERT(sizeof (bytes) >= NN_NUMBUF_SZ);
_Static_assert(sizeof (bytes) >= NN_NUMBUF_SZ, "bytes truncated");
if (dump_opt['d'] < 3)
return;
@ -2663,9 +2665,9 @@ dump_full_bpobj(bpobj_t *bpo, const char *name, int indent)
uint64_t i;
/* make sure nicenum has enough space */
CTASSERT(sizeof (bytes) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (comp) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (uncomp) >= NN_NUMBUF_SZ);
_Static_assert(sizeof (bytes) >= NN_NUMBUF_SZ, "bytes truncated");
_Static_assert(sizeof (comp) >= NN_NUMBUF_SZ, "comp truncated");
_Static_assert(sizeof (uncomp) >= NN_NUMBUF_SZ, "uncomp truncated");
if (dump_opt['d'] < 3)
return;
@ -2941,10 +2943,10 @@ dump_blkptr_list(dsl_deadlist_t *dl, char *name)
}
/* make sure nicenum has enough space */
CTASSERT(sizeof (bytes) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (comp) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (uncomp) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (entries) >= NN_NUMBUF_SZ);
_Static_assert(sizeof (bytes) >= NN_NUMBUF_SZ, "bytes truncated");
_Static_assert(sizeof (comp) >= NN_NUMBUF_SZ, "comp truncated");
_Static_assert(sizeof (uncomp) >= NN_NUMBUF_SZ, "uncomp truncated");
_Static_assert(sizeof (entries) >= NN_NUMBUF_SZ, "entries truncated");
if (dump_opt['d'] < 3)
return;
@ -3428,11 +3430,12 @@ dump_object(objset_t *os, uint64_t object, int verbosity,
int error;
/* make sure nicenum has enough space */
CTASSERT(sizeof (iblk) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (dblk) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (lsize) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (asize) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (bonus_size) >= NN_NUMBUF_SZ);
_Static_assert(sizeof (iblk) >= NN_NUMBUF_SZ, "iblk truncated");
_Static_assert(sizeof (dblk) >= NN_NUMBUF_SZ, "dblk truncated");
_Static_assert(sizeof (lsize) >= NN_NUMBUF_SZ, "lsize truncated");
_Static_assert(sizeof (asize) >= NN_NUMBUF_SZ, "asize truncated");
_Static_assert(sizeof (bonus_size) >= NN_NUMBUF_SZ,
"bonus_size truncated");
if (*print_header) {
(void) printf("\n%10s %3s %5s %5s %5s %6s %5s %6s %s\n",
@ -3581,7 +3584,8 @@ dump_object(objset_t *os, uint64_t object, int verbosity,
for (;;) {
char segsize[32];
/* make sure nicenum has enough space */
CTASSERT(sizeof (segsize) >= NN_NUMBUF_SZ);
_Static_assert(sizeof (segsize) >= NN_NUMBUF_SZ,
"segsize truncated");
error = dnode_next_offset(dn,
0, &start, minlvl, blkfill, 0);
if (error)
@ -3770,7 +3774,7 @@ dump_objset(objset_t *os)
uint64_t flags;
/* make sure nicenum has enough space */
CTASSERT(sizeof (numbuf) >= NN_NUMBUF_SZ);
_Static_assert(sizeof (numbuf) >= NN_NUMBUF_SZ, "numbuf truncated");
dsl_pool_config_enter(dmu_objset_pool(os), FTAG);
dmu_objset_fast_stat(os, &dds);
@ -5542,7 +5546,7 @@ zdb_blkptr_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
(zcb->zcb_totalasize - bytes) / 1024 / kb_per_sec;
/* make sure nicenum has enough space */
CTASSERT(sizeof (buf) >= NN_NUMBUF_SZ);
_Static_assert(sizeof (buf) >= NN_NUMBUF_SZ, "buf truncated");
zfs_nicebytes(bytes, buf, sizeof (buf));
(void) fprintf(stderr,
@ -6651,12 +6655,18 @@ dump_block_stats(spa_t *spa)
const char *typename;
/* make sure nicenum has enough space */
CTASSERT(sizeof (csize) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (lsize) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (psize) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (asize) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (avg) >= NN_NUMBUF_SZ);
CTASSERT(sizeof (gang) >= NN_NUMBUF_SZ);
_Static_assert(sizeof (csize) >= NN_NUMBUF_SZ,
"csize truncated");
_Static_assert(sizeof (lsize) >= NN_NUMBUF_SZ,
"lsize truncated");
_Static_assert(sizeof (psize) >= NN_NUMBUF_SZ,
"psize truncated");
_Static_assert(sizeof (asize) >= NN_NUMBUF_SZ,
"asize truncated");
_Static_assert(sizeof (avg) >= NN_NUMBUF_SZ,
"avg truncated");
_Static_assert(sizeof (gang) >= NN_NUMBUF_SZ,
"gang truncated");
if (t < DMU_OT_NUMTYPES)
typename = dmu_ot[t].ot_name;

View File

@ -125,7 +125,6 @@ void spl_dumpstack(void);
"failed (0 == %lld)\n", \
(long long) (_verify3_right)); \
} while (0)
#define CTASSERT_GLOBAL(x) CTASSERT(x)
/*
* Debugging disabled (--disable-debug)

View File

@ -109,8 +109,9 @@ enum scope_prefix_types {
* dmu_prefetch_max
*/
#define ZFS_MODULE_PARAM(scope_prefix, name_prefix, name, type, perm, desc) \
CTASSERT_GLOBAL( \
sizeof (scope_prefix) == sizeof (enum scope_prefix_types)); \
_Static_assert( \
sizeof (scope_prefix) == sizeof (enum scope_prefix_types), \
"" #scope_prefix " size mismatch with enum scope_prefix_types"); \
module_param(name_prefix ## name, type, perm); \
MODULE_PARM_DESC(name_prefix ## name, desc)
@ -138,8 +139,9 @@ enum scope_prefix_types {
*/
#define ZFS_MODULE_PARAM_CALL( \
scope_prefix, name_prefix, name, setfunc, getfunc, perm, desc) \
CTASSERT_GLOBAL( \
sizeof (scope_prefix) == sizeof (enum scope_prefix_types)); \
_Static_assert( \
sizeof (scope_prefix) == sizeof (enum scope_prefix_types), \
"" #scope_prefix " size mismatch with enum scope_prefix_types"); \
module_param_call(name_prefix ## name, setfunc, getfunc, \
&name_prefix ## name, perm); \
MODULE_PARM_DESC(name_prefix ## name, desc)
@ -150,8 +152,9 @@ enum scope_prefix_types {
*/
#define ZFS_MODULE_VIRTUAL_PARAM_CALL( \
scope_prefix, name_prefix, name, setfunc, getfunc, perm, desc) \
CTASSERT_GLOBAL(\
sizeof (scope_prefix) == sizeof (enum scope_prefix_types)); \
_Static_assert( \
sizeof (scope_prefix) == sizeof (enum scope_prefix_types), \
"" #scope_prefix " size mismatch with enum scope_prefix_types"); \
module_param_call(name_prefix ## name, setfunc, getfunc, NULL, perm); \
MODULE_PARM_DESC(name_prefix ## name, desc)

View File

@ -120,13 +120,6 @@ void spl_dumpstack(void);
(long long) (_verify3_right)); \
} while (0)
#define CTASSERT_GLOBAL(x) _CTASSERT(x, __LINE__)
#define CTASSERT(x) { _CTASSERT(x, __LINE__); }
#define _CTASSERT(x, y) __CTASSERT(x, y)
#define __CTASSERT(x, y) \
typedef char __attribute__((unused)) \
__compile_time_assertion__ ## y[(x) ? 1 : -1]
/*
* Debugging disabled (--disable-debug)
*/

View File

@ -250,7 +250,8 @@ typedef struct l2arc_dev_hdr_phys {
const uint64_t dh_pad[30]; /* pad to 512 bytes */
zio_eck_t dh_tail;
} l2arc_dev_hdr_phys_t;
CTASSERT_GLOBAL(sizeof (l2arc_dev_hdr_phys_t) == SPA_MINBLOCKSIZE);
_Static_assert(sizeof (l2arc_dev_hdr_phys_t) == SPA_MINBLOCKSIZE,
"l2arc_dev_hdr_phys_t wrong size");
/*
* A single ARC buffer header entry in a l2arc_log_blk_phys_t.
@ -307,10 +308,12 @@ typedef struct l2arc_log_blk_phys {
* The size of l2arc_log_blk_phys_t has to be power-of-2 aligned with
* SPA_MINBLOCKSHIFT because of L2BLK_SET_*SIZE macros.
*/
CTASSERT_GLOBAL(IS_P2ALIGNED(sizeof (l2arc_log_blk_phys_t),
1ULL << SPA_MINBLOCKSHIFT));
CTASSERT_GLOBAL(sizeof (l2arc_log_blk_phys_t) >= SPA_MINBLOCKSIZE);
CTASSERT_GLOBAL(sizeof (l2arc_log_blk_phys_t) <= SPA_MAXBLOCKSIZE);
_Static_assert(IS_P2ALIGNED(sizeof (l2arc_log_blk_phys_t),
1ULL << SPA_MINBLOCKSHIFT), "l2arc_log_blk_phys_t misaligned");
_Static_assert(sizeof (l2arc_log_blk_phys_t) >= SPA_MINBLOCKSIZE,
"l2arc_log_blk_phys_t too small");
_Static_assert(sizeof (l2arc_log_blk_phys_t) <= SPA_MAXBLOCKSIZE,
"l2arc_log_blk_phys_t too big");
/*
* These structures hold in-flight abd buffers for log blocks as they're being

View File

@ -521,8 +521,8 @@ typedef struct vdev_boot_envblock {
sizeof (zio_eck_t)];
zio_eck_t vbe_zbt;
} vdev_boot_envblock_t;
CTASSERT_GLOBAL(sizeof (vdev_boot_envblock_t) == VDEV_PAD_SIZE);
_Static_assert(sizeof (vdev_boot_envblock_t) == VDEV_PAD_SIZE,
"vdev_boot_envblock_t wrong size");
typedef struct vdev_label {
char vl_pad1[VDEV_PAD_SIZE]; /* 8K */

View File

@ -111,14 +111,6 @@ do { \
#undef assert
#endif
/* Compile time assert */
#define CTASSERT_GLOBAL(x) _CTASSERT(x, __LINE__)
#define CTASSERT(x) { _CTASSERT(x, __LINE__); }
#define _CTASSERT(x, y) __CTASSERT(x, y)
#define __CTASSERT(x, y) \
typedef char __attribute__((unused)) \
__compile_time_assertion__ ## y[(x) ? 1 : -1]
#ifdef NDEBUG
#define ASSERT3B(x, y, z) \
((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z)))

View File

@ -685,7 +685,8 @@ zfsctl_root_readdir(struct vop_readdir_args *ap)
if (zfs_uio_offset(&uio) != dots_offset)
return (SET_ERROR(EINVAL));
CTASSERT(sizeof (node->snapdir->sn_name) <= sizeof (entry.d_name));
_Static_assert(sizeof (node->snapdir->sn_name) <= sizeof (entry.d_name),
"node->snapdir->sn_name too big for entry.d_name");
entry.d_fileno = node->snapdir->sn_id;
entry.d_type = DT_DIR;
strcpy(entry.d_name, node->snapdir->sn_name);

View File

@ -1777,8 +1777,10 @@ zfs_checkexp(vfs_t *vfsp, struct sockaddr *nam, int *extflagsp,
credanonp, numsecflavors, secflavors));
}
CTASSERT(SHORT_FID_LEN <= sizeof (struct fid));
CTASSERT(LONG_FID_LEN <= sizeof (struct fid));
_Static_assert(sizeof (struct fid) >= SHORT_FID_LEN,
"struct fid bigger than SHORT_FID_LEN");
_Static_assert(sizeof (struct fid) >= LONG_FID_LEN,
"struct fid bigger than LONG_FID_LEN");
static int
zfs_fhtovp(vfs_t *vfsp, fid_t *fidp, int flags, vnode_t **vpp)

View File

@ -3937,8 +3937,10 @@ zfs_inactive(vnode_t *vp, cred_t *cr, caller_context_t *ct)
}
CTASSERT(sizeof (struct zfid_short) <= sizeof (struct fid));
CTASSERT(sizeof (struct zfid_long) <= sizeof (struct fid));
_Static_assert(sizeof (struct zfid_short) <= sizeof (struct fid),
"struct zfid_short bigger than struct fid");
_Static_assert(sizeof (struct zfid_long) <= sizeof (struct fid),
"struct zfid_long bigger than struct fid");
/*ARGSUSED*/
static int

View File

@ -89,7 +89,8 @@ abd_checksum_edonr_tmpl_init(const zio_cksum_salt_t *salt)
* size by double-hashing it (the new salt block will be composed of
* H(salt) || H(H(salt))).
*/
CTASSERT(EDONR_BLOCK_SIZE == 2 * (EDONR_MODE / 8));
_Static_assert(EDONR_BLOCK_SIZE == 2 * (EDONR_MODE / 8),
"Edon-R block size mismatch");
EdonRHash(EDONR_MODE, salt->zcs_bytes, sizeof (salt->zcs_bytes) * 8,
salt_block);
EdonRHash(EDONR_MODE, salt_block, EDONR_MODE, salt_block +