This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix ubsan ICE with flexible array members
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>, Jakub Jelinek <jakub at redhat dot com>
- Date: Tue, 15 Jul 2014 13:01:10 +0200
- Subject: [PATCH] Fix ubsan ICE with flexible array members
- Authentication-results: sourceware.org; auth=none
We were missing a check that the TYPE_MAX_VALUE is not NULL.
If it is, we ICE later when gimplifying the UBSAN_BOUNDS call arguments.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2014-07-15 Marek Polacek <polacek@redhat.com>
* c-ubsan.c (ubsan_instrument_bounds): Don't instrument if
TYPE_MAX_VALUE is NULL.
* gcc.dg/ubsan/bounds-1.c: New test.
diff --git gcc/c-family/c-ubsan.c gcc/c-family/c-ubsan.c
index 3698580..ad5dd0b 100644
--- gcc/c-family/c-ubsan.c
+++ gcc/c-family/c-ubsan.c
@@ -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);
diff --git gcc/testsuite/gcc.dg/ubsan/bounds-1.c gcc/testsuite/gcc.dg/ubsan/bounds-1.c
index e69de29..6f3cd2d 100644
--- gcc/testsuite/gcc.dg/ubsan/bounds-1.c
+++ gcc/testsuite/gcc.dg/ubsan/bounds-1.c
@@ -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];
+}
Marek