]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/111736 - avoid address sanitizing of __seg_gs
authorRichard Biener <rguenther@suse.de>
Thu, 21 Mar 2024 07:30:39 +0000 (08:30 +0100)
committerRichard Biener <rguenther@suse.de>
Thu, 21 Mar 2024 09:48:55 +0000 (10:48 +0100)
The following more thoroughly avoids address sanitizing accesses
to non-generic address-spaces.

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
gcc/testsuite/gcc.target/i386/pr111736.c [new file with mode: 0644]

index cfe83106460528a8b326eb405e3622fdc4ec9f00..7f91cc616fcacf753ce5735163d9259a1b3de094 100644 (file)
@@ -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 should not be instrumented.  */
+  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 (file)
index 0000000..231fdd0
--- /dev/null
@@ -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" } } */