Hi Gustavo,

On 17/12/25 22:20, Gustavo Romero wrote:
Add a sentinel to the ARMASIdx enum so it can be used when the total
number of address spaces is required.

Signed-off-by: Gustavo Romero <[email protected]>
---
  target/arm/cpu.h | 1 +
  1 file changed, 1 insertion(+)

diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 39f2b2e54d..00f5af0fcd 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -2336,6 +2336,7 @@ typedef enum ARMASIdx {
      ARMASIdx_S = 1,
      ARMASIdx_TagNS = 2,
      ARMASIdx_TagS = 3,
+    ARMASIdx_MAX

The problem with including this in the enum is this confuses static
analyzers:

warning: enumeration value 'ARMASIdx_MAX' not handled in switch [-Wswitch]

To avoid that we /define/ it manually instead:

#define ARMASIdx_MAX 4

  } ARMASIdx;

Usually the definition is within the enum declaration, and we name
it ${enum}_COUNT:

    typedef enum ARMASIdx {
        ARMASIdx_NS = 0,
        ARMASIdx_S = 1,
        ARMASIdx_TagNS = 2,
        ARMASIdx_TagS = 3,
    #define ARMASIdx_COUNT 4
    } ARMASIdx;

Unfortunately this didn't work well with QAPI, so we could never enable
-Wswitch globally:
https://lore.kernel.org/qemu-devel/[email protected]/

Today I'm not sure what is the best style anymore, so just take
my comments are historical 2 cents.

Regards,

Phil.


Reply via email to