qcow2: Silence clang -m32 compiler warning
PATCH 1/1 qcow2: Silence clang -m32 compiler warning
With -m32, size_t is generally only a uint32_t. That makes clang complain that in the assertion
assert(qiov->size <= INT64_MAX);
the range of the type of qiov->size (size_t) is too small for any of its values to ever exceed INT64_MAX.
Cast qiov->size to uint64_t to silence clang.
("block: use int64_t instead of uint64_t in driver read handlers")
---
I don't know whether this is the best possible solution, or whether we should care about this at all (I personally think it's basically just wrong for clang to warn about always-true conditions in assertions), but I thought I might as well just send this patch as the basis for a discussion.
--- block/qcow2-cluster.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
block/qcow2-cluster.c +2 -1
@@ -513,7 +513,8 @@ static int coroutine_fn do_perform_cow_read(BlockDriverState *bs,*/ assert (src_cluster_offset <=INT64_MAX );assert (src_cluster_offset + offset_in_cluster <=INT64_MAX ); -assert (qiov->size <=INT64_MAX ); +/* Cast qiov->size to uint64_t to silence a compiler warning on -m32 */ +assert ((uint64_t )qiov->size <=INT64_MAX );bdrv_check_qiov_request (src_cluster_offset + offset_in_cluster, qiov->size, qiov,0 , &error_abort);/*
Signature · 1 line
2.31.1
Quoted 7 lines · Hanna Reitz
With -m32,
size_tis generally only auint32_t. That makes clang complain that in the assertionassert(qiov->size <= INT64_MAX);the range of the type of
qiov->size(size_t) is too small for any of its values to ever exceedINT64_MAX.
Yep, I'm not surprised that we hit that.
Quoted 6 lines
Cast
qiov->sizetouint64_tto silence clang.Fixes f7ef38dd1310d7d9db76d0aa16899cbc5744f36d("block: use
int64_tinstead ofuint64_tin driver read handlers")
Quoted 7 lines
Signed-off-by Hanna Reitz <[email protected]>---
I don't know whether this is the best possible solution, or whether we should care about this at all (I personally think it's basically just wrong for clang to warn about always-true conditions in assertions), but I thought I might as well just send this patch as the basis for a discussion.
I agree that the compiler is overly noisy, but the fix is simple enough that I'm fine with it as written.
Since the original went through my tree, I'm happy to take this one through my NBD tree as well.
Quoted 21 lines
--- block/qcow2-cluster.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)block/qcow2-cluster.c +2
-1@@ -513,7 +513,8 @@ static int coroutine_fn do_perform_cow_read(BlockDriverState *bs,*/ assert (src_cluster_offset <=INT64_MAX );assert (src_cluster_offset + offset_in_cluster <=INT64_MAX ); -assert (qiov->size <=INT64_MAX ); +/* Cast qiov->size to uint64_t to silence a compiler warning on -m32 */ +assert ((uint64_t )qiov->size <=INT64_MAX );bdrv_check_qiov_request (src_cluster_offset + offset_in_cluster, qiov->size, qiov,0 , &error_abort);/* Signature · 1 line
2.31.1
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Quoted 22 lines · Eric Blake
Quoted 7 lines · Hanna Reitz
With -m32,
size_tis generally only auint32_t. That makes clang complain that in the assertionassert(qiov->size <= INT64_MAX);the range of the type of
qiov->size(size_t) is too small for any of its values to ever exceedINT64_MAX.Yep, I'm not surprised that we hit that.
Quoted 5 lines
Cast
qiov->sizetouint64_tto silence clang.Fixes f7ef38dd1310d7d9db76d0aa16899cbc5744f36d("block: use
int64_tinstead ofuint64_tin driver read handlers")Quoted 7 lines
Signed-off-by Hanna Reitz <[email protected]>---
I don't know whether this is the best possible solution, or whether we should care about this at all (I personally think it's basically just wrong for clang to warn about always-true conditions in assertions), but I thought I might as well just send this patch as the basis for a discussion.
Quoted 2 lines
I agree that the compiler is overly noisy, but the fix is simple enough that I'm fine with it as written.
Well, I just hope clang won’t become even more clever in the future and realize the cast has no real effect...
Quoted 4 lines
Reviewed-by Eric Blake <[email protected]>Since the original went through my tree, I'm happy to take this one through my NBD tree as well.
Thanks!
Hanna