re PR sanitizer/79558 (ICE: Segfault in ubsan_type_descriptor, at ubsan.c:412)
authorMarek Polacek <polacek@redhat.com>
Mon, 20 Feb 2017 15:50:23 +0000 (15:50 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Mon, 20 Feb 2017 15:50:23 +0000 (15:50 +0000)
PR sanitizer/79558
* ubsan.c (ubsan_type_descriptor): Check if TYPE_MAX_VALUE is null.

* c-c++-common/ubsan/bounds-14.c: New test.

From-SVN: r245605

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/ubsan/bounds-14.c [new file with mode: 0644]
gcc/ubsan.c

index ab2e544d6d229bc9bbbc9c61129e7da7b62d3aec..02b51576e2ddf8555b5bf452eebd530b837c5e72 100644 (file)
@@ -3,6 +3,9 @@
        PR middle-end/79537
        * gimplify.c (gimplify_expr): Handle unused *&&L;.
 
+       PR sanitizer/79558
+       * ubsan.c (ubsan_type_descriptor): Check if TYPE_MAX_VALUE is null.
+
 2017-02-20  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/79568
index bbe7ac9a4a487575f948970320667a5a55a8f78e..645d2ed0e9dd4a87f5583e2fc3a8809bb92b0655 100644 (file)
@@ -3,6 +3,9 @@
        PR middle-end/79537
        * gcc.dg/comp-goto-4.c: New test.
 
+       PR sanitizer/79558
+       * c-c++-common/ubsan/bounds-14.c: New test.
+
 2017-02-20  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/79568
diff --git a/gcc/testsuite/c-c++-common/ubsan/bounds-14.c b/gcc/testsuite/c-c++-common/ubsan/bounds-14.c
new file mode 100644 (file)
index 0000000..ddb5251
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR sanitizer/79558 */
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=bounds" } */
+
+void
+fn1 (int n)
+{
+  int i, j;
+  int x[2][0];
+  for (i = 0; i < n; i++)
+    for (j = 0; j < n; j++)
+      x[i][j] = 5;
+}
index 0291401eecff4d317f3d62c160f0980168557618..11a41e1dc535eb87167450879d025bb8537d6d8a 100644 (file)
@@ -409,7 +409,9 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle)
        {
          pp_left_bracket (&pretty_name);
          tree dom = TYPE_DOMAIN (t);
-         if (dom && TREE_CODE (TYPE_MAX_VALUE (dom)) == INTEGER_CST)
+         if (dom != NULL_TREE
+             && TYPE_MAX_VALUE (dom) != NULL_TREE
+             && TREE_CODE (TYPE_MAX_VALUE (dom)) == INTEGER_CST)
            {
              if (tree_fits_uhwi_p (TYPE_MAX_VALUE (dom))
                  && tree_to_uhwi (TYPE_MAX_VALUE (dom)) + 1 != 0)