diff mbox series

tree-optimization/111736 - avoid address sanitizing of __seg_gs

Message ID 20240321092545.F18DB3858429@sourceware.org
State New
Headers show
Series tree-optimization/111736 - avoid address sanitizing of __seg_gs | expand

Commit Message

Richard Biener March 21, 2024, 9:25 a.m. UTC
The following more thoroughly avoids address sanitizing accesses
to non-generic address-spaces.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

OK?

Thanks,
Richard.

	PR tree-optimization/111736
	* asan.cc (instrument_derefs): Do not instrument accesses
	to non-generic address-spaces.

	* gcc.target/i386/pr111736.c: New testcase.
---
 gcc/asan.cc                              |  4 ++++
 gcc/testsuite/gcc.target/i386/pr111736.c | 23 +++++++++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr111736.c
diff mbox series

Patch

diff --git a/gcc/asan.cc b/gcc/asan.cc
index cfe83106460..04caf8802e2 100644
--- a/gcc/asan.cc
+++ b/gcc/asan.cc
@@ -2755,6 +2755,10 @@  instrument_derefs (gimple_stmt_iterator *iter, tree t,
   if (VAR_P (inner) && DECL_HARD_REGISTER (inner))
     return;
 
+  /* Accesses to non-generic address-spaces are not handled.  */
+  if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (TREE_TYPE (inner))))
+    return;
+
   poly_int64 decl_size;
   if ((VAR_P (inner)
        || (TREE_CODE (inner) == RESULT_DECL
diff --git a/gcc/testsuite/gcc.target/i386/pr111736.c b/gcc/testsuite/gcc.target/i386/pr111736.c
new file mode 100644
index 00000000000..231fdd07e80
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr111736.c
@@ -0,0 +1,23 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -fsanitize=address" } */
+
+int __seg_gs m;
+
+int foo (void)
+{
+  return m;
+}
+
+extern int  __seg_gs n;
+
+int bar (void)
+{
+  return n;
+}
+
+int baz (int __seg_gs *o)
+{
+  return *o;
+}
+
+/* { dg-final { scan-assembler-not "asan_report_load" } } */