Structures or unions without any named members aren't liked by Misra
(nor the C standard). Avoid emitting such for leaves without any known
bits.
At this occasion also add the script to the X86 section in ./MAINTAINERS.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -601,6 +601,7 @@ F: xen/arch/x86/
F: xen/include/public/arch-x86/
F: xen/include/xen/lib/x86
F: xen/lib/x86
+F: xen/tools/gen-cpuid.py
F: tools/firmware/hvmloader/
F: tools/firmware/rombios/
F: tools/firmware/vgabios/
--- a/xen/tools/gen-cpuid.py
+++ b/xen/tools/gen-cpuid.py
@@ -367,6 +367,7 @@ def crunch_numbers(state):
for word in range(state.nr_entries):
names = []
+ empty = 1
for bit in range(32):
name = state.names.get(word * 32 + bit, "")
@@ -380,9 +381,15 @@ def crunch_numbers(state):
if name in ("APIC", "OSXSAVE", "OSPKE"):
name = ""
+ if name:
+ empty = 0
+
names.append(name.lower())
- state.bitfields.append("bool " + ":1, ".join(names) + ":1")
+ if empty:
+ state.bitfields.append("unsigned int empty_" + str(word) + ":32")
+ else:
+ state.bitfields.append("bool " + ":1, ".join(names) + ":1")
def write_results(state):
On 02/08/2023 10:43 am, Jan Beulich wrote:
> Structures or unions without any named members aren't liked by Misra
> (nor the C standard). Avoid emitting such for leaves without any known
> bits.
>
> At this occasion also add the script to the X86 section in ./MAINTAINERS.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -601,6 +601,7 @@ F: xen/arch/x86/
> F: xen/include/public/arch-x86/
> F: xen/include/xen/lib/x86
> F: xen/lib/x86
> +F: xen/tools/gen-cpuid.py
> F: tools/firmware/hvmloader/
> F: tools/firmware/rombios/
> F: tools/firmware/vgabios/
> --- a/xen/tools/gen-cpuid.py
> +++ b/xen/tools/gen-cpuid.py
> @@ -367,6 +367,7 @@ def crunch_numbers(state):
> for word in range(state.nr_entries):
>
> names = []
> + empty = 1
> for bit in range(32):
>
> name = state.names.get(word * 32 + bit, "")
> @@ -380,9 +381,15 @@ def crunch_numbers(state):
> if name in ("APIC", "OSXSAVE", "OSPKE"):
> name = ""
>
> + if name:
> + empty = 0
> +
> names.append(name.lower())
>
> - state.bitfields.append("bool " + ":1, ".join(names) + ":1")
> + if empty:
> + state.bitfields.append("unsigned int empty_" + str(word) + ":32")
> + else:
> + state.bitfields.append("bool " + ":1, ".join(names) + ":1")
There's no need for the extra empty variable (this is python, not C).
if any(names):
state.bitfields.append("bool " + ":1, ".join(names) + ":1")
else:
state.bitfields.append("uint32_t empty_%s" % (word, ))
But there's a related bug later in the script which MISRA won't notice
unless it happens to run on the cset boundary introducing a new leaf.
I'll see about doing a patch to address both.
~Andrew
© 2016 - 2026 Red Hat, Inc.