c-ubsan.c (ubsan_instrument_bounds): Don't instrument if TYPE_MAX_VALUE is NULL.
authorMarek Polacek <polacek@redhat.com>
Tue, 15 Jul 2014 11:06:07 +0000 (11:06 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 15 Jul 2014 11:06:07 +0000 (11:06 +0000)
* c-ubsan.c (ubsan_instrument_bounds): Don't instrument if
TYPE_MAX_VALUE is NULL.

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

From-SVN: r212552

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

index 2cd29fe927f9c832cc4fd5ed8547d9c09b8635fe..977de693e5c5c2e1d9427b8e16dc906a9882f95d 100644 (file)
@@ -1,3 +1,8 @@
+2014-07-15  Marek Polacek  <polacek@redhat.com>
+
+       * c-ubsan.c (ubsan_instrument_bounds): Don't instrument if
+       TYPE_MAX_VALUE is NULL.
+
 2014-07-14  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/61294
index 36985806b4e1aa773cfc36e092a215817a7417dd..ad5dd0bf92af5aa43fdad278316d91662b15c195 100644 (file)
@@ -265,7 +265,7 @@ ubsan_instrument_bounds (location_t loc, tree array, tree *index,
   tree type = TREE_TYPE (array);
   tree domain = TYPE_DOMAIN (type);
 
-  if (domain == NULL_TREE)
+  if (domain == NULL_TREE || TYPE_MAX_VALUE (domain) == NULL_TREE)
     return NULL_TREE;
 
   tree bound = TYPE_MAX_VALUE (domain);
index 2f259639676a24c8ef650c43dba1ccb6408f80c0..8332a20c859f9697f6e25b30b6959199c39f46c9 100644 (file)
@@ -1,3 +1,7 @@
+2014-07-15  Marek Polacek  <polacek@redhat.com>
+
+       * gcc.dg/ubsan/bounds-1.c: New test.
+
 2014-06-15  Tobias Burnus  <burnus@net-b.de>
 
        * gfortran.dg/coarray_34.f90: New.
diff --git a/gcc/testsuite/gcc.dg/ubsan/bounds-1.c b/gcc/testsuite/gcc.dg/ubsan/bounds-1.c
new file mode 100644 (file)
index 0000000..6f3cd2d
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=bounds" } */
+
+struct T { int c; char d[]; } t = { 1, "abcdefg" };
+
+int
+baz (int i)
+{
+  return t.d[i];
+}