public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH libatomic/arm] avoid warning on constant addresses (PR 101379)
@ 2021-07-09 23:11 Martin Sebor
  2021-07-15  8:33 ` Christophe Lyon
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Martin Sebor @ 2021-07-09 23:11 UTC (permalink / raw)
  To: gcc-patches, Christophe Lyon

[-- Attachment #1: Type: text/plain, Size: 978 bytes --]

The attached tweak avoids the new -Warray-bounds instances when
building libatomic for arm. Christophe confirms it resolves
the problem (thank you!)

As we have discussed, the main goal of this class of warnings
is to detect accesses at addresses derived from null pointers
(e.g., to struct members or array elements at a nonzero offset).
Diagnosing accesses at hardcoded addresses is incidental because
at the stage they are detected the two are not distinguishable
from each another.

I'm planning (hoping) to implement detection of invalid pointer
arithmetic involving null for GCC 12, so this patch is a stopgap
solution to unblock the arm libatomic build without compromising
the warning.  Once the new detection is in place these workarounds
can be removed or replaced with something more appropriate (e.g.,
declaring the objects at the hardwired addresses with an attribute
like AVR's address or io; that would enable bounds checking at
those addresses as well).

Martin

[-- Attachment #2: gcc-101379.diff --]
[-- Type: text/x-patch, Size: 918 bytes --]

PR bootstrap/101379 - libatomic arm build failure after r12-2132 due to -Warray-bounds on a constant address

libatomic/ChangeLog:
	* /config/linux/arm/host-config.h (__kernel_helper_version): New
	function.  Adjust shadow macro.

diff --git a/libatomic/config/linux/arm/host-config.h b/libatomic/config/linux/arm/host-config.h
index 1520f237d73..777d08a2b85 100644
--- a/libatomic/config/linux/arm/host-config.h
+++ b/libatomic/config/linux/arm/host-config.h
@@ -39,8 +39,14 @@ typedef void (__kernel_dmb_t) (void);
 #define __kernel_dmb (*(__kernel_dmb_t *) 0xffff0fa0)
 
 /* Kernel helper page version number.  */
-#define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
+static inline unsigned*
+__kernel_helper_version ()
+{
+  unsigned *volatile addr = (unsigned int *)0xffff0ffc;
+  return addr;
+}
 
+#define __kernel_helper_version (*__kernel_helper_version())
 
 #ifndef HAVE_STREX
 static inline bool

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-07-21 16:54 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-09 23:11 [PATCH libatomic/arm] avoid warning on constant addresses (PR 101379) Martin Sebor
2021-07-15  8:33 ` Christophe Lyon
2021-07-16 17:42 ` Thomas Schwinge
2021-07-16 21:11   ` Martin Sebor
2021-07-19  8:49     ` Thomas Schwinge
2021-07-17 22:28   ` Andrew Stubbs
2021-07-19  8:46     ` [gcn] Work-around libgomp 'error: array subscript 0 is outside array bounds of ‘__lds struct gomp_thread * __lds[0]’ [-Werror=array-bounds]' (was: [PATCH libatomic/arm] avoid warning on constant addresses (PR 101379)) Thomas Schwinge
2021-07-19  8:56       ` Jakub Jelinek
2021-07-19 11:10       ` Andrew Stubbs
2021-07-20  7:23       ` [gcn] Work-around libgomp 'error: array subscript 0 is outside array bounds of ‘__lds struct gomp_thread * __lds[0]’ [-Werror=array-bounds]' Thomas Schwinge
2021-07-20  8:40         ` '#pragma GCC diagnostic' (mis-)use in 'statement' of 'if' (was: [gcn] Work-around libgomp 'error: array subscript 0 is outside array bounds of ‘__lds struct gomp_thread * __lds[0]’ [-Werror=array-bounds]') Thomas Schwinge
2021-07-20 19:47           ` '#pragma GCC diagnostic' (mis-)use in 'statement' of 'if' Martin Sebor
2021-07-20 20:16             ` Jakub Jelinek
2021-07-21 16:41 ` [PATCH libatomic/arm] avoid warning on constant addresses (PR 101379) Kyrylo Tkachov
2021-07-21 16:54   ` Martin Sebor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).