[dpdk-dev,v3,03/24] rte_common.h: cast gcc builtin result to avoid complaints

Message ID 152609033730.121661.15300461327237900961.stgit@localhost.localdomain (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Andy Green May 12, 2018, 1:58 a.m. UTC
  /projects/lagopus/src/dpdk/build/include/rte_common.h:416:9:
warning: conversion to 'uint32_t' {aka 'unsigned int'} from
'int' may change the sign of the result [-Wsign-conversion]
  return __builtin_ctz(v);
         ^~~~~~~~~~~~~~~~

The builtin is defined to return int, but we want to
return it as uint32_t.  Its only defined valid return
values are positive integers or zero, which is OK for
uint32_t.  So just add an explicit cast.

Signed-off-by: Andy Green <andy@warmcat.com>
---
 lib/librte_eal/common/include/rte_common.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Thomas Monjalon May 13, 2018, 8:40 p.m. UTC | #1
12/05/2018 03:58, Andy Green:
> /projects/lagopus/src/dpdk/build/include/rte_common.h:416:9:
> warning: conversion to 'uint32_t' {aka 'unsigned int'} from
> 'int' may change the sign of the result [-Wsign-conversion]
>   return __builtin_ctz(v);
>          ^~~~~~~~~~~~~~~~
> 
> The builtin is defined to return int, but we want to
> return it as uint32_t.  Its only defined valid return
> values are positive integers or zero, which is OK for
> uint32_t.  So just add an explicit cast.

    Fixes: 03f6bced5bba ("eal: use intrinsic function")
    Cc: stable@dpdk.org

> Signed-off-by: Andy Green <andy@warmcat.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index 69e5ed1e3..679f2f184 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -413,7 +413,7 @@  rte_align64prevpow2(uint64_t v)
 static inline uint32_t
 rte_bsf32(uint32_t v)
 {
-	return __builtin_ctz(v);
+	return (uint32_t)__builtin_ctz(v);
 }
 
 /**