Module Name:    src
Committed By:   mrg
Date:           Mon Sep  4 20:58:52 UTC 2023

Modified Files:
        src/sys/arch/amd64/include: cpu.h
        src/sys/arch/i386/include: cpu.h

Log Message:
x86: avoid annoying GCC 12 bounds check in curcpu() and curlwp().

these functions read %gs and return an pointer at an offset from this
value (the current cpu, or lwp pointers), and GCC is complaining that
they're accessing a array cpu_info[0] (ie, zero length, no storage.)

several attempts to workaround it have failed, and because of the
asm volatile nature of this, it seems very unlikely a compiler would
take this and do something wrong with it.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/amd64/include/cpu.h
cvs rdiff -u -r1.184 -r1.185 src/sys/arch/i386/include/cpu.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/include/cpu.h
diff -u src/sys/arch/amd64/include/cpu.h:1.71 src/sys/arch/amd64/include/cpu.h:1.72
--- src/sys/arch/amd64/include/cpu.h:1.71	Sun Apr  9 08:17:56 2023
+++ src/sys/arch/amd64/include/cpu.h	Mon Sep  4 20:58:52 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.71 2023/04/09 08:17:56 riastradh Exp $	*/
+/*	$NetBSD: cpu.h,v 1.72 2023/09/04 20:58:52 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -48,6 +48,14 @@
 static struct cpu_info *x86_curcpu(void);
 static lwp_t *x86_curlwp(void);
 
+/*
+ * XXXGCC12 has:
+ * ./machine/cpu.h:57:9: error: array subscript 0 is outside array bounds of 'struct cpu_info * const[0]' [-Werror=array-bounds]
+ *    56 |         __asm("movq %%gs:%1, %0" :
+ */
+#pragma GCC push_options
+#pragma GCC diagnostic ignored "-Warray-bounds"
+
 __inline __always_inline static struct cpu_info * __unused __nomsan
 x86_curcpu(void)
 {
@@ -72,6 +80,8 @@ x86_curlwp(void)
 	return l;
 }
 
+#pragma GCC pop_options
+
 #endif	/* __GNUC__ && !_MODULE */
 
 #ifdef XENPV

Index: src/sys/arch/i386/include/cpu.h
diff -u src/sys/arch/i386/include/cpu.h:1.184 src/sys/arch/i386/include/cpu.h:1.185
--- src/sys/arch/i386/include/cpu.h:1.184	Sun Apr  9 08:18:03 2023
+++ src/sys/arch/i386/include/cpu.h	Mon Sep  4 20:58:52 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.184 2023/04/09 08:18:03 riastradh Exp $	*/
+/*	$NetBSD: cpu.h,v 1.185 2023/09/04 20:58:52 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -45,6 +45,14 @@
 static struct cpu_info *x86_curcpu(void);
 static lwp_t *x86_curlwp(void);
 
+/*
+ * XXXGCC12 has:
+ * ./machine/cpu.h:57:9: error: array subscript 0 is outside array bounds of 'struct cpu_info * const[0]' [-Werror=array-bounds]
+ *    56 |         __asm("movq %%gs:%1, %0" :
+ */
+#pragma GCC push_options
+#pragma GCC diagnostic ignored "-Warray-bounds"
+
 __inline __always_inline static struct cpu_info * __unused
 x86_curcpu(void)
 {
@@ -68,7 +76,10 @@ x86_curlwp(void)
 	    (*(struct cpu_info * const *)offsetof(struct cpu_info, ci_curlwp)));
 	return l;
 }
-#endif
+
+#pragma GCC pop_options
+
+#endif	/* __GNUC__ && !_MODULE */
 
 #ifdef XENPV
 #define	CLKF_USERMODE(frame)	(curcpu()->ci_xen_clockf_usermode)

Reply via email to