Do not instrument register variables in object-size sanitizer (PR sanitizer/70878).
authorMartin Liska <mliska@suse.cz>
Tue, 11 Apr 2017 13:08:08 +0000 (15:08 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Tue, 11 Apr 2017 13:08:08 +0000 (13:08 +0000)
2017-04-11  Martin Liska  <mliska@suse.cz>

PR sanitizer/70878
* ubsan.c (instrument_object_size): Do not instrument register
variables.
2017-04-11  Martin Liska  <mliska@suse.cz>

PR sanitizer/70878
* gcc.dg/ubsan/pr70878.c: New test.

From-SVN: r246837

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/ubsan/pr70878.c [new file with mode: 0644]
gcc/ubsan.c

index c56b450..71894ec 100644 (file)
@@ -1,3 +1,9 @@
+2017-04-11  Martin Liska  <mliska@suse.cz>
+
+       PR sanitizer/70878
+       * ubsan.c (instrument_object_size): Do not instrument register
+       variables.
+
 2017-04-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/80381
index ebfe739..116b5b2 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-11  Martin Liska  <mliska@suse.cz>
+
+       PR sanitizer/70878
+       * gcc.dg/ubsan/pr70878.c: New test.
+
 2017-04-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/80381
diff --git a/gcc/testsuite/gcc.dg/ubsan/pr70878.c b/gcc/testsuite/gcc.dg/ubsan/pr70878.c
new file mode 100644 (file)
index 0000000..acd7fb0
--- /dev/null
@@ -0,0 +1,9 @@
+/* PR sanitizer/80878 */
+/* { dg-do compile { target { { i?86-*-* x86_64-*-* } && lp64 } } } */
+/* { dg-options "-fsanitize=object-size" } */
+
+void * sbrk ()
+{
+ volatile register unsigned int sp_r1 __asm__ ("ebx");
+ return __builtin_strcat ((char*)sp_r1, 0); /* { dg-warning "cast to pointer from integer of different size" } */
+}
index 323c1cc..c01d633 100644 (file)
@@ -1806,7 +1806,11 @@ instrument_object_size (gimple_stmt_iterator *gsi, bool is_lhs)
   bool decl_p = DECL_P (inner);
   tree base;
   if (decl_p)
-    base = inner;
+    {
+      if (DECL_REGISTER (inner))
+       return;
+      base = inner;
+    }
   else if (TREE_CODE (inner) == MEM_REF)
     base = TREE_OPERAND (inner, 0);
   else