public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Warray-bounds: Warn only for generic address spaces
@ 2021-10-12 18:33 Siddhesh Poyarekar
  2021-10-12 19:06 ` Martin Sebor
  2021-10-13  8:20 ` Richard Biener
  0 siblings, 2 replies; 5+ messages in thread
From: Siddhesh Poyarekar @ 2021-10-12 18:33 UTC (permalink / raw)
  To: gcc-patches; +Cc: msebor

The warning is falsely triggered for THREAD_SELF in glibc when
accessing TCB through the segment register.

gcc/ChangeLog:

	* gimple-array-bounds.cc
	(array_bounds_checker::check_mem_ref): Bail out for
	non-generic address spaces.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/addr-space-3.c: New test case.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
---
 gcc/gimple-array-bounds.cc                   | 3 +++
 gcc/testsuite/gcc.target/i386/addr-space-3.c | 5 +++++
 2 files changed, 8 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/i386/addr-space-3.c

diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc
index 0517e5ddd8e..36fc1dbe3f8 100644
--- a/gcc/gimple-array-bounds.cc
+++ b/gcc/gimple-array-bounds.cc
@@ -432,6 +432,9 @@ array_bounds_checker::check_mem_ref (location_t location, tree ref,
   if (aref.offset_in_range (axssize))
     return false;
 
+  if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (axstype)))
+    return false;
+
   if (TREE_CODE (aref.ref) == SSA_NAME)
     {
       gimple *def = SSA_NAME_DEF_STMT (aref.ref);
diff --git a/gcc/testsuite/gcc.target/i386/addr-space-3.c b/gcc/testsuite/gcc.target/i386/addr-space-3.c
new file mode 100644
index 00000000000..4bd940e696a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/addr-space-3.c
@@ -0,0 +1,5 @@
+/* Verify that __seg_fs/gs marked variables do not trigger an array bounds
+   warning.  */
+/* { dg-do compile */
+/* { dg-options "-O2 -Warray-bounds" } */
+#include "addr-space-2.c"
-- 
2.31.1


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

end of thread, other threads:[~2021-10-13  8:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12 18:33 [PATCH] Warray-bounds: Warn only for generic address spaces Siddhesh Poyarekar
2021-10-12 19:06 ` Martin Sebor
2021-10-13  0:14   ` Siddhesh Poyarekar
2021-10-13  8:20 ` Richard Biener
2021-10-13  8:27   ` Siddhesh Poyarekar

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).