Hi Ian,

Yesterday's enhancement to -Warray-bounds has exposed a couple of
issues in libgo where the code writes into an invalid constant
address that the warning is designed to flag.

On the assumption that those invalid addresses are deliberate,
the attached patch suppresses these instances by using #pragma
GCC diagnostic but I don't think I'm supposed to commit it (at
least Git won't let me).  To avoid Go bootstrap failures please
either apply the patch or otherwise suppress the warning (e.g.,
by using a volatile pointer temporary).

Thanks
Martin
Use Object Size Type zero for -Warray-bounds [PR101374].

PR bootstrap/101374 - -Warray-bounds accessing a member subobject as derived

libgo/ChangeLog:
	PR bootstrap/101374
	* runtime/proc.c (runtime_mstart): Suppress -Warray-bounds.
	* runtime/runtime_c.c (runtime_signalstack): Same.

diff --git a/libgo/runtime/proc.c b/libgo/runtime/proc.c
index 38bf7a6b255..61635e6c1ea 100644
--- a/libgo/runtime/proc.c
+++ b/libgo/runtime/proc.c
@@ -594,7 +594,14 @@ runtime_mstart(void *arg)
 		gp->entry = nil;
 		gp->param = nil;
 		__builtin_call_with_static_chain(pfn(gp1), fv);
+
+		/* Writing to an invalid address is detected.  */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
+
 		*(int*)0x21 = 0x21;
+
+#pragma GCC diagnostic push
 	}
 
 	if(mp->exiting) {
@@ -662,7 +669,12 @@ setGContext(void)
 		gp->entry = nil;
 		gp->param = nil;
 		__builtin_call_with_static_chain(pfn(gp1), fv);
+
+		/* Writing to an invalid address is detected.  */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
 		*(int*)0x22 = 0x22;
+#pragma GCC diagnostic pop
 	}
 }
 
diff --git a/libgo/runtime/runtime_c.c b/libgo/runtime/runtime_c.c
index 18222c14465..53feaa075c7 100644
--- a/libgo/runtime/runtime_c.c
+++ b/libgo/runtime/runtime_c.c
@@ -116,7 +116,11 @@ runtime_signalstack(byte *p, uintptr n)
 	if(p == nil)
 		st.ss_flags = SS_DISABLE;
 	if(sigaltstack(&st, nil) < 0)
+	  /* Writing to an invalid address is detected.  */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
 		*(int *)0xf1 = 0xf1;
+#pragma GCC diagnostic push
 }
 
 int32 go_open(char *, int32, int32)

Reply via email to