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 c56b4505a35d335c4b90ede37460e3d99a6ab332..71894ec9b4cf51be56cde56694d51c4110410863 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 ebfe7392a9858a4464f62654f80b8db48fce2bc6..116b5b2707dd2593b544a206694c30b82195b1a5 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 323c1ccdb4902fa1ce797197099dc1faa2e993c0..c01d63318c238bbf5b58c88cad4d4388960467a4 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