[RFC PATCH 05/19] graph: fix variable shadowing errors

Bruce Richardson bruce.richardson at intel.com
Thu Nov 6 17:33:45 CET 2025


On Thu, Nov 06, 2025 at 07:50:13AM -0800, Stephen Hemminger wrote:
> On Thu,  6 Nov 2025 14:09:34 +0000
> Bruce Richardson <bruce.richardson at intel.com> wrote:
> 
> > The nested use of MIN/MAX macros causes shadowing due to the use of the
> > hard-coded temporary variable names in the macros. We can fix this in
> > graph library by using MIN_T/MAX_T macros instead, which actually makes
> > more sense in some circumstances:
> > 
> > * when defining SZ, use of RTE_MIN_T makes sense as the comments says it
> >   is defined to be usable for compile-time evaluation.
> > * for the size calculations, RTE_MAX_T is also useful as it explicitly
> >   encodes the type, making it clear that we are evaluating the size
> >   variables as "int" type, larger than the uin16_t size is defined as.
> > 
> > Fixes: b6ef3794b866 ("graph: move node clone name func into private as common")
> > Cc: stable at dpdk.org
> > 
> > Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
> 
> I had a patch series (not sent) for lots of these.
> This is how I addressed min/max
> 
> From 5c8d69c734f90a774f83aaf47bc6c61bb19f411e Mon Sep 17 00:00:00 2001
> From: Stephen Hemminger <stephen at networkplumber.org>
> Date: Thu, 28 Aug 2025 09:24:54 -0700
> Subject: [PATCH 06/13] eal: add more min/max helpers
> 
> Add RTE_MIN3() to handle case of RTE_MIN(RTE_MIN(...)).
> Change name of local temporary variables in RTE_MAX()
> to allow for combinations of RTE_MIN(RTE_MAX(...)) without
> causing shadow declaration warnings.
> 
> Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>

Yep, since sending the set, I similarly changed the variables in the MAX
call to _x and _y, similar to you. I was also considering the MIN3 / MAX3
change too, but had not implemented it.

I'll roll your patch below into my set in next version, for 26.03.

/Bruce

> ---
>  lib/eal/include/rte_common.h | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
> index 9e7d84f929..1f0edef73f 100644
> --- a/lib/eal/include/rte_common.h
> +++ b/lib/eal/include/rte_common.h
> @@ -799,6 +799,19 @@ __extension__ typedef uint64_t RTE_MARKER64[0];
>  		_a < _b ? _a : _b; \
>  	})
>  
> +/**
> + * Macro to return the minimum of three numbers
> + */
> +#define RTE_MIN3(a, b, c)			\
> +	__extension__ ({			\
> +		typeof (a) _a = (a);		\
> +		typeof (b) _b = (b);		\
> +		typeof (c) _c = (c);		\
> +		_a < _b ? (_a < _c ? _a : _c)	\
> +			: (_b < _c ? _b : _c);	\
> +	})
> +
> +
>  /**
>   * Macro to return the minimum of two numbers
>   *
> @@ -814,9 +827,9 @@ __extension__ typedef uint64_t RTE_MARKER64[0];
>   */
>  #define RTE_MAX(a, b) \
>  	__extension__ ({ \
> -		typeof (a) _a = (a); \
> -		typeof (b) _b = (b); \
> -		_a > _b ? _a : _b; \
> +		typeof (a) _ax = (a); \
> +		typeof (b) _bx = (b); \
> +		_ax > _bx ? _ax : _bx; \
>  	})
>  
>  /**
> -- 
> 2.51.0
> 


More information about the dev mailing list