eal/stack: fix 'pointer-sign' warning

Message ID 1560531283-5229-1-git-send-email-phil.yang@arm.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series eal/stack: fix 'pointer-sign' warning |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS

Commit Message

Phil Yang June 14, 2019, 4:54 p.m. UTC
  clang raise 'pointer-sign' warnings in __atomic_compare_exchange
when passing 'uint64_t *' to parameter of type 'int64_t *' converts
between pointers to integer types with different sign.

Fixes: 7e6e609939a8 ("stack: add C11 atomic implementation")

Signed-off-by: Phil Yang <phil.yang@arm.com>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>

---
 lib/librte_stack/rte_stack_lf_c11.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Eads, Gage June 14, 2019, 7:49 p.m. UTC | #1
> clang raise 'pointer-sign' warnings in __atomic_compare_exchange when
> passing 'uint64_t *' to parameter of type 'int64_t *' converts between
> pointers to integer types with different sign.
> 
> Fixes: 7e6e609939a8 ("stack: add C11 atomic implementation")
> 
> Signed-off-by: Phil Yang <phil.yang@arm.com>
> Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> 
> ---
>  lib/librte_stack/rte_stack_lf_c11.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/librte_stack/rte_stack_lf_c11.h
> b/lib/librte_stack/rte_stack_lf_c11.h
> index a316e9a..e3b9eff 100644
> --- a/lib/librte_stack/rte_stack_lf_c11.h
> +++ b/lib/librte_stack/rte_stack_lf_c11.h
> @@ -97,7 +97,7 @@ __rte_stack_lf_pop_elems(struct rte_stack_lf_list *list,
>  	return NULL;
>  #else
>  	struct rte_stack_lf_head old_head;
> -	uint64_t len;
> +	int64_t len;

This works, but I'd prefer to keep 'len' unsigned. How about changing the definition of 'len' in struct rte_stack_lf_list to uint64_t, and in rte_stack_lf_generic.h casting it to rte_atomic64_t* when its address is passed to the rte_atomic64_...() functions?
  
Phil Yang June 17, 2019, 7:49 a.m. UTC | #2
> -----Original Message-----
> From: Eads, Gage <gage.eads@intel.com>
> Sent: Saturday, June 15, 2019 3:50 AM
> To: Phil Yang (Arm Technology China) <Phil.Yang@arm.com>; dev@dpdk.org
> Cc: nd <nd@arm.com>; Honnappa Nagarahalli
> <Honnappa.Nagarahalli@arm.com>; Gavin Hu (Arm Technology China)
> <Gavin.Hu@arm.com>
> Subject: RE: [PATCH] eal/stack: fix 'pointer-sign' warning
> 
> > clang raise 'pointer-sign' warnings in __atomic_compare_exchange when
> > passing 'uint64_t *' to parameter of type 'int64_t *' converts between
> > pointers to integer types with different sign.
> >
> > Fixes: 7e6e609939a8 ("stack: add C11 atomic implementation")
> >
> > Signed-off-by: Phil Yang <phil.yang@arm.com>
> > Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> >
> > ---
> >  lib/librte_stack/rte_stack_lf_c11.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/librte_stack/rte_stack_lf_c11.h
> > b/lib/librte_stack/rte_stack_lf_c11.h
> > index a316e9a..e3b9eff 100644
> > --- a/lib/librte_stack/rte_stack_lf_c11.h
> > +++ b/lib/librte_stack/rte_stack_lf_c11.h
> > @@ -97,7 +97,7 @@ __rte_stack_lf_pop_elems(struct rte_stack_lf_list
> *list,
> >  	return NULL;
> >  #else
> >  	struct rte_stack_lf_head old_head;
> > -	uint64_t len;
> > +	int64_t len;
> 
> This works, but I'd prefer to keep 'len' unsigned. How about changing the
> definition of 'len' in struct rte_stack_lf_list to uint64_t, and in
> rte_stack_lf_generic.h casting it to rte_atomic64_t* when its address is
> passed to the rte_atomic64_...() functions?

It is better I think. I have upstreamed the v2, please review it. 

Thanks,
Phil
  

Patch

diff --git a/lib/librte_stack/rte_stack_lf_c11.h b/lib/librte_stack/rte_stack_lf_c11.h
index a316e9a..e3b9eff 100644
--- a/lib/librte_stack/rte_stack_lf_c11.h
+++ b/lib/librte_stack/rte_stack_lf_c11.h
@@ -97,7 +97,7 @@  __rte_stack_lf_pop_elems(struct rte_stack_lf_list *list,
 	return NULL;
 #else
 	struct rte_stack_lf_head old_head;
-	uint64_t len;
+	int64_t len;
 	int success;
 
 	/* Reserve num elements, if available */