]> xenbits.xensource.com Git - people/andrewcoop/xen.git/commitdiff
x86/pv: Fix build with Clang and CONFIG_PERF_COUNTERS
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 2 Jan 2025 19:46:19 +0000 (19:46 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 6 Jan 2025 12:26:42 +0000 (12:26 +0000)
Clang, of at least verion 17 complains:

  arch/x86/pv/hypercall.c:30:10: error: variable 'eax' is used uninitialized
  whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
     30 |     if ( !compat )
        |          ^~~~~~~
  arch/x86/pv/hypercall.c:87:29: note: uninitialized use occurs here
     87 |     perfc_incra(hypercalls, eax);
        |                             ^~~

This function is forced always_inline to cause compat to be
constant-propagated through, but that is only a heuristic to try and get the
compiler to do what we want, not a gurantee that it does.

Clang doesn't appear to be able to see that the only case where compat is
true (and therefore the if() is false) is when there's an else clause on the
end which sets eax too.

Initialise eax to -1, which ought to be optimised out, but if for whatever
reason it happens not to be, then perfc_incra() will fail it's bounds check
and do nothing.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/pv/hypercall.c

index 2febade44b73768c7480e16e6b622c79579e57da..17581d232e19665df6fedd0e659f2216fad3fe8f 100644 (file)
@@ -21,7 +21,7 @@ static void always_inline
 _pv_hypercall(struct cpu_user_regs *regs, bool compat)
 {
     struct vcpu *curr = current;
-    unsigned long eax;
+    unsigned long eax = -1; /* Clang -Wsometimes-uninitialized */
 
     ASSERT(guest_kernel_mode(curr, regs));