mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Ricardo Ribalda <ribalda@chromium.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>,
	Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	linux-kernel@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH] mm: vmstat.h: Annotate operations between enums
Date: Mon, 2 Dec 2024 09:18:11 -0700	[thread overview]
Message-ID: <20241202161811.GA2843691@thelio-3990X> (raw)
In-Reply-To: <20241202-fix-vmstat-v1-1-c995585b7df5@chromium.org>

Hi Ricardo,

On Mon, Dec 02, 2024 at 04:02:19PM +0000, Ricardo Ribalda wrote:
> Compiler is confused when we do arithmetic operations between two
> different enum types.
> In this case NR_VM_STAT_ITEMS and NR_LRU_BASE are not actual
> enumerators, they are used to find the first and the count of the
> enumerator.
> 
> Add a casting to int, to avoid the following llvm 9 warning:
> ./include/linux/vmstat.h:504:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
>   504 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
>       |                            ~~~~~~~~~~~~~~~~~~~~~ ^
>   505 |                            item];
>       |                            ~~~~
> ./include/linux/vmstat.h:511:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
>   511 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
>       |                            ~~~~~~~~~~~~~~~~~~~~~ ^
>   512 |                            NR_VM_NUMA_EVENT_ITEMS +
>       |                            ~~~~~~~~~~~~~~~~~~~~~~
> ./include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
>   518 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
>       |                               ~~~~~~~~~~~ ^ ~~~
> ./include/linux/vmstat.h:524:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
>   524 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
>       |                            ~~~~~~~~~~~~~~~~~~~~~ ^
>   525 |                            NR_VM_NUMA_EVENT_ITEMS +
>       |                            ~~~~~~~~~~~~~~~~~~~~~~
> 
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>

I think it is just better to disable this specific warning for normal
and W=1 builds so that it is not visible for people, as this objectively
makes the code uglier:

https://lore.kernel.org/20241008005136.GA241099@thelio-3990X/

https://lore.kernel.org/20241017-disable-two-clang-enum-warnings-v2-1-163ac04346ae@kernel.org/

I have just pinged that patch for acceptance.

Cheers,
Nathan

> ---
>  include/linux/vmstat.h | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
> index d2761bf8ff32..32c641d25bea 100644
> --- a/include/linux/vmstat.h
> +++ b/include/linux/vmstat.h
> @@ -501,27 +501,26 @@ static inline const char *zone_stat_name(enum zone_stat_item item)
>  #ifdef CONFIG_NUMA
>  static inline const char *numa_stat_name(enum numa_stat_item item)
>  {
> -	return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
> -			   item];
> +	return vmstat_text[(int)NR_VM_ZONE_STAT_ITEMS + item];
>  }
>  #endif /* CONFIG_NUMA */
>  
>  static inline const char *node_stat_name(enum node_stat_item item)
>  {
> -	return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
> +	return vmstat_text[(int)NR_VM_ZONE_STAT_ITEMS +
>  			   NR_VM_NUMA_EVENT_ITEMS +
>  			   item];
>  }
>  
>  static inline const char *lru_list_name(enum lru_list lru)
>  {
> -	return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
> +	return node_stat_name((int)NR_LRU_BASE + lru) + 3; // skip "nr_"
>  }
>  
>  #if defined(CONFIG_VM_EVENT_COUNTERS) || defined(CONFIG_MEMCG)
>  static inline const char *vm_event_name(enum vm_event_item item)
>  {
> -	return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
> +	return vmstat_text[(int)NR_VM_ZONE_STAT_ITEMS +
>  			   NR_VM_NUMA_EVENT_ITEMS +
>  			   NR_VM_NODE_STAT_ITEMS +
>  			   NR_VM_STAT_ITEMS +
> 
> ---
> base-commit: 40384c840ea1944d7c5a392e8975ed088ecf0b37
> change-id: 20241202-fix-vmstat-88968bcaa955
> 
> Best regards,
> -- 
> Ricardo Ribalda <ribalda@chromium.org>
> 

  reply	other threads:[~2024-12-02 16:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-02 16:02 Ricardo Ribalda
2024-12-02 16:18 ` Nathan Chancellor [this message]
2024-12-02 17:27   ` Ricardo Ribalda
2024-12-15 21:36 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241202161811.GA2843691@thelio-3990X \
    --to=nathan@kernel.org \
    --cc=justinstitt@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=ndesaulniers@google.com \
    --cc=ribalda@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®