]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR sanitizer/83014 (ICE in pretty-print with -fsanitize=bounds)
authorJakub Jelinek <jakub@redhat.com>
Mon, 25 Jun 2018 16:54:49 +0000 (18:54 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 25 Jun 2018 16:54:49 +0000 (18:54 +0200)
Backported from mainline
2017-11-24  Jakub Jelinek  <jakub@redhat.com>

PR sanitizer/83014
* ubsan.c (ubsan_type_descriptor): Use pp_unsigned_wide_integer
instead of pp_printf with HOST_WIDE_INT_PRINT_DEC.  Avoid calling
tree_to_uhwi twice.

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

From-SVN: r262038

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

index 1bf9540d50b3b3a49624bde42cf2a5e84ce7ea88..d69483ce35cf5c085543393874a2779436b6310b 100644 (file)
@@ -2,7 +2,12 @@
 
        Backported from mainline
        2017-11-24  Jakub Jelinek  <jakub@redhat.com>
-
+       PR sanitizer/83014
+       * ubsan.c (ubsan_type_descriptor): Use pp_unsigned_wide_integer
+       instead of pp_printf with HOST_WIDE_INT_PRINT_DEC.  Avoid calling
+       tree_to_uhwi twice.
        * tree-object-size.c (pass_through_call): Do not handle
        BUILT_IN_STPNCPY_CHK which is not a pass through call.
 
index 10146f45ea0a67bbeae752f64449001ee08ca492..431ad7c09b6f9291c93c405fe72bb69fc367c5df 100644 (file)
@@ -2,6 +2,9 @@
 
        Backported from mainline
        2017-11-24  Jakub Jelinek  <jakub@redhat.com>
+       PR sanitizer/83014
+       * gcc.dg/ubsan/pr83014.c: New test.
 
        * gcc.dg/builtin-object-size-18.c: New test.
 
diff --git a/gcc/testsuite/gcc.dg/ubsan/pr83014.c b/gcc/testsuite/gcc.dg/ubsan/pr83014.c
new file mode 100644 (file)
index 0000000..de62604
--- /dev/null
@@ -0,0 +1,12 @@
+/* PR sanitizer/83014 */
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=undefined" } */
+
+int
+foo (void)
+{
+  int data[5];
+  data[0] = 0;
+  data[5] = 0;
+  return data[0];
+}
index 0b4ddbc4dcb09efcfc822090399b86aecf20d79d..4541e58ab3ce9e549faa63ccafa97959b76ea384 100644 (file)
@@ -413,10 +413,10 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle)
              && TYPE_MAX_VALUE (dom) != NULL_TREE
              && TREE_CODE (TYPE_MAX_VALUE (dom)) == INTEGER_CST)
            {
+             unsigned HOST_WIDE_INT m;
              if (tree_fits_uhwi_p (TYPE_MAX_VALUE (dom))
-                 && tree_to_uhwi (TYPE_MAX_VALUE (dom)) + 1 != 0)
-               pp_printf (&pretty_name, HOST_WIDE_INT_PRINT_DEC,
-                           tree_to_uhwi (TYPE_MAX_VALUE (dom)) + 1);
+                 && (m = tree_to_uhwi (TYPE_MAX_VALUE (dom))) + 1 != 0)
+               pp_unsigned_wide_integer (&pretty_name, m + 1);
              else
                pp_wide_int (&pretty_name,
                             wi::add (wi::to_widest (TYPE_MAX_VALUE (dom)), 1),