re PR sanitizer/81223 (ICE in instrument_null at gcc/ubsan.c:1230)
authorMarek Polacek <polacek@redhat.com>
Tue, 27 Jun 2017 11:38:31 +0000 (11:38 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 27 Jun 2017 11:38:31 +0000 (11:38 +0000)
PR sanitizer/81223
* ubsan.c (instrument_null): Check get_base_address's result for null.

* gcc.dg/ubsan/pr81223.c: New test.

From-SVN: r249687

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

index 665e0b5b085a0406945cf503c08a9c2b7acc4296..f9e00198bbfd352960685b5c72193570e232e68a 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-27  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/81223
+       * ubsan.c (instrument_null): Check get_base_address's result for null.
+
 2017-06-27  Marc Glisse  <marc.glisse@inria.fr>
 
        * match.pd ((A+-B)+(C-A), (A+B)-(A-C)): New transformations.
index 7364606164cac74f4e93f217ca0a519f241eaa84..98faa118078c1182248f511b0dd9bcd6e059a54e 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-27  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/81223
+       * gcc.dg/ubsan/pr81223.c: New test.
+
 2017-06-27  Marc Glisse  <marc.glisse@inria.fr>
 
        * gcc.dg/tree-ssa/assoc-1.c: New file.
diff --git a/gcc/testsuite/gcc.dg/ubsan/pr81223.c b/gcc/testsuite/gcc.dg/ubsan/pr81223.c
new file mode 100644 (file)
index 0000000..e7aff52
--- /dev/null
@@ -0,0 +1,12 @@
+/* PR sanitizer/81223 */
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=undefined" } */
+
+void bar ();
+
+void
+foo (int x)
+{
+  struct S { char a[x]; } v;
+  bar (v);
+}
index c7a06ef0e8ddfb8ab844e5970766bf9c2d8e43d5..bd0588b89baa07a4ae336d701af124336e74df2f 100644 (file)
@@ -1228,7 +1228,8 @@ instrument_null (gimple_stmt_iterator gsi, tree t, bool is_lhs)
   if (TREE_CODE (t) == ADDR_EXPR)
     t = TREE_OPERAND (t, 0);
   tree base = get_base_address (t);
-  if (TREE_CODE (base) == MEM_REF
+  if (base != NULL_TREE
+      && TREE_CODE (base) == MEM_REF
       && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)
     instrument_mem_ref (t, base, &gsi, is_lhs);
 }