re PR sanitizer/70875 (ICE in get_ubsan_type_info_for_type with -fsanitize=undefined)
authorMarek Polacek <polacek@redhat.com>
Fri, 6 May 2016 09:47:25 +0000 (09:47 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 6 May 2016 09:47:25 +0000 (09:47 +0000)
PR sanitizer/70875
* ubsan.c (get_ubsan_type_info_for_type): Remove assert.

* gcc.dg/ubsan/bounds-3.c: New test.

From-SVN: r235951

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

index 951ae2cc5dc18c42f45aa433869ce03a49524552..1c6c42ca52389eb7129bfb814cf88a11493a8a55 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-06  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/70875
+       * ubsan.c (get_ubsan_type_info_for_type): Remove assert.
+
 2016-05-06  Oleg Endo  <olegendo@gcc.gnu.org>
 
        PR target/54089
index 17773ced6cf8517e12c8a7028c1250ab900ed517..aaf3e00c017badd6c6ff088b0c077bb46078e508 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-06  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/70875
+       * gcc.dg/ubsan/bounds-3.c: New test.
+
 2016-05-06  Oleg Endo  <olegendo@gcc.gnu.org>
 
        PR target/54089
diff --git a/gcc/testsuite/gcc.dg/ubsan/bounds-3.c b/gcc/testsuite/gcc.dg/ubsan/bounds-3.c
new file mode 100644 (file)
index 0000000..50ad673
--- /dev/null
@@ -0,0 +1,22 @@
+/* PR sanitizer/70875 */
+/* { dg-do run } */
+/* { dg-options "-fsanitize=bounds" } */
+
+int
+foo (int n, int k)
+{
+  struct S
+  {
+    int i[n];
+    int value;
+  } s[2];
+  return s[k].value = 0;
+}
+
+int
+main ()
+{
+  return foo (2, 2);
+}
+
+/* { dg-output "index 2 out of bounds for type 'S \\\[2\\\]'" } */
index 802341e999539cea7ed8a03ea873d5b6a1e88c24..c5543f821d8bcf761889d7b75606f29de1da0c79 100644 (file)
@@ -302,7 +302,6 @@ ubsan_source_location (location_t loc)
 static unsigned short
 get_ubsan_type_info_for_type (tree type)
 {
-  gcc_assert (TYPE_SIZE (type) && tree_fits_uhwi_p (TYPE_SIZE (type)));
   if (TREE_CODE (type) == REAL_TYPE)
     return tree_to_uhwi (TYPE_SIZE (type));
   else if (INTEGRAL_TYPE_P (type))