Skip to contentSkip to conversation

Fix Clang 24 -Wunused-but-set-global warnings

PATCH In review Yosry Ahmed 3 participants 5 messages Oct 22 – Nov 11

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Fix Clang 24 -Wunused-but-set-global warnings

Building kvm-unit-tests with Clang 24 fails with -Werror due to the new -Wunused-but-set-global warning flagging static variables that are written to but never read in lib/chr-testdev.c and lib/x86/desc.c.

Remove both unused variables.

Yosry Ahmed (2):
chr-testdev: Remove unused in_vq
x86/desc: Remove unused exception flag

 lib/chr-testdev.c | 3 +--
 lib/x86/desc.c    | 2 --
 2 files changed, 1 insertion(+), 4 deletions(-)

base-commit: 5a221342a025948fa7d84f0c404748f6ba57f3ad

Signature · 1 line
2.56.0.257.gf7497c7d27-goog
#1 lore raw

PATCH 1/2 chr-testdev: Remove unused in_vq

in_vq is assigned in chr_testdev_init() from vqs[0], but kvm-unit-tests only writes to the character device via out_vq and never consumes input from the host. Clang 24 warns on this with -Wunused-but-set-global:

lib/chr-testdev.c:15:26: error: variable 'in_vq' set but not used [-Werror,-Wunused-but-set-global]

Remove the unused variable.

Fixes b412ad0d39a1 ("Introduce chr-testdev")
---
 lib/chr-testdev.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
lib/chr-testdev.c +1 -2
index b3c641a833feb..c23fd92a46308 100644
@@ -12,7 +12,7 @@
 #define TESTDEV_NAME "chr-testdev"
 
 static struct virtio_device *vcon;
-static struct virtqueue *in_vq, *out_vq;
+static struct virtqueue *out_vq;
 static struct spinlock lock;
 
 static void __testdev_send(char *buf, unsigned int len)
@@ -65,6 +65,5 @@ void chr_testdev_init(void)
 		return;
 	}
 
-	in_vq = vqs[0];
 	out_vq = vqs[1];
 }
Signature · 1 line
2.56.0.257.gf7497c7d27-goog
Reviewed-by on v1 1/2
#2 lore raw

Re: [kvm-unit-tests PATCH 1/2] chr-testdev: Remove unused in_vq

Quoted 40 lines · Yosry Ahmed

in_vq is assigned in chr_testdev_init() from vqs[0], but kvm-unit-tests only writes to the character device via out_vq and never consumes input from the host. Clang 24 warns on this with -Wunused-but-set-global:

lib/chr-testdev.c:15:26: error: variable 'in_vq' set but not used [-Werror,-Wunused-but-set-global]

Remove the unused variable.

Fixes b412ad0d39a1 ("Introduce chr-testdev")
---
 lib/chr-testdev.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
lib/chr-testdev.c +1 -2
index b3c641a833feb..c23fd92a46308 100644
@@ -12,7 +12,7 @@
 #define TESTDEV_NAME "chr-testdev"
 
 static struct virtio_device *vcon;
-static struct virtqueue *in_vq, *out_vq;
+static struct virtqueue *out_vq;
 static struct spinlock lock;
 
 static void __testdev_send(char *buf, unsigned int len)
@@ -65,6 +65,5 @@ void chr_testdev_init(void)
 		return;
 	}
 
-	in_vq = vqs[0];
 	out_vq = vqs[1];
 }
Signature · 1 line
2.56.0.257.gf7497c7d27-goog
#3 lore raw

PATCH 2/2 x86/desc: Remove unused exception flag

In reply to Yosry Ahmed

exception is set to true in exception_handler() but is never read because exception recovery redirects regs->rip to exception_handler_longjmp(). Clang 24 warns on this with -Wunused-but-set-global:

lib/x86/desc.c:483:13: error: variable 'exception' set but not used [-Werror,-Wunused-but-set-global]

Remove the unused variable.

Fixes 932ba2d2f530 ("x86: simplify test_for_exception trigger functions")
---
 lib/x86/desc.c | 2 --
 1 file changed, 2 deletions(-)
lib/x86/desc.c +0 -2
index f4cdfbc92c560..b5d4056260a1d 100644
@@ -480,7 +480,6 @@ void setup_alt_stack(void)
 }
 #endif
 
-static bool exception;
 static jmp_buf *exception_jmpbuf;
 
 static void exception_handler_longjmp(void)
@@ -491,7 +490,6 @@ static void exception_handler_longjmp(void)
 static void exception_handler(struct ex_regs *regs)
 {
 	/* longjmp must happen after iret, so do not do it now.  */
-	exception = true;
 	regs->rip = (unsigned long)&exception_handler_longjmp;
 	regs->cs = read_cs();
 }
Signature · 1 line
2.56.0.257.gf7497c7d27-goog
Reviewed-by on v1 2/2
#4 lore raw

Re: [kvm-unit-tests PATCH 2/2] x86/desc: Remove unused exception flag

Am 22.10.26 um 22:44 schrieb Yosry Ahmed:

Quoted 31 lines

exception is set to true in exception_handler() but is never read because exception recovery redirects regs->rip to exception_handler_longjmp(). Clang 24 warns on this with -Wunused-but-set-global:

lib/x86/desc.c:483:13: error: variable 'exception' set but not used [-Werror,-Wunused-but-set-global]

Remove the unused variable.

Fixes 932ba2d2f530 ("x86: simplify test_for_exception trigger functions")
---
  lib/x86/desc.c | 2 --
  1 file changed, 2 deletions(-)
lib/x86/desc.c +0 -1
index f4cdfbc92c560..b5d4056260a1d 100644
@@ -480,7 +480,6 @@ void setup_alt_stack(void)
  }
  #endif
 
-static bool exception;
  static jmp_buf *exception_jmpbuf;
 
  static void exception_handler_longjmp(void)

lib/x86/desc.c static void exception_handler_longjmp(void) · line 495

Quoted 7 lines
lib/x86/desc.c +0 -1
@@ -491,7 +490,6 @@ static void exception_handler_longjmp(void)
  static void exception_handler(struct ex_regs *regs)
  {
  	/* longjmp must happen after iret, so do not do it now.  */
-	exception = true;
  	regs->rip = (unsigned long)&exception_handler_longjmp;
  	regs->cs = read_cs();
  }

... and committed it now to the repository.

Thanks,
Thomas