mm/vmstat: Fix a W=1 clang compiler warning
Subsystems (3)
PATCH 1/1 mm/vmstat: Fix a W=1 clang compiler warning
Fix the following clang compiler warning that is reported if the kernel is built with W=1:
./include/linux/vmstat.h:518:36: error: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Werror,-Wenum-enum-conversion]
518 | return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
| ~~~~~~~~~~~ ^ ~~~
--- include/linux/vmstat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/vmstat.h +1 -1
@@ -515,7 +515,7 @@ static inline const char *node_stat_name(enum node_stat_item 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 (NR_LRU_BASE + (enum node_stat_item )lru) +3 ;// skip "nr_" }#if defined(CONFIG_VM_EVENT_COUNTERS ) || defined(CONFIG_MEMCG )
Andrew Morton
maintainerQuoted 12 lines · On Thu, 12 Dec 2024 13:31:26 -0800 Bart Van Assche <[email protected]> wrote:
Fix the following clang compiler warning that is reported if the kernel is built with W=1:
./include/linux/vmstat.h:518:36: error: arithmetic between different enumeration types ('enumnode_stat_item' and 'enumlru_list') [-Werror,-Wenum-enum-conversion]
518 | returnnode_stat_name(NR_LRU_BASE + lru)+ 3; // skip "nr_"| ~~~~~~~~~~~ ^ ~~~...
include/linux/vmstat.h static inline const char *node_stat_name(enum node_stat_item item) · line 520
Quoted 7 lines
include/linux/vmstat.h +1
-1@@ -515,7 +515,7 @@ static inline const char *node_stat_name(enum node_stat_item 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 (NR_LRU_BASE + (enum node_stat_item )lru) +3 ;// skip "nr_" }
Spose so. One always suspects that adding a typecast is a sign that we screwed things up somehow. The relationship between enums lru_list and node_stat_item is foggy, and I'm unsure whether this is the place to make the transition it. Perhaps lru_list_name() should take an `unsigned int' arg instead.
Quoted 15 lines · Andrew Morton
Quoted 13 lines · On Thu, 12 Dec 2024 13:31:26 -0800 Bart Van Assche <[email protected]> wrote:
Fix the following clang compiler warning that is reported if the kernel is built with W=1:
./include/linux/vmstat.h:518:36: error: arithmetic between different enumeration types ('enumnode_stat_item' and 'enumlru_list') [-Werror,-Wenum-enum-conversion]
518 | returnnode_stat_name(NR_LRU_BASE + lru)+ 3; // skip "nr_"| ~~~~~~~~~~~ ^ ~~~...
include/linux/vmstat.h +0
-0@@ -515,7 +515,7 @@ static inline const char *node_stat_name(enum node_stat_item item)
Quoted 12 lines
include/linux/vmstat.h static inline const char *node_stat_name(enum node_stat_item item) · line 520
Quoted 6 lines
include/linux/vmstat.h +1
-1static 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 (NR_LRU_BASE + (enum node_stat_item )lru) +3 ;// skip "nr_" }Spose so. One always suspects that adding a typecast is a sign that we screwed things up somehow. The relationship between enums
lru_listandnode_stat_itemis foggy, and I'm unsure whether this is the place to make the transition it. Perhapslru_list_name()should take an `unsigned int' arg instead.
Could the (untested) patch below be a better approach?
Thanks,
Bart.
include/linux/mmzone.h +14 -2
@@ -135,10 +135,16 @@ enum numa_stat_item {#define NR_VM_NUMA_EVENT_ITEMS 0#endif +/* +* enum lru_list constants are often added to NR_ZONE_LRU_BASE. Define +* NR_ZONE_LRU_BASE as an integer instead of enum node_stat_item to prevent +* that the compiler warns about enumeration type mismatches. +*/ +#define NR_ZONE_LRU_BASE 1/* Used only for compaction and reclaim retry */ +enum zone_stat_item {/* First 128 byte cacheline (assuming 64 bit words) */ NR_FREE_PAGES , -NR_ZONE_LRU_BASE ,/* Used only for compaction and reclaim retry */ NR_ZONE_INACTIVE_ANON =NR_ZONE_LRU_BASE ,NR_ZONE_ACTIVE_ANON ,NR_ZONE_INACTIVE_FILE ,
@@ -157,8 +163,14 @@ enum zone_stat_item {#endif NR_VM_ZONE_STAT_ITEMS }; +/* +* enum lru_list constants are often added to NR_LRU_BASE. Define NR_LRU_BASE +* as an integer instead of enum node_stat_item to prevent that the compiler +* warns about enumeration type mismatches. +*/ +#define NR_LRU_BASE 0 +enum node_stat_item { -NR_LRU_BASE ,NR_INACTIVE_ANON =NR_LRU_BASE ,/* must match order of LRU_[IN]ACTIVE */ NR_ACTIVE_ANON ,/* " " " " " */ NR_INACTIVE_FILE ,/* " " " " " */
Quoted 5 lines
Spose so. One always suspects that adding a typecast is a sign that we screwed things up somehow. The relationship between enums
lru_listandnode_stat_itemis foggy, and I'm unsure whether this is the place to make the transition it. Perhapslru_list_name()should take an `unsigned int' arg instead.
All of these *_name() functions do seem to expect arguments in range of the corresponding enums, so perhaps keep those args typed as a form of self-documenting code, and do this instead?
---
From f8960df01b7f4fdc8d09a366886563385aed7f18 Mon Sep 17 00:00:00 2001
From: Ivan Shapovalov <[email protected]>
Date: Wed, 22 Jan 2025 04:10:59 +0300
Subject: [PATCH] mm: fix more clang compiler warnings
In the similar vein as 30c2de0a267c ("mm/vmstat: fix a W=1 clang compiler warning"), fix several more sites that generate warnings with clang 19.1.7:
./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: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 +
| ~~~~~~~~~~~~~~~~~~~~~~3 warnings generated.
Similarly for mm_inline.h:
./include/linux/mm_inline.h:47:41: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
47 | __mod_lruvec_state(lruvec, NR_LRU_BASE + lru, nr_pages);
| ~~~~~~~~~~~ ^ ~~~
./include/linux/mm_inline.h:49:22: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
49 | NR_ZONE_LRU_BASE + lru, nr_pages);
| ~~~~~~~~~~~~~~~~ ^ ~~~2 warnings generated.
Additionally, change the lru_list_name() and mm_inline.h sites to use the same (int)ENUMERATOR + ... idiom to match the three first fixes above for consistency. Everywhere else is's semantically more correct thing to do because we are not really treating any of these enums as other enums but rather treating all of those as indices.
--- include/linux/mm_inline.h | 4 ++-- include/linux/vmstat.h | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-)
include/linux/mm_inline.h +2 -2
@@ -44,9 +44,9 @@ static __always_inline void __update_lru_size(struct lruvec *lruvec,lockdep_assert_held (&lruvec->lru_lock);WARN_ON_ONCE (nr_pages != (int )nr_pages); -__mod_lruvec_state (lruvec,NR_LRU_BASE + lru, nr_pages); +__mod_lruvec_state (lruvec, (int )NR_LRU_BASE + lru, nr_pages);__mod_zone_page_state (&pgdat->node_zones[zid], -NR_ZONE_LRU_BASE + lru, nr_pages); + (int )NR_ZONE_LRU_BASE + lru, nr_pages); } static __always_inline void update_lru_size(struct lruvec *lruvec,
include/linux/vmstat.h +4 -4
@@ -501,27 +501,27 @@ 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 + +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 + (enum node_stat_item )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 +
Signature · 1 line
2.48.1.5.g9188e14f140
Quoted 11 lines · Ivan Shapovalov
Quoted 5 lines
Spose so. One always suspects that adding a typecast is a sign that we screwed things up somehow. The relationship between enums
lru_listandnode_stat_itemis foggy, and I'm unsure whether this is the place to make the transition it. Perhapslru_list_name()should take an `unsigned int' arg instead.All of these
*_name()functions do seem to expect arguments in range of the corresponding enums, so perhaps keep those args typed as a form of self-documenting code, and do this instead?[ ... ]
Please take a look at
https://lore.kernel.org/linux-mm/[email protected]/. I think the patch I posted on December 13 requires fewer changes and no type casts.
Thanks,
Bart.
Quoted 9 lines · Ivan Shapovalov
Quoted 5 lines
Spose so. One always suspects that adding a typecast is a sign that we screwed things up somehow. The relationship between enums
lru_listandnode_stat_itemis foggy, and I'm unsure whether this is the place to make the transition it. Perhapslru_list_name()should take an `unsigned int' arg instead.All of these
*_name()functions do seem to expect arguments in range of the corresponding enums, so perhaps keep those args typed as a form of self-documenting code, and do this instead?
If nobody objects I will submit this patch for review after the merge window has closed:
Subject: [PATCH] mm/vmstat: Fix W=1 clang compiler warnings
Commit 30c2de0a267c ("mm/vmstat: fix a W=1 clang compiler warning") suppresses some but not all compiler warnings that are reported by clang when building with W=1 about NR_LRU_BASE and NR_ZONE_LRU_BASE. Hence revert commit 30c2de0a267c and instead make NR_LRU_BASE and NR_ZONE_LRU_BASE integer constants instead of enumeration constants.
--- include/linux/mmzone.h | 22 +++++++++++++++++++--- include/linux/vmstat.h | 9 +++++++-- 2 files changed, 26 insertions(+), 5 deletions(-)
include/linux/mmzone.h +19 -3
@@ -135,10 +135,19 @@ enum numa_stat_item {#define NR_VM_NUMA_EVENT_ITEMS 0#endif +/* +* NR_ZONE_LRU_BASE and NR_VM_ZONE_STAT_ITEMS are often added to enumeration +* constants of another type than enum_zone_stat_item. Define these constants +* as an integer instead of enum node_stat_item to prevent that the compiler +* warns about enumeration type mismatches when these constants are used. +*/ +#define NR_ZONE_LRU_BASE (1 * __NR_ZONE_LRU_BASE) +#define NR_VM_ZONE_STAT_ITEMS (1 * __NR_VM_ZONE_STAT_ITEMS) +enum zone_stat_item {/* First 128 byte cacheline (assuming 64 bit words) */ NR_FREE_PAGES , -NR_ZONE_LRU_BASE ,/* Used only for compaction and reclaim retry */ + __NR_ZONE_LRU_BASE,/* Used only for compaction and reclaim retry */ NR_ZONE_INACTIVE_ANON =NR_ZONE_LRU_BASE ,NR_ZONE_ACTIVE_ANON ,NR_ZONE_INACTIVE_FILE ,
@@ -155,10 +164,17 @@ enum zone_stat_item { #ifdef CONFIG_UNACCEPTED_MEMORY NR_UNACCEPTED, #endif - NR_VM_ZONE_STAT_ITEMS }; + __NR_VM_ZONE_STAT_ITEMS }; + +/* + * enum lru_list constants are often added to NR_LRU_BASE. Define NR_LRU_BASE + * as an integer instead of enum node_stat_item to prevent that the compiler + * warns about enumeration type mismatches. + */ +#define NR_LRU_BASE (1 * __NR_LRU_BASE) enum node_stat_item { - NR_LRU_BASE, + __NR_LRU_BASE, NR_INACTIVE_ANON = NR_LRU_BASE, /* must match order of LRU_[IN]ACTIVE */ NR_ACTIVE_ANON, /* " " " " " */ NR_INACTIVE_FILE, /* " " " " " */
include/linux/vmstat.h +7 -2
@@ -135,8 +135,13 @@ static inline void vm_events_fold_cpu(int cpu)#define count_vm_vma_lock_event (x) do {} while (0)#endif +/* +* item##_NORMAL has type enum vm_event_item while ZONE_NORMAL and zid have +* type enum zone_type. Suppress compiler warnings about mixing different +* enumeration types by converting item##_NORMAL into an int with '1 *'. +*/ #define __count_zid_vm_events (item, zid, delta) \ - __count_vm_events(item##_NORMAL - ZONE_NORMAL + zid, delta) + __count_vm_events(1 * item##_NORMAL - ZONE_NORMAL + zid, delta)/* * Zone and node-based page accounting with per cpu differentials.
@@ -515,7 +520,7 @@ static inline const char *node_stat_name(enum node_stat_item item)static inline const char *lru_list_name (enum lru_list lru) { -return node_stat_name (NR_LRU_BASE + (enum node_stat_item )lru) +3 ;// skip "nr_" +return node_stat_name (NR_LRU_BASE + lru) +3 ;// skip "nr_" }#if defined(CONFIG_VM_EVENT_COUNTERS ) || defined(CONFIG_MEMCG )
Quoted 46 lines · Bart Van Assche
Quoted 9 lines · Ivan Shapovalov
Quoted 5 lines
Spose so. One always suspects that adding a typecast is a sign that we screwed things up somehow. The relationship between enums
lru_listandnode_stat_itemis foggy, and I'm unsure whether this is the place to make the transition it. Perhapslru_list_name()should take an `unsigned int' arg instead.All of these
*_name()functions do seem to expect arguments in range of the corresponding enums, so perhaps keep those args typed as a form of self-documenting code, and do this instead?If nobody objects I will submit this patch for review after the merge window has closed:
Subject: [PATCH] mm/vmstat: Fix W=1 clang compiler warnings
Commit
30c2de0a267c("mm/vmstat: fix a W=1 clang compiler warning") suppresses some but not all compiler warnings that are reported by clang when building with W=1 aboutNR_LRU_BASEandNR_ZONE_LRU_BASE. Hence revert commit30c2de0a267cand instead makeNR_LRU_BASEandNR_ZONE_LRU_BASEinteger constants instead of enumeration constants.Cc Ivan Shapovalov <[email protected]>Signed-off-by Bart Van Assche <[email protected]>--- include/linux/mmzone.h | 22 +++++++++++++++++++--- include/linux/vmstat.h | 9 +++++++-- 2 files changed, 26 insertions(+), 5 deletions(-)include/linux/mmzone.h +2
-0@@ -135,10 +135,19 @@ enum numa_stat_item {#define NR_VM_NUMA_EVENT_ITEMS 0#endif +/* +* NR_ZONE_LRU_BASE and NR_VM_ZONE_STAT_ITEMS are often added to enumeration
+ * constants of another type thanenum_zone_stat_item. Define these constants
+ * as an integer instead of enumnode_stat_itemto prevent that the compiler
+ * warns about enumeration type mismatches when these constants are used.
+ */
include/linux/mmzone.h enum numa_stat_item { · line 145
Quoted 2 lines
include/linux/mmzone.h +2
-0+#define NR_ZONE_LRU_BASE (1 * __NR_ZONE_LRU_BASE) +#define NR_VM_ZONE_STAT_ITEMS (1 * __NR_VM_ZONE_STAT_ITEMS)
Seems an acceptable approach, dunno if this multiply by one is any better than casting to int?
include/linux/mmzone.h enum numa_stat_item { · line 151
Quoted 7 lines
include/linux/mmzone.h +2
-1+enum zone_stat_item {/* First 128 byte cacheline (assuming 64 bit words) */ NR_FREE_PAGES , -NR_ZONE_LRU_BASE ,/* Used only for compaction and reclaim retry */ + __NR_ZONE_LRU_BASE,/* Used only for compaction and reclaim retry */ NR_ZONE_INACTIVE_ANON =NR_ZONE_LRU_BASE ,
Should we rather use __NR_ZONE_LRU_BASE here?
Quoted 16 lines
NR_ZONE_ACTIVE_ANON,
NR_ZONE_INACTIVE_FILE,include/linux/mmzone.h +4
-1@@ -155,10 +164,17 @@ enum zone_stat_item {#ifdef CONFIG_UNACCEPTED_MEMORY NR_UNACCEPTED , #endif - NR_VM_ZONE_STAT_ITEMS }; + __NR_VM_ZONE_STAT_ITEMS }; + +/* +* enum lru_list constants are often added to NR_LRU_BASE. Define
NR_LRU_BASE
+ * as an integer instead of enumnode_stat_itemto prevent that the compiler
+ * warns about enumeration type mismatches.
+ */
include/linux/mmzone.h enum zone_stat_item { · line 178
Quoted 6 lines
include/linux/mmzone.h +2
-1+#define NR_LRU_BASE (1 * __NR_LRU_BASE)enum node_stat_item { -NR_LRU_BASE , + __NR_LRU_BASE,NR_INACTIVE_ANON =NR_LRU_BASE ,/* must match order of LRU_[IN]ACTIVE */
ditto
Quoted 33 lines
NR_ACTIVE_ANON, /* " " " " " */
NR_INACTIVE_FILE, /* " " " " " */include/linux/vmstat.h +6
-2@@ -135,8 +135,13 @@ static inline void vm_events_fold_cpu(int cpu)#define count_vm_vma_lock_event (x) do {} while (0)#endif +/* +* item##_NORMAL has type enum vm_event_item while ZONE_NORMAL and zid have +* type enum zone_type. Suppress compiler warnings about mixing different +* enumeration types by converting item##_NORMAL into an int with '1 *'. +*/ #define __count_zid_vm_events (item, zid, delta) \ - __count_vm_events(item##_NORMAL - ZONE_NORMAL + zid, delta) + __count_vm_events(1 * item##_NORMAL - ZONE_NORMAL + zid, delta)/* * Zone and node-based page accounting with per cpu differentials. @@ -515,7 +520,7 @@ static inline const char *node_stat_name(enum node_stat_item item)static inline const char *lru_list_name (enum lru_list lru) { -return node_stat_name (NR_LRU_BASE + (enum node_stat_item )lru) +3 ;// skip "
nr_"include/linux/vmstat.h +1
-0+return node_stat_name (NR_LRU_BASE + lru) +3 ;// skip "nr_" }#if defined(CONFIG_VM_EVENT_COUNTERS ) || defined(CONFIG_MEMCG )
Quoted 6 lines · Vlastimil Babka
include/linux/mmzone.h enum numa_stat_item { · line 145
Quoted 2 lines · Bart Van Assche
include/linux/mmzone.h +2
-0+#define NR_ZONE_LRU_BASE (1 * __NR_ZONE_LRU_BASE) +#define NR_VM_ZONE_STAT_ITEMS (1 * __NR_VM_ZONE_STAT_ITEMS)Seems an acceptable approach, dunno if this multiply by one is any better than casting to int?
For enumeration types that are wider than an int, casting to an int causes the highest bits to be lost. Multiplying by one doesn't have this disadvantage. Please note that I don't have a strong opinion about this and that casting to int would also work here.
Quoted 9 lines
include/linux/mmzone.h enum numa_stat_item { · line 151
Quoted 7 lines
include/linux/mmzone.h +2
-1+enum zone_stat_item {/* First 128 byte cacheline (assuming 64 bit words) */ NR_FREE_PAGES , -NR_ZONE_LRU_BASE ,/* Used only for compaction and reclaim retry */ + __NR_ZONE_LRU_BASE,/* Used only for compaction and reclaim retry */ NR_ZONE_INACTIVE_ANON =NR_ZONE_LRU_BASE ,Should we rather use
__NR_ZONE_LRU_BASEhere?
Right, I will fix this and also a similar issue below.
Thanks,
Bart.
Quoted 38 lines · On Wed, 29 Jan 2025 11:22:00 +0100 Vlastimil Babka <[email protected]> wrote:
Quoted 37 lines · Bart Van Assche
Quoted 9 lines · Ivan Shapovalov
Quoted 5 lines
Spose so. One always suspects that adding a typecast is a sign that we screwed things up somehow. The relationship between enums
lru_listandnode_stat_itemis foggy, and I'm unsure whether this is the place to make the transition it. Perhapslru_list_name()should take an `unsigned int' arg instead.All of these
*_name()functions do seem to expect arguments in range of the corresponding enums, so perhaps keep those args typed as a form of self-documenting code, and do this instead?If nobody objects I will submit this patch for review after the merge window has closed:
Subject: [PATCH] mm/vmstat: Fix W=1 clang compiler warnings
Commit
30c2de0a267c("mm/vmstat: fix a W=1 clang compiler warning") suppresses some but not all compiler warnings that are reported by clang when building with W=1 aboutNR_LRU_BASEandNR_ZONE_LRU_BASE. Hence revert commit30c2de0a267cand instead makeNR_LRU_BASEandNR_ZONE_LRU_BASEinteger constants instead of enumeration constants.Cc Ivan Shapovalov <[email protected]>Signed-off-by Bart Van Assche <[email protected]>--- include/linux/mmzone.h | 22 +++++++++++++++++++--- include/linux/vmstat.h | 9 +++++++-- 2 files changed, 26 insertions(+), 5 deletions(-)include/linux/mmzone.h +0
-0@@ -135,10 +135,19 @@ enum numa_stat_item {#define NR_VM_NUMA_EVENT_ITEMS 0#endif
Quoted 14 lines
include/linux/mmzone.h enum numa_stat_item { · line 145
Quoted 11 lines
include/linux/mmzone.h +2
-0+/* +* NR_ZONE_LRU_BASE and NR_VM_ZONE_STAT_ITEMS are often added to enumeration
+ * constants of another type thanenum_zone_stat_item. Define these constants
+ * as an integer instead of enumnode_stat_itemto prevent that the compiler
+ * warns about enumeration type mismatches when these constants are used.
+ */include/linux/mmzone.h +2
-0+#define NR_ZONE_LRU_BASE (1 * __NR_ZONE_LRU_BASE) +#define NR_VM_ZONE_STAT_ITEMS (1 * __NR_VM_ZONE_STAT_ITEMS)Seems an acceptable approach, dunno if this multiply by one is any better than casting to int?
I'd probably use (enum_value + 0) rather than a multiply. And, if you are going to use multiply, I think it should be (value * 1) for the same reason that 'if (1 == x)' horrible.
David